From 86c4fc6e2e4f320287864e6538f160bb4c85b750 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Sat, 2 Mar 2024 20:51:36 +0000 Subject: [PATCH] chore: add permit type guard --- .../render-transaction/render-transaction.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/static/scripts/rewards/render-transaction/render-transaction.ts b/static/scripts/rewards/render-transaction/render-transaction.ts index cfcc4aca..4a1ef014 100644 --- a/static/scripts/rewards/render-transaction/render-transaction.ts +++ b/static/scripts/rewards/render-transaction/render-transaction.ts @@ -5,11 +5,10 @@ import { claimErc20PermitHandlerWrapper, fetchFundingWallet, generateInvalidateP import { claimErc721PermitHandler } from "../web3/erc721-permit"; import { verifyCurrentNetwork } from "../web3/verify-current-network"; import { insertErc20PermitTableData, insertErc721PermitTableData } from "./insert-table-data"; -import { displayRewardDetails, displayRewardPagination } from "./read-claim-data-from-url"; import { renderEnsName } from "./render-ens-name"; import { renderNftSymbol, renderTokenSymbol } from "./render-token-symbol"; import { setPagination } from "./set-pagination"; -import { Erc721Permit } from "./tx-type"; +import { Erc20Permit, RewardPermit } from "./tx-type"; type Success = boolean; @@ -37,7 +36,7 @@ export async function renderTransaction(app: AppState, nextTx?: boolean): Promis verifyCurrentNetwork(app.reward.networkId).catch(console.error); - if (app.reward.type === "erc20-permit") { + if (permitCheck(app.reward)) { const treasury = await fetchFundingWallet(app); // insert tx data into table @@ -60,7 +59,7 @@ export async function renderTransaction(app: AppState, nextTx?: boolean): Promis claimButton.element.addEventListener("click", claimErc20PermitHandlerWrapper(app)); table.setAttribute(`data-claim`, "ok"); - } else if (app.reward.type === "erc721-permit") { + } else { const requestedAmountElement = insertErc721PermitTableData(app.reward, table); table.setAttribute(`data-claim`, "ok"); @@ -75,8 +74,12 @@ export async function renderTransaction(app: AppState, nextTx?: boolean): Promis const toElement = document.getElementById(`rewardRecipient`) as Element; renderEnsName({ element: toElement, address: app.reward.transferDetails.to }).catch(console.error); - claimButton.element.addEventListener("click", claimErc721PermitHandler(app.reward as Erc721Permit)); + claimButton.element.addEventListener("click", claimErc721PermitHandler(app.reward)); } return true; } + +function permitCheck(permit: RewardPermit): permit is Erc20Permit { + return permit.type === "erc20-permit"; +}