Skip to content

Commit

Permalink
Merge pull request #726 from yieldprotocol/fix/assetPairOnLoad-not-lo…
Browse files Browse the repository at this point in the history
…ading-as-default

assetPairLoading as false on load to prevent not fetching price data
  • Loading branch information
brucedonovan authored Dec 10, 2021
2 parents d810679 + 712a83b commit d146390
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -430,15 +430,14 @@ 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<IVault> => {

/* get the asset Pair info if required */
if (!userState.assetPairMap.has(vault.baseId + vault.ilkId)) {
diagnostics && console.log('AssetPairInfo queued for fetching from network');
await updateAssetPair(vault.baseId, vault.ilkId);
} else {
diagnostics && console.log('AssetPairInfo exists in assetPairMap');
}

/* Get dynamic vault data */
const [
{ ink, art },
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useAssetPair.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<IAssetPair | undefined>();
Expand All @@ -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]);

Expand Down

0 comments on commit d146390

Please sign in to comment.