From 980d99f1669d9522c9402cb0211041e658f2e715 Mon Sep 17 00:00:00 2001 From: Aries Gunawan Date: Sat, 26 Oct 2024 06:02:20 -0400 Subject: [PATCH] fix: cleanup --- static/scripts/rewards/web3/erc20-permit.ts | 11 ++++++----- static/scripts/rewards/web3/erc721-permit.ts | 5 +---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/static/scripts/rewards/web3/erc20-permit.ts b/static/scripts/rewards/web3/erc20-permit.ts index 90495f83..44a37a44 100644 --- a/static/scripts/rewards/web3/erc20-permit.ts +++ b/static/scripts/rewards/web3/erc20-permit.ts @@ -10,7 +10,6 @@ import { toaster, errorToast, MetaMaskError } from "../toaster"; import { connectWallet } from "./connect-wallet"; import { convertToNetworkId } from "./use-rpc-handler"; import { decodeError } from "@ariesgun/ethers-decode-error"; -// import { decodeError } from "./error-decoder"; export async function fetchTreasury(permit: Permit): Promise<{ balance: BigNumber; allowance: BigNumber; decimals: number; symbol: string }> { let balance: BigNumber, allowance: BigNumber, decimals: number, symbol: string; @@ -91,6 +90,7 @@ export async function transferFromPermit(permit2Contract: Contract, reward: Perm buttonController.hideLoader(); buttonController.showMakeClaim(); } else { + console.error(e); const { error } = decodeError(e, permit2Abi); errorToast(e, `Error in permitTransferFrom: ${error}`); } @@ -273,11 +273,12 @@ invalidateButton.addEventListener("click", async function invalidateButtonClickH if (!app.signer) return; await invalidateNonce(app.signer, app.reward.nonce); - } catch (error: unknown) { - if (error instanceof Error) { - const e = error as unknown as MetaMaskError; + } catch (err: unknown) { + if (err instanceof Error) { + const e = err as unknown as MetaMaskError; console.error(e); - errorToast(e, e.reason); + const { error } = decodeError(e, permit2Abi); + errorToast(e, `Error in invalidateNonce: ${error}`); return; } } diff --git a/static/scripts/rewards/web3/erc721-permit.ts b/static/scripts/rewards/web3/erc721-permit.ts index d346c936..adc26039 100644 --- a/static/scripts/rewards/web3/erc721-permit.ts +++ b/static/scripts/rewards/web3/erc721-permit.ts @@ -32,11 +32,8 @@ export function claimErc721PermitHandler(reward: ERC721Permit) { } buttonController.showLoader(); - - const nftContract = new ethers.Contract(reward.tokenAddress, nftRewardAbi, signer); - if (!nftContract) return; - try { + const nftContract = new ethers.Contract(reward.tokenAddress, nftRewardAbi, signer); const tx: TransactionResponse = await nftContract.safeMint( { beneficiary: reward.beneficiary,