Skip to content

Commit

Permalink
Merge pull request #1165 from edenia/fix/review-endpoints-timeout
Browse files Browse the repository at this point in the history
fix(webapp): Endpoints fail in Account and Contracts page
  • Loading branch information
xavier506 authored Mar 7, 2023
2 parents 9e84ac7 + 3cd018a commit 8462d17
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions webapp/src/context/state.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const useSharedState = () => {
},
})
} catch (error) {
console.error(error)
console.error(error?.message || error)
}
}, [dispatch, state.tpb, state.tps, state.tpsWaitingBlock])

Expand All @@ -218,7 +218,7 @@ export const useSharedState = () => {

dispatch({ type: 'updateSchedule', payload: result.active })
} catch (error) {
console.error(error)
console.error(error?.message || error)

if (error?.message === ENDPOINTS_ERROR) {
await stopTrackingProducerSchedule()
Expand Down Expand Up @@ -250,7 +250,7 @@ export const useSharedState = () => {

setLastBlock(info.head_block_num)
} catch (error) {
console.error(error)
console.error(error?.message || error)

if (error?.message === ENDPOINTS_ERROR) {
await stopTrackingInfo()
Expand Down
15 changes: 9 additions & 6 deletions webapp/src/utils/eosapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const ENDPOINTS_ERROR =
'Each endpoint failed when trying to execute the function'

const waitRequestInterval = 120000
const timeout = 15000
const timeout = 60000
const eosApis = eosConfig.endpoints.map(endpoint => {
return {
api: EosApi({
Expand Down Expand Up @@ -61,11 +61,14 @@ const callWithTimeout = async (promise, ms) => {
timeoutID = setTimeout(() => reject(new Error(timeoutMessage)), ms)
})

return Promise.race([promise, timeoutPromise]).then((response) => {
clearTimeout(timeoutID)

return response
})
return Promise.race([promise, timeoutPromise])
.then(response => response)
.catch(error => {
throw error
})
.finally(() => {
clearTimeout(timeoutID)
})
}

const getAbi = async account => {
Expand Down

0 comments on commit 8462d17

Please sign in to comment.