diff --git a/apps/common/components/BalanceReminderPopover.tsx b/apps/common/components/BalanceReminderPopover.tsx index 269a499bd..d063acc4e 100755 --- a/apps/common/components/BalanceReminderPopover.tsx +++ b/apps/common/components/BalanceReminderPopover.tsx @@ -12,6 +12,7 @@ import {ImageWithFallback} from '@common/components/ImageWithFallback'; import {useWallet} from '@common/contexts/useWallet'; import {useYearn} from '@common/contexts/useYearn'; import {useBalance} from '@common/hooks/useBalance'; +import {IconQuestion} from '@common/icons/IconQuestion'; import type {ReactElement} from 'react'; import type {TAddress} from '@yearn-finance/web-lib/types'; @@ -88,7 +89,7 @@ function TokenItem({element}: {element: TBalanceReminderElement}): ReactElement } export function BalanceReminderPopover(): ReactElement { - const {balances: tokens, isLoading} = useWallet(); + const {balances: tokens, isLoading, triggerForknetBalances} = useWallet(); const {address, ens, isActive, onDesactivate} = useWeb3(); const {vaults} = useYearn(); @@ -154,6 +155,16 @@ export function BalanceReminderPopover(): ReactElement {
+
+ +
{isActive && address && ens ? ens : isActive && address ? truncateHex(address, 5) : 'Connect wallet'}
diff --git a/apps/common/contexts/useWallet.tsx b/apps/common/contexts/useWallet.tsx index 1d77f0bc9..0dbba605b 100755 --- a/apps/common/contexts/useWallet.tsx +++ b/apps/common/contexts/useWallet.tsx @@ -1,4 +1,4 @@ -import {createContext, memo, useCallback, useContext, useEffect, useMemo} from 'react'; +import {createContext, memo, useCallback, useContext, useEffect, useMemo, useState} from 'react'; import { OPT_YVAGEUR_USDC_STAKING_CONTRACT, OPT_YVALETH_FRXETH_STAKING_CONTRACT, @@ -73,6 +73,7 @@ export type TWalletContext = { balancesNonce: number; isLoading: boolean; refresh: (tokenList?: TUseBalancesTokens[]) => Promise; + triggerForknetBalances: () => void; }; const defaultToken: TToken = { @@ -96,7 +97,8 @@ const defaultProps = { cumulatedValueInVaults: 0, balancesNonce: 0, isLoading: true, - refresh: async (): Promise => ({}) + refresh: async (): Promise => ({}), + triggerForknetBalances: (): void => {} }; /* 🔵 - Yearn Finance ********************************************************** @@ -107,6 +109,7 @@ const WalletContext = createContext(defaultProps); export const WalletContextApp = memo(function WalletContextApp({children}: {children: ReactElement}): ReactElement { const {vaults, vaultsMigrations, vaultsRetired, isLoadingVaultList, prices} = useYearn(); const {onLoadStart, onLoadDone} = useUI(); + const [shouldUseForknetBalances, set_shouldUseForknetBalances] = useState(false); //List all tokens related to yearn vaults const availableTokens = useMemo((): TUseBalancesTokens[] => { @@ -192,6 +195,7 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil tokensExists[vault.token.address] = true; } }); + return tokens; }, [isLoadingVaultList, vaults]); @@ -218,6 +222,19 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil return tokens; }, [vaultsRetired]); + const allTokens = useMemo((): TUseBalancesTokens[] => { + const tokens = [...availableTokens, ...migratableTokens, ...retiredTokens]; + if (!shouldUseForknetBalances) { + return tokens; + } + for (const token of tokens) { + if (token.chainID === 1) { + tokens.push({...token, chainID: 1337}); + } + } + return tokens; + }, [availableTokens, migratableTokens, retiredTokens, shouldUseForknetBalances]); + // Fetch the balances const { data: tokensRaw, @@ -226,7 +243,7 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil nonce, isLoading } = useBalances({ - tokens: [...availableTokens, ...migratableTokens, ...retiredTokens], + tokens: [...allTokens], prices }); @@ -300,6 +317,8 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil [tokens] ); + console.log(tokens); + /* 🔵 - Yearn Finance ****************************************************** ** Setup and render the Context provider to use in the app. ***************************************************************************/ @@ -312,7 +331,8 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil balancesNonce: nonce, cumulatedValueInVaults, isLoading: isLoading || false, - refresh: onRefresh + refresh: onRefresh, + triggerForknetBalances: (): void => set_shouldUseForknetBalances((s): boolean => !s) }), [tokens, cumulatedValueInVaults, isLoading, onRefresh, nonce] ); diff --git a/apps/common/icons/IconQuestion.tsx b/apps/common/icons/IconQuestion.tsx index 2bbf4afb8..072bae953 100644 --- a/apps/common/icons/IconQuestion.tsx +++ b/apps/common/icons/IconQuestion.tsx @@ -23,8 +23,8 @@ export function IconQuestion(props: React.SVGProps): ReactElement fill={'currentColor'} />