improve progress percentage

This commit is contained in:
gozzy 2022-11-13 06:32:56 +00:00
parent d7d9ebe214
commit a9b27bf4c1
3 changed files with 19 additions and 2 deletions

View File

@ -9,7 +9,7 @@ import { loadCachedEvents, getPastEvents } from './helpers'
const EVENTS_PATH = './static/events/' const EVENTS_PATH = './static/events/'
const EVENTS = ['Deposit', 'Withdrawal'] const EVENTS = ['Deposit', 'Withdrawal']
const enabledChains = ['1', '56', '5', '100', '137' ] const enabledChains = ['1', '56', '100', '137' ]
async function main(type, netId) { async function main(type, netId) {
const { tokens, nativeCurrency, deployedBlock } = networkConfig[`netId${netId}`] const { tokens, nativeCurrency, deployedBlock } = networkConfig[`netId${netId}`]

View File

@ -9,6 +9,13 @@ import { sleep, flattenNArray, formatEvents, capitalizeFirstLetter } from '@/uti
const supportedCaches = ['1', '56', '100', '137'] const supportedCaches = ['1', '56', '100', '137']
let store
if (process.browser) {
window.onNuxtReady(({ $store }) => {
store = $store
})
}
class EventService { class EventService {
constructor({ netId, amount, currency, factoryMethods }) { constructor({ netId, amount, currency, factoryMethods }) {
this.idb = window.$nuxt.$indexedDB(netId) this.idb = window.$nuxt.$indexedDB(netId)
@ -31,6 +38,13 @@ class EventService {
return `${type}s_${this.currency}_${this.amount}` 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) { async getEvents(type) {
let cachedEvents = await this.getEventsFromDB(type) let cachedEvents = await this.getEventsFromDB(type)
@ -315,6 +329,8 @@ class EventService {
} }
async getBatchEventsFromRpc({ fromBlock, type }) { async getBatchEventsFromRpc({ fromBlock, type }) {
this.updateEventProgress(0, type)
try { try {
const batchSize = 10 const batchSize = 10
const blockRange = 10000 const blockRange = 10000
@ -335,6 +351,7 @@ class EventService {
this.createBatchRequest({ batchIndex, batchBlocks, blockDenom, batchSize, type }) this.createBatchRequest({ batchIndex, batchBlocks, blockDenom, batchSize, type })
) )
this.updateEventProgress(batchIndex / batchCount, type)
events = events.concat(batch) events = events.concat(batch)
} }

View File

@ -5,7 +5,7 @@ import { download } from '@/store/snark'
import networkConfig from '@/networkConfig' import networkConfig from '@/networkConfig'
import { mimc, bloomService } from '@/services' import { mimc, bloomService } from '@/services'
const supportedCaches = ['1', '56', '100', '137', '5'] const supportedCaches = ['1', '56', '100', '137']
class MerkleTreeService { class MerkleTreeService {
constructor({ netId, amount, currency, commitment, instanceName }) { constructor({ netId, amount, currency, commitment, instanceName }) {