From b8082bb81dbf754c86b4b6f407f9cf23258a30f0 Mon Sep 17 00:00:00 2001 From: Majorfi Date: Fri, 9 Feb 2024 12:38:56 +0100 Subject: [PATCH] build: bump --- .vscode/settings.json | 2 +- package.json | 4 ++-- src/contexts/useYearnWallet.tsx | 25 ++++++++++++++++--------- src/utils/helpers.ts | 9 ++++----- yarn.lock | 8 ++++---- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2afec2bc..5c798751 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,7 @@ "editor.wordWrap": "off", "editor.autoIndent": "keep", "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "editor.quickSuggestions": { "strings": true diff --git a/package.json b/package.json index 95898818..186aa191 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yearn-finance/web-lib", - "version": "3.0.133", + "version": "3.0.134", "main": "./dist/index.js", "types": "./dist/index.d.js", "files": [ @@ -25,7 +25,7 @@ "export": "tsc && next build && next export -o ipfs" }, "dependencies": { - "@builtbymom/web3": "^0.0.20", + "@builtbymom/web3": "^0.0.37", "@headlessui/react": "^1.7.18", "@rainbow-me/rainbowkit": "^1.3.3", "@react-hookz/web": "^24.0.2", diff --git a/src/contexts/useYearnWallet.tsx b/src/contexts/useYearnWallet.tsx index f3c130e7..83936349 100755 --- a/src/contexts/useYearnWallet.tsx +++ b/src/contexts/useYearnWallet.tsx @@ -1,6 +1,7 @@ import {createContext, memo, useCallback, useContext, useMemo, useState} from 'react'; +import {useWeb3} from '@builtbymom/web3/contexts/useWeb3'; import {useBalances} from '@builtbymom/web3/hooks/useBalances.multichains'; -import {toAddress, toNormalizedBN} from '@builtbymom/web3/utils'; +import {isZeroAddress, toAddress, toNormalizedBN, zeroNormalizedBN} from '@builtbymom/web3/utils'; import {useDeepCompareMemo} from '@react-hookz/web'; import { @@ -44,15 +45,15 @@ const defaultToken: TYToken = { chainID: 1, value: 0, stakingValue: 0, - price: toNormalizedBN(0), - balance: toNormalizedBN(0), + price: zeroNormalizedBN, + balance: zeroNormalizedBN, supportedZaps: [] }; const defaultProps = { getToken: (): TYToken => defaultToken, - getBalance: (): TNormalizedBN => toNormalizedBN(0), - getPrice: (): TNormalizedBN => toNormalizedBN(0), + getBalance: (): TNormalizedBN => zeroNormalizedBN, + getPrice: (): TNormalizedBN => zeroNormalizedBN, balances: {}, cumulatedValueInV2Vaults: 0, cumulatedValueInV3Vaults: 0, @@ -206,6 +207,7 @@ export const YearnWalletContextApp = memo(function YearnWalletContextApp({ }: { children: ReactElement; }): ReactElement { + const {address: userAddress} = useWeb3(); const {vaults, prices, vaultsMigrations} = useYearn(); const [shouldUseForknetBalances, set_shouldUseForknetBalances] = useState(false); const {tokens, isLoading, onRefresh} = useYearnBalances({shouldUseForknetBalances}); @@ -241,15 +243,20 @@ export const YearnWalletContextApp = memo(function YearnWalletContextApp({ [tokens] ); const getBalance = useCallback( - ({address, chainID}: TTokenAndChain): TNormalizedBN => - tokens?.[chainID || 1]?.[address]?.balance || toNormalizedBN(0), - [tokens] + ({address, chainID}: TTokenAndChain): TNormalizedBN => { + if (isZeroAddress(userAddress)) { + return zeroNormalizedBN; + } + return tokens?.[chainID || 1]?.[address]?.balance || zeroNormalizedBN; + }, + [tokens, userAddress] ); + const getPrice = useCallback( ({address, chainID}: TTokenAndChain): TNormalizedBN => { const price = tokens?.[chainID || 1]?.[address]?.price; if (!price) { - return toNormalizedBN(prices?.[chainID]?.[address] || 0, 6) || toNormalizedBN(0); + return toNormalizedBN(prices?.[chainID]?.[address] || 0, 6) || zeroNormalizedBN; } return price; }, diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 71bfe8f7..adf05ff5 100755 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -81,13 +81,12 @@ export const numberSort = ({a, b, sortDirection}: {a?: number; b?: number; sortD sortDirection === 'desc' ? (b ?? 0) - (a ?? 0) : (a ?? 0) - (b ?? 0); export const bigNumberSort = ({a, b, sortDirection}: {a: bigint; b: bigint; sortDirection: TSortDirection}): number => - Number(toNormalizedBN(sortDirection === 'desc' ? b - a : a - b).normalized); - + Number(toNormalizedBN(sortDirection === 'desc' ? b - a : a - b, 18).normalized); /* 🔵 - Yearn Finance ****************************************************** -** allowanceKey is used to access the unique allowance key matching one -** token with one spender -**************************************************************************/ + ** allowanceKey is used to access the unique allowance key matching one + ** token with one spender + **************************************************************************/ export function allowanceKey(chainID: number, token: TAddress, spender: TAddress, owner: TAddress): string { return `${chainID}_${token}_${spender}_${owner}`; } diff --git a/yarn.lock b/yarn.lock index eb411bcc..0b6a613e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -388,10 +388,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@builtbymom/web3@^0.0.20": - version "0.0.20" - resolved "https://registry.yarnpkg.com/@builtbymom/web3/-/web3-0.0.20.tgz#5685e11f2b3a90c0a5d7b06692aaa9d500792fc5" - integrity sha512-no59LxzMChgZZd6XnJuh69go3PtD/3k1dTQ7KX3dpYhXZxLX2LdaDqnPVMsXmz6IovMpjAmKrkCEqEN6jlPRmA== +"@builtbymom/web3@^0.0.37": + version "0.0.37" + resolved "https://registry.yarnpkg.com/@builtbymom/web3/-/web3-0.0.37.tgz#0bc5aa08df38334266765282a3bb6da9c3dae83c" + integrity sha512-7eQLsrbR2k+mh0xBdBA1YV7m4e530CUnKl6EjYWMu7djTZkuMGGZTxQDVjwFIfAyYw6ktNrwv/3ZUlrMWVgAaQ== dependencies: "@rainbow-me/rainbowkit" "^1.3.0" "@react-hookz/web" "^24.0.2"