diff --git a/apps/common/contexts/useWallet.tsx b/apps/common/contexts/useWallet.tsx index 8cced007c..a7ede2aa1 100755 --- a/apps/common/contexts/useWallet.tsx +++ b/apps/common/contexts/useWallet.tsx @@ -284,7 +284,7 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil } } return cumulatedValueInVaults; - }, [vaults, vaultsMigrations, tokens, nonce]); + }, [vaults, vaultsMigrations, tokens]); const onRefresh = useCallback( async (tokenToUpdate?: TUseBalancesTokens[]): Promise => { @@ -339,9 +339,17 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil isLoading: isLoading || false, shouldUseForknetBalances, refresh: onRefresh, - triggerForknetBalances: (): void => set_shouldUseForknetBalances((s): boolean => !s) + triggerForknetBalances: (): void => + set_shouldUseForknetBalances((s): boolean => { + const isEnabled = !s; + if (!(window as any).ethereum) { + (window as any).ethereum = {}; + } + (window as any).ethereum.useForknetForMainnet = isEnabled; + return isEnabled; + }) }), - [tokens, cumulatedValueInVaults, isLoading, onRefresh, nonce] + [getToken, getBalance, getPrice, tokens, nonce, cumulatedValueInVaults, isLoading, shouldUseForknetBalances, onRefresh] ); return {children}; diff --git a/apps/common/utils/actions.ts b/apps/common/utils/actions.ts index fcf0bbb7f..81b4d2475 100755 --- a/apps/common/utils/actions.ts +++ b/apps/common/utils/actions.ts @@ -17,6 +17,15 @@ import type {TAddress} from '@yearn-finance/web-lib/types'; import type {TWriteTransaction} from '@yearn-finance/web-lib/utils/wagmi/provider'; import type {TTxResponse} from '@yearn-finance/web-lib/utils/web3/transaction'; +function getChainID(chainID: number): number { + if ((window as any).ethereum.useForknetForMainnet) { + if (chainID === 1) { + return 1337; + } + } + return chainID; +} + //Because USDT do not return a boolean on approve, we need to use this ABI const ALTERNATE_ERC20_APPROVE_ABI = [ { @@ -42,7 +51,7 @@ export async function isApprovedERC20(connector: Connector | undefined, chainID: const result = await readContract({ ...wagmiProvider, abi: erc20ABI, - chainId: chainID, + chainId: getChainID(chainID), address: tokenAddress, functionName: 'allowance', args: [wagmiProvider.address, spender] @@ -64,7 +73,7 @@ export async function allowanceOf(props: TAllowanceOf): Promise { const wagmiProvider = await toWagmiProvider(props.connector); const result = await readContract({ ...wagmiProvider, - chainId: props.chainID, + chainId: getChainID(props.chainID), abi: erc20ABI, address: props.tokenAddress, functionName: 'allowance', diff --git a/apps/vaults/hooks/useSortVaults.ts b/apps/vaults/hooks/useSortVaults.ts index 20f0dc841..bc615cc0b 100644 --- a/apps/vaults/hooks/useSortVaults.ts +++ b/apps/vaults/hooks/useSortVaults.ts @@ -30,7 +30,14 @@ export function useSortVaults(vaultList: TYDaemonVaults, sortBy: TPossibleSortBy ); const sortedByForwardAPR = useCallback( - (): TYDaemonVaults => vaultList.sort((a, b): number => numberSort({a: a.apr?.forwardAPR.netAPR, b: b.apr?.forwardAPR.netAPR, sortDirection})), + (): TYDaemonVaults => + vaultList.sort((a, b): number => + numberSort({ + a: a.apr?.forwardAPR?.type === '' ? a.apr?.netAPR : a.apr?.forwardAPR.netAPR, + b: b.apr?.forwardAPR?.type === '' ? b.apr?.netAPR : b.apr?.forwardAPR.netAPR, + sortDirection + }) + ), [sortDirection, vaultList] ); @@ -86,10 +93,9 @@ export function useSortVaults(vaultList: TYDaemonVaults, sortBy: TPossibleSortBy return sortedByName(); } if (sortBy === 'forwardAPR') { - return sortedByForwardAPR(); - } - if (sortBy === 'apr') { - return sortedByAPR(); + const sort = sortedByForwardAPR(); + console.log(sort); + return sort; } if (sortBy === 'tvl') { return sortedByTVL(); @@ -105,7 +111,7 @@ export function useSortVaults(vaultList: TYDaemonVaults, sortBy: TPossibleSortBy } return sortResult; - }, [sortBy, sortDirection, sortedByForwardAPR, sortedByAvailable, sortedByDeposited, sortedByName, sortedByTVL, stringifiedVaultList]); + }, [stringifiedVaultList, sortDirection, sortBy, sortedByName, sortedByForwardAPR, sortedByAPR, sortedByTVL, sortedByDeposited, sortedByAvailable, sortedByFeaturingScore]); return sortedVaults; } diff --git a/package.json b/package.json index d83fa0380..b56281cd2 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "@rainbow-me/rainbowkit": "^1.1.1", "@wagmi/chains": "1.8.0", "@wagmi/core": "^1.4.3", - "@yearn-finance/web-lib": "^3.0.53", + "@yearn-finance/web-lib": "^3.0.56", "axios": "^1.5.0", "dayjs": "^1.11.9", "eslint-config-prettier": "^9.0.0", diff --git a/yarn.lock b/yarn.lock index daa3e6170..aa86e6403 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3411,10 +3411,10 @@ resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== -"@yearn-finance/web-lib@^3.0.53": - version "3.0.53" - resolved "https://registry.yarnpkg.com/@yearn-finance/web-lib/-/web-lib-3.0.53.tgz#78690b9b9072ee97ccfea77b4ba78b85b8e9ba91" - integrity sha512-K5Ok27ruhztL0hY+n9dXR9YUcPo9ktdxqkzKd9cPmjrUjU4rTUfSQiq/t/vFkJH5ixJ/xCsCDrEj2/nfPW6Jvw== +"@yearn-finance/web-lib@^3.0.56": + version "3.0.56" + resolved "https://registry.yarnpkg.com/@yearn-finance/web-lib/-/web-lib-3.0.56.tgz#321e556abf0d8d8b2e4a854d70ab1fa7ec531ea0" + integrity sha512-DO3H4XHtH7jK+a4r8+rFeV3+UEnTtQWiRAldqUC0U5Oy44Hb1ha22yHulQG0yWEqw9CG6TLlWtbc2/S5V/nisw== dependencies: "@babel/core" "^7.23.0" "@headlessui/react" "^1.7.17"