fix: event service

This commit is contained in:
Danil Kovtonyuk 2022-07-05 18:29:31 +10:00
parent 56a6835d80
commit d36b1a9866
No known key found for this signature in database
GPG Key ID: E72A919BF08C3746
3 changed files with 26 additions and 10 deletions

View File

@ -133,8 +133,8 @@
:class="{ 'slide-animation-active': isLoading }"
:disabled="isWithdrawalButtonDisable"
:loading="isLoadingRelayers || isLoading"
@click="onWithdraw"
data-test="button_start_withdraw"
@click="onWithdraw"
>
{{ $t('withdrawButton') }}
</b-button>
@ -382,6 +382,8 @@ export default {
},
activeTab(newTab, oldTab) {
if (newTab !== oldTab && newTab === 1) {
this.withdrawAddress = ''
this.withdrawNote = ''
this.error = {
type: '',
message: ''

View File

@ -36,10 +36,10 @@ class EventService {
}
return cachedEvents
}
async updateEvents(type) {
async updateEvents(type, cachedEvents) {
const { deployedBlock } = networkConfig[`netId${this.netId}`]
const savedEvents = await this.getEvents(type)
const savedEvents = cachedEvents || (await this.getEvents(type))
let fromBlock = deployedBlock
if (savedEvents) {
@ -157,8 +157,17 @@ class EventService {
}
}
async getStatisticsRpc({ fromBlock, eventsCount }) {
async getStatisticsRpc({ eventsCount }) {
const { deployedBlock } = networkConfig[`netId${this.netId}`]
const savedEvents = await this.getEvents(eventsType.DEPOSIT)
if (savedEvents.events.length) {
const { events } = await this.updateEvents(eventsType.DEPOSIT, savedEvents)
return events
}
const blockRange = 4950
const fromBlock = deployedBlock
const { blockDifference, currentBlockNumber } = await this.getBlocksDiff({ fromBlock })
let numberParts = blockDifference === 0 ? 1 : Math.ceil(blockDifference / blockRange)
@ -225,6 +234,15 @@ class EventService {
async getEventsPartFromRpc({ fromBlock, toBlock, type }) {
try {
const { currentBlockNumber } = await this.getBlocksDiff({ fromBlock })
if (fromBlock > currentBlockNumber) {
return {
events: [],
lastBlock: fromBlock
}
}
const events = await this.contract.getPastEvents(capitalizeFirstLetter(type), {
fromBlock,
toBlock

View File

@ -270,19 +270,15 @@ const actions = {
async updateSelectEvents({ dispatch, commit, state, rootGetters, getters }) {
const netId = rootGetters['metamask/netId']
const { currency, amount } = state.selectedStatistic
const { deployedBlock } = networkConfig[`netId${netId}`]
const eventService = getters.eventsInterface.getService({ netId, amount, currency })
const savedEvents = await eventService.getEvents(eventsType.DEPOSIT)
const fromBlock = savedEvents?.lastBlock || deployedBlock
const graphEvents = await eventService.getEventsFromGraph({ fromBlock, methodName: 'getStatistic' })
const graphEvents = await eventService.getEventsFromGraph({ methodName: 'getStatistic' })
let statistic = graphEvents?.events
if (!statistic || !statistic.length) {
const fresh = await eventService.getStatisticsRpc({ fromBlock, eventsCount: 10 })
const fresh = await eventService.getStatisticsRpc({ eventsCount: 10 })
statistic = fresh || []
}