Skip to content

Commit

Permalink
fix: use forknet
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 16, 2023
1 parent 33da362 commit eb92587
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
14 changes: 11 additions & 3 deletions apps/common/contexts/useWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TChainTokens> => {
Expand Down Expand Up @@ -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 <WalletContext.Provider value={contextValue}>{children}</WalletContext.Provider>;
Expand Down
13 changes: 11 additions & 2 deletions apps/common/utils/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -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]
Expand All @@ -64,7 +73,7 @@ export async function allowanceOf(props: TAllowanceOf): Promise<bigint> {
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',
Expand Down
18 changes: 12 additions & 6 deletions apps/vaults/hooks/useSortVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);

Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit eb92587

Please sign in to comment.