diff --git a/src/contexts/UserContext.tsx b/src/contexts/UserContext.tsx index e2595f79f..713b749df 100644 --- a/src/contexts/UserContext.tsx +++ b/src/contexts/UserContext.tsx @@ -53,7 +53,7 @@ const initState: IUserContextState = { seriesLoading: true as boolean, assetsLoading: true as boolean, strategiesLoading: true as boolean, - assetPairLoading: true as boolean, + assetPairLoading: false as boolean, /* Current User selections */ selectedSeries: null, @@ -430,7 +430,6 @@ const UserProvider = ({ children }: any) => { /* Add in the dynamic vault data by mapping the vaults list */ const vaultListMod = await Promise.all( _vaultList.map(async (vault: IVaultRoot): Promise => { - /* get the asset Pair info if required */ if (!userState.assetPairMap.has(vault.baseId + vault.ilkId)) { diagnostics && console.log('AssetPairInfo queued for fetching from network'); @@ -438,7 +437,7 @@ const UserProvider = ({ children }: any) => { } else { diagnostics && console.log('AssetPairInfo exists in assetPairMap'); } - + /* Get dynamic vault data */ const [ { ink, art }, diff --git a/src/hooks/useAssetPair.ts b/src/hooks/useAssetPair.ts index 45bda1f04..7e0a5bc6e 100644 --- a/src/hooks/useAssetPair.ts +++ b/src/hooks/useAssetPair.ts @@ -1,6 +1,6 @@ import { useContext, useState, useEffect, useCallback } from 'react'; -import { IAsset, IAssetPair, ISettingsContext } from '../types'; +import { IAsset, IAssetPair, ISettingsContext, IUserContext } from '../types'; import { SettingsContext } from '../contexts/SettingsContext'; import { UserContext } from '../contexts/UserContext'; @@ -14,7 +14,7 @@ export const useAssetPair = (base: IAsset, collateral: IAsset): IAssetPair | und const { userState: { assetPairMap, assetPairLoading }, userActions: { updateAssetPair }, - } = useContext(UserContext); + } = useContext(UserContext) as IUserContext; /* LOCAL STATE */ const [assetPair, setAssetPair] = useState(); @@ -32,10 +32,10 @@ export const useAssetPair = (base: IAsset, collateral: IAsset): IAssetPair | und useEffect(() => { if (base?.id && collateral?.id && !assetPairLoading) { /* try get from state first */ - const pair_: IAssetPair = assetPairMap.get(base.id + collateral.id); + const pair_ = assetPairMap.get(base.id + collateral.id); pair_ && setAssetPair(pair_); /* else update the pair data */ - !pair_ && (async () => updatePair(base, collateral))() ; + !pair_ && (async () => updatePair(base, collateral))(); } }, [assetPairLoading, assetPairMap, base, collateral, updatePair]);