Merge pull request 'Community build #002' (#3) from staging

[#3](https://development.tornadocash.community/tornadocash/classic-ui/pulls/3)
This commit is contained in:
gozzy 2022-09-22 07:18:55 +00:00
commit c80e4bb2fb
127 changed files with 60 additions and 64 deletions

View File

@ -1,3 +1,10 @@
.warning {
color: #ff8a00;
border-color: #ff8a00;
border-width: 2px;
font-size: 1.5em;
}
.info { .info {
&-name { &-name {
font-size: 0.929rem; font-size: 0.929rem;

View File

@ -29,10 +29,8 @@
{{ $t('saveAsFile') }} <span class="has-text-primary">{{ filename }}</span> {{ $t('saveAsFile') }} <span class="has-text-primary">{{ filename }}</span>
</div> </div>
<template v-if="!isSetupAccount"> <template v-if="!isSetupAccount">
<i18n tag="div" path="yourDontHaveAccount" class="notice"> <i18n tag="div" path="yourDontHaveAccount" class="notice warning">
<template v-slot:account> <template v-slot:account></template>
<a @click="_redirectToAccount">{{ $t('account.button') }}</a>
</template>
</i18n> </i18n>
</template> </template>
<b-checkbox v-if="isSetupAccount" v-model="isEncrypted"> <b-checkbox v-if="isSetupAccount" v-model="isEncrypted">

View File

@ -37,7 +37,7 @@
"iBackedUpTheNote": "I backed up the note", "iBackedUpTheNote": "I backed up the note",
"iEncryptedTheNote": "Create an on-chain backup of this note with your Account {address}", "iEncryptedTheNote": "Create an on-chain backup of this note with your Account {address}",
"yourNoteWontBeSaved": "Your note won't be saved in your browser. Please make sure it's backed up!", "yourNoteWontBeSaved": "Your note won't be saved in your browser. Please make sure it's backed up!",
"yourDontHaveAccount": "You can also save encrypted notes on-chain by setting up the Note Account. Create one on the {account} page.", "yourDontHaveAccount": "FAILURE TO BACKUP NOTES WILL RESULT IN LOSS OF FUNDS",
"sendDeposit": "Send Deposit", "sendDeposit": "Send Deposit",
"clickToCopy": "Click to copy", "clickToCopy": "Click to copy",
"copied": "Copied!", "copied": "Copied!",

View File

@ -37,7 +37,7 @@
"iBackedUpTheNote": "Я сделал резервную копию", "iBackedUpTheNote": "Я сделал резервную копию",
"iEncryptedTheNote": "Создать резервную копию этой Note в блокчейне с помощью Аккаунта {address}", "iEncryptedTheNote": "Создать резервную копию этой Note в блокчейне с помощью Аккаунта {address}",
"yourNoteWontBeSaved": "Ваша Note не будет сохранена в браузере. Убедитесь, что вы сделали резервную копию!", "yourNoteWontBeSaved": "Ваша Note не будет сохранена в браузере. Убедитесь, что вы сделали резервную копию!",
"yourDontHaveAccount": "Вы также можете сохранять зашифрованные Note в блокчейне, создав аккаунт для приватных Note. Создайте его на странице {account}.", "yourDontHaveAccount": "НЕВОЗМОЖНОСТЬ СОЗДАТЬ РЕЗЕРВНУЮ ЗАПИСКУ ПРИВЕДЕТ К ПОТЕРЕ СРЕДСТВ",
"sendDeposit": "Отправить депозит", "sendDeposit": "Отправить депозит",
"clickToCopy": "Скопировать", "clickToCopy": "Скопировать",
"copied": "Скопировано!", "copied": "Скопировано!",

View File

@ -37,7 +37,7 @@
"iBackedUpTheNote": "我已备份了凭证", "iBackedUpTheNote": "我已备份了凭证",
"iEncryptedTheNote": "用您的账户{address}创建此凭证的链上备份", "iEncryptedTheNote": "用您的账户{address}创建此凭证的链上备份",
"yourNoteWontBeSaved": "你的存款凭证不会被存储在浏览器的缓存中,请确认已作好备份。", "yourNoteWontBeSaved": "你的存款凭证不会被存储在浏览器的缓存中,请确认已作好备份。",
"yourDontHaveAccount": "您还可以通过设置凭证账户将加密的凭证保存在链上。 在 {account} 页面上创建。", "yourDontHaveAccount": "未能备份票据将导致资金损失",
"sendDeposit": "发送存款", "sendDeposit": "发送存款",
"clickToCopy": "点击复制", "clickToCopy": "点击复制",
"copied": "已复制!", "copied": "已复制!",

View File

@ -83,13 +83,11 @@
"eslint-plugin-vue": "^6.0.1", "eslint-plugin-vue": "^6.0.1",
"esm": "^3.2.25", "esm": "^3.2.25",
"jest": "^24.9.0", "jest": "^24.9.0",
"node-stream-zip": "^1.15.0",
"nodemon": "^2.0.0", "nodemon": "^2.0.0",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"raw-loader": "^3.1.0", "raw-loader": "^3.1.0",
"sass": "^1.49.9", "sass": "^1.49.9",
"sass-loader": "^8.0.0", "sass-loader": "^8.0.0",
"vue-jest": "^3.0.5", "vue-jest": "^3.0.5"
"zip-local": "^0.3.4"
} }
} }

View File

@ -30,14 +30,9 @@ export async function loadCachedEvents({ name, directory, deployedBlock }) {
if (module) { if (module) {
const events = JSON.parse(module) const events = JSON.parse(module)
const [lastEvent] = JSON.parse(module).sort(
(a, b) => (b.block || b.blockNumber) - (a.block || a.blockNumber)
)
const lastBlock = lastEvent.block || lastEvent.blockNumber
return { return {
events, events,
lastBlock lastBlock: events[events.length - 1].blockNumber
} }
} }
} catch (err) { } catch (err) {
@ -68,8 +63,7 @@ export async function getPastEvents({ type, fromBlock, netId, events, contractAt
const blockDifference = Math.ceil(blockNumberBuffer - fromBlock) const blockDifference = Math.ceil(blockNumberBuffer - fromBlock)
// eth_logs and eth_filter are restricted > 10,000 block queries // eth_logs and eth_filter are restricted > 10,000 block queries
const blockDenom = blockDifference > 10000 ? 4950 : 20 const blockRange = 10000
const blockRange = blockDifference / blockDenom
let chunksCount = blockDifference === 0 ? 1 : Math.ceil(blockDifference / blockRange) let chunksCount = blockDifference === 0 ? 1 : Math.ceil(blockDifference / blockRange)
const chunkSize = Math.ceil(blockDifference / chunksCount) const chunkSize = Math.ceil(blockDifference / chunksCount)

View File

@ -1,17 +1,37 @@
import fs from 'fs' import fs from 'fs'
import zipper from 'zip-local' import Jszip from 'jszip'
const compressionConfig = {
type: "nodebuffer",
compression: "DEFLATE",
compressionOptions: {
level: 9
}
}
const fileConfig = {
binary: true,
compression: "DEFLATE"
}
export async function save(filePath) {
const jszip = new Jszip()
const directories = filePath.split('/')
const fileName = directories[directories.length - 1]
export function save(fileName) {
try { try {
zipper.sync const data = fs.readFileSync(`${filePath}`)
.zip(`${fileName}`)
.compress() await jszip.file(`${fileName}`, data, fileConfig)
.save(`${fileName}.zip`) await jszip.generateNodeStream({
...compressionConfig,
streamFiles: true
})
.pipe(fs.createWriteStream(`${filePath}.zip`))
fs.unlinkSync(fileName)
return true return true
} catch (err) { } catch (err) {
console.log('on save error', fileName, err.message) console.log('on save error', filePath, err.message)
return false return false
} }
} }

View File

@ -64,7 +64,7 @@ async function main(type, netId) {
let freshEvents = cachedEvents.events.concat(events) let freshEvents = cachedEvents.events.concat(events)
if (type === 'Withdrawal') { if (type === 'Withdrawal') {
freshEvents = uniqBy(freshEvents, 'nullifierHash').sort((a, b) => b.blockNumber - a.blockNumber) freshEvents = uniqBy(freshEvents, 'nullifierHash').sort((a, b) => a.blockNumber - b.blockNumber)
} else { } else {
freshEvents = freshEvents.filter((e, index) => Number(e.leafIndex) === index) freshEvents = freshEvents.filter((e, index) => Number(e.leafIndex) === index)
} }

View File

@ -14,7 +14,7 @@ class EventService {
this.idb = window.$nuxt.$indexedDB(netId) this.idb = window.$nuxt.$indexedDB(netId)
const { nativeCurrency } = networkConfig[`netId${netId}`] const { nativeCurrency } = networkConfig[`netId${netId}`]
const hasCache = supportedCaches.indexOf(Number(this.netId)) !== 0 const hasCache = supportedCaches.includes(netId.toString())
this.netId = netId this.netId = netId
this.amount = amount this.amount = amount
@ -37,6 +37,7 @@ class EventService {
if (!cachedEvents && this.hasCache) { if (!cachedEvents && this.hasCache) {
cachedEvents = await this.getEventsFromCache(type) cachedEvents = await this.getEventsFromCache(type)
} }
return cachedEvents return cachedEvents
} }
async updateEvents(type, cachedEvents) { async updateEvents(type, cachedEvents) {
@ -45,6 +46,7 @@ class EventService {
const savedEvents = cachedEvents || (await this.getEvents(type)) const savedEvents = cachedEvents || (await this.getEvents(type))
let fromBlock = deployedBlock let fromBlock = deployedBlock
if (savedEvents) { if (savedEvents) {
fromBlock = savedEvents.lastBlock + 1 fromBlock = savedEvents.lastBlock + 1
} }
@ -138,22 +140,23 @@ class EventService {
async getEventsFromDB(type) { async getEventsFromDB(type) {
try { try {
const instanceName = this.getInstanceName(type) const instanceName = this.getInstanceName(type)
const savedEvents = await this.idb.getAll({ storeName: instanceName }) const savedEvents = await this.idb.getAll({ storeName: instanceName })
if (!savedEvents || !savedEvents.length) { if (!savedEvents || !savedEvents.length) {
return undefined return undefined
} }
const event = await this.idb.getFromIndex({ // IndexedDB scrambles assortment
storeName: 'lastEvents', savedEvents.sort((a, b) => {
indexName: 'name', if (a.leafIndex && b.leafIndex) {
key: instanceName return a.leafIndex - b.leafIndex
}
return a.blockNumber - b.blockNumber
}) })
return { return {
events: savedEvents, events: savedEvents,
lastBlock: event.blockNumber lastBlock: savedEvents[savedEvents.length - 1].blockNumber
} }
} catch (err) { } catch (err) {
return undefined return undefined
@ -268,7 +271,7 @@ class EventService {
async getBatchEventsFromRpc({ fromBlock, type }) { async getBatchEventsFromRpc({ fromBlock, type }) {
try { try {
const blockRange = 4950 const blockRange = 10000
const { blockDifference, currentBlockNumber } = await this.getBlocksDiff({ fromBlock }) const { blockDifference, currentBlockNumber } = await this.getBlocksDiff({ fromBlock })
let numberParts = blockDifference === 0 ? 1 : Math.ceil(blockDifference / blockRange) let numberParts = blockDifference === 0 ? 1 : Math.ceil(blockDifference / blockRange)
@ -311,15 +314,17 @@ class EventService {
async getEventsFromRpc({ fromBlock, type }) { async getEventsFromRpc({ fromBlock, type }) {
try { try {
const { blockDifference } = await this.getBlocksDiff({ fromBlock })
let events let events
if (Number(this.netId) === 1) { if (blockDifference < 10000) {
const rpcEvents = await this.getEventsPartFromRpc({ fromBlock, toBlock: 'latest', type }) const rpcEvents = await this.getEventsPartFromRpc({ fromBlock, toBlock: 'latest', type })
events = rpcEvents?.events || [] events = rpcEvents?.events || []
} else { } else {
const rpcEvents = await this.getBatchEventsFromRpc({ fromBlock, type }) const rpcEvents = await this.getBatchEventsFromRpc({ fromBlock, type })
events = rpcEvents?.events || [] events = rpcEvents?.events || []
} }
return events return events
} catch (err) { } catch (err) {
return [] return []
@ -332,6 +337,7 @@ class EventService {
const rpcEvents = await this.getEventsFromRpc({ fromBlock, type }) const rpcEvents = await this.getEventsFromRpc({ fromBlock, type })
const allEvents = [].concat(rpcEvents || []) const allEvents = [].concat(rpcEvents || [])
if (allEvents.length) { if (allEvents.length) {
return { return {
events: allEvents, events: allEvents,

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More