Skip to content

Commit 26e0f83

Browse files
fix: chainId undefined
1 parent 6ac4403 commit 26e0f83

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

apps/main/src/dex/DexLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { useNetworks } from './entities/networks'
99
export function DexLayout() {
1010
const { network: networkId = 'ethereum' } = useParams<Partial<UrlParams>>()
1111
const { data: networks } = useNetworks()
12-
const network = recordValues(networks).find((n) => n.id === networkId)!
12+
const network = recordValues(networks).find((n) => n.id === networkId)
1313

1414
useRedirectToEth(network, networkId)
15-
useAutoRefresh(network)
15+
useAutoRefresh(network?.chainId)
1616

1717
return <Outlet />
1818
}

apps/main/src/dex/hooks/useAutoRefresh.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
import { useCallback } from 'react'
1+
import { useCallback, useMemo } from 'react'
22
import curvejsApi from '@/dex/lib/curvejs'
33
import useStore from '@/dex/store/useStore'
4-
import type { NetworkDef } from '@ui/utils'
54
import { type CurveApi, useConnection } from '@ui-kit/features/connect-wallet'
65
import usePageVisibleInterval from '@ui-kit/hooks/usePageVisibleInterval'
76
import { REFRESH_INTERVAL } from '@ui-kit/lib/model'
87
import { useGasInfoAndUpdateLib } from '@ui-kit/lib/model/entities/gas-info'
9-
import { useNetworkByChain, useNetworks } from '../entities/networks'
8+
import { useNetworks } from '../entities/networks'
109

11-
export const useAutoRefresh = (networkDef: NetworkDef) => {
10+
export const useAutoRefresh = (chainId: number | undefined) => {
1211
const { curveApi } = useConnection()
13-
12+
const { data: networks } = useNetworks()
1413
const fetchPools = useStore((state) => state.pools.fetchPools)
15-
const poolDataMapper = useStore((state) => state.pools.poolsMapper[networkDef.chainId])
14+
const poolDataMapper = useStore((state) => chainId && state.pools.poolsMapper[chainId])
1615
const fetchPoolsVolume = useStore((state) => state.pools.fetchPoolsVolume)
1716
const fetchPoolsTvl = useStore((state) => state.pools.fetchPoolsTvl)
1817
const setTokensMapper = useStore((state) => state.tokens.setTokensMapper)
1918
const fetchAllStoredBalances = useStore((state) => state.userBalances.fetchAllStoredBalances)
2019

21-
const { data: networks } = useNetworks()
22-
const { data: network } = useNetworkByChain({ chainId: networkDef.chainId })
20+
const network = useMemo(() => chainId && networks[chainId], [chainId, networks])
2321

24-
useGasInfoAndUpdateLib({ chainId: networkDef.chainId, networks })
22+
useGasInfoAndUpdateLib({ chainId, networks })
2523

2624
const fetchPoolsVolumeTvl = useCallback(
2725
async (curve: CurveApi) => {
28-
const { chainId } = curve
26+
if (!chainId || !poolDataMapper) return
2927
const poolsData = Object.values(poolDataMapper)
3028
await Promise.all([fetchPoolsVolume(chainId, poolsData), fetchPoolsTvl(curve, poolsData)])
3129
void setTokensMapper(curve, poolsData)
3230
},
33-
[fetchPoolsTvl, fetchPoolsVolume, poolDataMapper, setTokensMapper],
31+
[chainId, fetchPoolsTvl, fetchPoolsVolume, poolDataMapper, setTokensMapper],
3432
)
3533

3634
usePageVisibleInterval(() => {

packages/curve-ui-kit/src/lib/model/entities/gas-info.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,11 @@ const { useQuery: useGasInfoAndUpdateLibBase, fetchQuery: fetchGasInfoAndUpdateL
147147
refetchInterval: '1m',
148148
validationSuite: createValidationSuite(<TChainId extends number>({ chainId }: GasInfoParams<TChainId>) => {
149149
chainValidationGroup({ chainId })
150-
if (chainId) {
151-
group('apiValidation', () => {
152-
test('api', 'API chain ID mismatch', () => {
153-
enforce(getAnyCurve(chainId)).message('Chain ID should be loaded').equals(chainId)
154-
})
150+
group('apiValidation', () => {
151+
test('api', 'API chain ID mismatch', () => {
152+
enforce(getAnyCurve(chainId!)).message('Chain ID should be loaded').equals(chainId)
155153
})
156-
}
154+
})
157155
providerValidationGroup()
158156
}),
159157
})

0 commit comments

Comments
 (0)