From a9b27bf4c15f60842b00060519c7890ab7afb39c Mon Sep 17 00:00:00 2001 From: gozzy Date: Sun, 13 Nov 2022 06:32:56 +0000 Subject: [PATCH] improve progress percentage --- scripts/updateEvents.js | 2 +- services/events.js | 17 +++++++++++++++++ services/merkleTree.js | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/updateEvents.js b/scripts/updateEvents.js index 9eca0cd..13cb3be 100644 --- a/scripts/updateEvents.js +++ b/scripts/updateEvents.js @@ -9,7 +9,7 @@ import { loadCachedEvents, getPastEvents } from './helpers' const EVENTS_PATH = './static/events/' const EVENTS = ['Deposit', 'Withdrawal'] -const enabledChains = ['1', '56', '5', '100', '137' ] +const enabledChains = ['1', '56', '100', '137' ] async function main(type, netId) { const { tokens, nativeCurrency, deployedBlock } = networkConfig[`netId${netId}`] diff --git a/services/events.js b/services/events.js index 96891ee..33fcbf2 100644 --- a/services/events.js +++ b/services/events.js @@ -9,6 +9,13 @@ import { sleep, flattenNArray, formatEvents, capitalizeFirstLetter } from '@/uti const supportedCaches = ['1', '56', '100', '137'] +let store +if (process.browser) { + window.onNuxtReady(({ $store }) => { + store = $store + }) +} + class EventService { constructor({ netId, amount, currency, factoryMethods }) { this.idb = window.$nuxt.$indexedDB(netId) @@ -31,6 +38,13 @@ class EventService { return `${type}s_${this.currency}_${this.amount}` } + updateEventProgress(percentage, type) { + store.dispatch('loading/updateProgress', { + message: `Fetching past ${type} events`, + progress: Math.ceil(percentage * 100) + }) + } + async getEvents(type) { let cachedEvents = await this.getEventsFromDB(type) @@ -315,6 +329,8 @@ class EventService { } async getBatchEventsFromRpc({ fromBlock, type }) { + this.updateEventProgress(0, type) + try { const batchSize = 10 const blockRange = 10000 @@ -335,6 +351,7 @@ class EventService { this.createBatchRequest({ batchIndex, batchBlocks, blockDenom, batchSize, type }) ) + this.updateEventProgress(batchIndex / batchCount, type) events = events.concat(batch) } diff --git a/services/merkleTree.js b/services/merkleTree.js index 6805ad9..dfe33dc 100644 --- a/services/merkleTree.js +++ b/services/merkleTree.js @@ -5,7 +5,7 @@ import { download } from '@/store/snark' import networkConfig from '@/networkConfig' import { mimc, bloomService } from '@/services' -const supportedCaches = ['1', '56', '100', '137', '5'] +const supportedCaches = ['1', '56', '100', '137'] class MerkleTreeService { constructor({ netId, amount, currency, commitment, instanceName }) {