From 8baf214b4f6280c8c9332e2655e05e0a944d4c10 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Thu, 31 Mar 2022 12:04:10 +0100 Subject: [PATCH] bugfix: handle unkn0wn assets in protocol --- package.json | 2 +- src/config/assets.ts | 30 +++++++++++++++++++++++++++++- src/contexts/ChainContext.tsx | 11 ++++++----- src/contexts/UserContext.tsx | 2 +- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 1011cb6a1..799c5f2d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "app-v2", - "version": "2.1.11", + "version": "2.1.12", "private": true, "dependencies": { "@multiavatar/multiavatar": "^1.0.6", diff --git a/src/config/assets.ts b/src/config/assets.ts index da9cb8028..85185f45b 100644 --- a/src/config/assets.ts +++ b/src/config/assets.ts @@ -51,7 +51,7 @@ ASSET_INFO.set(UNKNOWN, { name: 'UNKNOWN', decimals: 18, symbol: 'UNKNOWN', - showToken: true, + showToken: false, isWrappedToken: false, color: '#FFFFFFFF', digitFormat: 2, @@ -257,3 +257,31 @@ ASSET_INFO.set(FUSDC2206, { tokenIdentifier: 844848939859969, limitToSeries: ['0x303230360000'] }); + +// ASSET_INFO.set(FDAI2209, { +// version: '1', +// name: 'FDAI2209', +// decimals: 8, +// symbol: 'FDAI2209', +// showToken: false, +// isWrappedToken: false, +// color: '#FF007A', +// digitFormat: 6, +// tokenType: TokenType.ERC1155_, +// tokenIdentifier: 563373963149313, +// limitToSeries: ['0x303130360000'] +// }); + +// ASSET_INFO.set(FUSDC2209, { +// version: '1', +// name: 'FUSDC2206', +// decimals: 8, +// symbol: 'FUSDC2206', +// showToken: false, +// isWrappedToken: false, +// color: '#FF007A', +// digitFormat: 6, +// tokenType: TokenType.ERC1155_, +// tokenIdentifier: 844848939859969, +// limitToSeries: ['0x303230360000'] +// }); \ No newline at end of file diff --git a/src/contexts/ChainContext.tsx b/src/contexts/ChainContext.tsx index e0f3ee7c2..8f8572f00 100644 --- a/src/contexts/ChainContext.tsx +++ b/src/contexts/ChainContext.tsx @@ -9,7 +9,7 @@ import { useConnection } from '../hooks/useConnection'; import yieldEnv from './yieldEnv.json'; import * as contracts from '../contracts'; import { IAssetInfo, IAssetRoot, IChainContextState, ISeriesRoot, IStrategyRoot, TokenType } from '../types'; -import { ASSET_INFO, ETH_BASED_ASSETS, yvUSDC } from '../config/assets'; +import { ASSET_INFO, ETH_BASED_ASSETS, UNKNOWN, yvUSDC } from '../config/assets'; import { nameFromMaturity, getSeason, SeasonType, clearCachedItems } from '../utils/appUtils'; import DaiMark from '../components/logos/DaiMark'; @@ -271,7 +271,7 @@ const ChainProvider = ({ children }: any) => { setAllowance = async (spender: string) => { console.log(spender); console.log(asset.address); - assetContract.setApprovalForAll(spender, true ); + assetContract.setApprovalForAll(spender, true); }; break; @@ -323,7 +323,9 @@ const ChainProvider = ({ children }: any) => { const { assetId: id, asset: address } = x; /* Get the basic hardcoded token info */ - const assetInfo = ASSET_INFO.get(id) as IAssetInfo; + const assetInfo = ASSET_INFO.has(id) + ? (ASSET_INFO.get(id) as IAssetInfo) + : (ASSET_INFO.get(UNKNOWN) as IAssetInfo); let { name, symbol, decimals, version } = assetInfo; /* On first load Checks/Corrects the ERC20 name/symbol/decimals (if possible ) */ @@ -356,8 +358,7 @@ const ChainProvider = ({ children }: any) => { } } - - const idToUse = assetInfo?.wrappedTokenId || id; // here we are using the unwrapped id + const idToUse = assetInfo?.wrappedTokenId || id; // here we are using the unwrapped id const newAsset = { ...assetInfo, diff --git a/src/contexts/UserContext.tsx b/src/contexts/UserContext.tsx index a9c5cc700..eb66d769d 100644 --- a/src/contexts/UserContext.tsx +++ b/src/contexts/UserContext.tsx @@ -241,7 +241,7 @@ const UserProvider = ({ children }: any) => { try { _accountData = await Promise.all( _publicData.map(async (asset: IAssetRoot): Promise => { - const balance = asset.name !== 'UNKOWN' ? await asset.getBalance(account) : ZERO_BN; + const balance = asset.name !== 'UNKNOWN' ? await asset.getBalance(account) : ZERO_BN; return { ...asset, balance: balance || ethers.constants.Zero,