From 9bbfb67f0adc805ecdfa7ae2ce0acf85162cd0ff Mon Sep 17 00:00:00 2001 From: Nguyen Van Viet Date: Wed, 13 Dec 2023 15:32:39 +0700 Subject: [PATCH] fix wrap/unwrap when wallet is not connected (#2448) --- src/hooks/useContract.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hooks/useContract.ts b/src/hooks/useContract.ts index 1c643279fd..8b6fa3c953 100644 --- a/src/hooks/useContract.ts +++ b/src/hooks/useContract.ts @@ -126,9 +126,12 @@ export function useTokenReadingContract(tokenAddress?: string, customChainId?: C } export function useWETHContract(customChainId?: ChainId): Contract | null { - const { chainId: walletChainId } = useActiveWeb3React() + const { chainId: walletChainId, account } = useActiveWeb3React() const chainId = customChainId || walletChainId - return useSigningContract(WETH[chainId].address, WETH_ABI) + const signContract = useSigningContract(WETH[chainId].address, WETH_ABI) + const readContract = useReadingContract(WETH[chainId].address, WETH_ABI) + + return account ? signContract : readContract } export function useArgentWalletDetectorContract(): Contract | null {