Skip to content

Commit

Permalink
fix: classic zap crash
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Oct 3, 2023
1 parent 837d838 commit 7213438
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/hooks/useContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ export function useContract(
): Contract | null {
const { account, isEVM } = useActiveWeb3React()
const { library } = useWeb3React()
const { readProvider } = useKyberSwapConfig()

const lib = useMemo(() => (account ? library : readProvider), [account, library, readProvider])

return useMemo(() => {
if (!isEVM || !address || !ABI || !library) return null
if (!isEVM || !address || !ABI || !lib) return null
try {
return getContract(address, ABI, library, withSignerIfPossible && account ? account : undefined)
return getContract(address, ABI, lib as any, withSignerIfPossible && account ? account : undefined)
} catch (error) {
console.error('Failed to get contract', error)
return null
}
}, [address, ABI, library, withSignerIfPossible, account, isEVM])
}, [address, ABI, lib, withSignerIfPossible, account, isEVM])
}

export function useContractForReading(
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useZap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ export const useZapInAmounts = (
if (tokenIn && tokenOut && pool && userIn?.gt(0)) {
const amounts = await calculateZapInAmounts(tokenIn, tokenOut, pool, userIn)

setResult({
amounts,
error: undefined,
})
if (amounts)
setResult({
amounts,
error: undefined,
})
}
} catch (err) {
setResult({
Expand Down

0 comments on commit 7213438

Please sign in to comment.