Skip to content

Commit

Permalink
perf(webapp): avoid tracking info when all endpoints fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Torresmorah committed Feb 22, 2023
1 parent faca5d0 commit b364c95
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions webapp/src/context/state.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react'

import useLightUAL from '../hooks/useUAL'
import { ualConfig } from '../config'
import eosApi from '../utils/eosapi'
import eosApi, { ENDPOINTS_ERROR } from '../utils/eosapi'

const SharedStateContext = React.createContext()

Expand Down Expand Up @@ -114,6 +114,7 @@ export const useSharedState = () => {
}

const [state, dispatch] = context
const waitTrackingInterval = 30000
let infoInterval
let scheduleInterval

Expand Down Expand Up @@ -194,24 +195,22 @@ export const useSharedState = () => {
},
})
} catch (error) {
console.log(error)
console.error(error)
}
}, [dispatch, state.tpb, state.tps, state.tpsWaitingBlock])

useEffect(()=>{
if(!lastBlock) return
useEffect(() => {
if (!lastBlock) return

const updateTransactions = async () => {
await getBlock(lastBlock)
}

updateTransactions()
},[lastBlock, getBlock])
}, [lastBlock, getBlock])

const startTrackingProducerSchedule = async ({ interval = 120 } = {}) => {
if (scheduleInterval) {
return
}
if (scheduleInterval) return

const handle = async () => {
try {
Expand All @@ -220,10 +219,20 @@ export const useSharedState = () => {
dispatch({ type: 'updateSchedule', payload: result.active })
} catch (error) {
console.error(error)

if (error?.message === ENDPOINTS_ERROR) {
await stopTrackingProducerSchedule()
setTimeout(() => {
startTrackingProducerSchedule({ interval })
}, waitTrackingInterval)
}
}
}

await handle()

if (scheduleInterval) return

scheduleInterval = setInterval(handle, interval * 1000)
}

Expand All @@ -240,8 +249,15 @@ export const useSharedState = () => {
})

setLastBlock(info.head_block_num)
} catch (error) {
} catch (error) {
console.error(error)

if (error?.message === ENDPOINTS_ERROR) {
await stopTrackingInfo()
setTimeout(() => {
startTrackingInfo({ interval })
}, waitTrackingInterval)
}
}
}

Expand All @@ -251,6 +267,9 @@ export const useSharedState = () => {
}

await handle()

if (infoInterval) return

infoInterval = setInterval(handle, interval * 1000)
}

Expand Down

0 comments on commit b364c95

Please sign in to comment.