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 {
&-name {
font-size: 0.929rem;

View File

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

View File

@ -37,7 +37,7 @@
"iBackedUpTheNote": "I backed up the note",
"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!",
"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",
"clickToCopy": "Click to copy",
"copied": "Copied!",

View File

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

View File

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

View File

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

View File

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

View File

@ -1,17 +1,37 @@
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 {
zipper.sync
.zip(`${fileName}`)
.compress()
.save(`${fileName}.zip`)
const data = fs.readFileSync(`${filePath}`)
await jszip.file(`${fileName}`, data, fileConfig)
await jszip.generateNodeStream({
...compressionConfig,
streamFiles: true
})
.pipe(fs.createWriteStream(`${filePath}.zip`))
fs.unlinkSync(fileName)
return true
} catch (err) {
console.log('on save error', fileName, err.message)
console.log('on save error', filePath, err.message)
return false
}
}

View File

@ -64,7 +64,7 @@ async function main(type, netId) {
let freshEvents = cachedEvents.events.concat(events)
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 {
freshEvents = freshEvents.filter((e, index) => Number(e.leafIndex) === index)
}

View File

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