Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed Feb 22, 2023
2 parents 74b62a9 + 9e84ac7 commit 2a26c6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-ultra-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
REACT_APP_EOS_API_NETWORK_NAME: 'ultra-testnet'
REACT_APP_EOS_API_NETWORK_LABEL: 'Ultra Testnet'
REACT_APP_EOS_API_NETWORK_LOGO: 'https://icodrops.com/wp-content/uploads/2019/06/Ultra-150x150.jpg'
REACT_APP_EOS_API_HOSTS: '[\"ultratest.api.eosnation.io\"]'
REACT_APP_EOS_API_HOSTS: '[\"ultratest.api.eosnation.io\",\"testnet.ultra.eosrio.io\",\"api.testnet.ultra.eossweden.org\",\"ultratest-api.eoseoul.io\"]'
REACT_APP_EOS_API_PORT: '443'
REACT_APP_EOS_API_PROTOCOL: 'https'
REACT_APP_EOS_CHAIN_ID: '7fc56be645bb76ab9d747b53089f132dcb7681db06f0852cfa03eaf6f7ac80e9'
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_DATA: ${{ secrets.POSTGRES_DATA }}
# hapi
HAPI_EOS_API_ENDPOINTS: '["https://ultratest.api.eosnation.io"]'
HAPI_EOS_API_ENDPOINTS: '["http://ultratest.api.eosnation.io","https://testnet.ultra.eosrio.io","https://api.testnet.ultra.eossweden.org","https://ultratest-api.eoseoul.io"]'
HAPI_EOS_API_NETWORK_NAME: ultra-testnet
HAPI_EOS_API_CHAIN_ID: 7fc56be645bb76ab9d747b53089f132dcb7681db06f0852cfa03eaf6f7ac80e9
HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }}
Expand Down
44 changes: 32 additions & 12 deletions webapp/src/context/state.context.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect, useCallback } from 'react'
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 @@ -107,12 +107,14 @@ export const SharedStateProvider = ({ ...props }) => {

export const useSharedState = () => {
const context = React.useContext(SharedStateContext)
const [lastBlock, setLastBlock] = useState()

if (!context) {
throw new Error(`useSharedState must be used within a SharedStateContext`)
}

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

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

useEffect(() => {
let block = state.info.head_block_num

if (!block || !state.info.infoInterval) return
if (!lastBlock) return

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

updateTransactions()
}, [state.info, getBlock])
}, [lastBlock, getBlock])

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

const handle = async () => {
try {
Expand All @@ -221,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 @@ -237,10 +245,19 @@ export const useSharedState = () => {

dispatch({
type: 'updateInfo',
payload: { ...info, infoInterval },
payload: { ...info },
})

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

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

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

await handle()

if (infoInterval) return

infoInterval = setInterval(handle, interval * 1000)
}

Expand Down

0 comments on commit 2a26c6c

Please sign in to comment.