Skip to content

Commit

Permalink
chore(webapp) don't use endpoint when info is outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
Torresmorah committed Dec 12, 2022
1 parent c514183 commit 744273c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions webapp/src/utils/eosapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const eosApis = eosConfig.endpoints.map(endpoint => {
verbose: false,
fetchConfiguration: {},
}),
endpoint,
lastFailureTime: 0,
}
})
Expand All @@ -25,6 +26,19 @@ const callEosApi = async method => {

try {
const response = await method(eosApi.api)
let headBlockTime = response.head_block_time

if (!headBlockTime) {
const info = await eosApi.api.getInfo({})

headBlockTime = info.head_block_time
}

const diffBlockTimems = new Date() - new Date(headBlockTime)

if (diffBlockTimems > eosConfig.syncToleranceInterval) {
throw new Error(`The endpoint ${eosApi.endpoint} is outdated`)
}

return response
} catch (error) {
Expand Down

0 comments on commit 744273c

Please sign in to comment.