Skip to content

Commit

Permalink
chore: add permit type guard
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Mar 2, 2024
1 parent e7b3d93 commit 86c4fc6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions static/scripts/rewards/render-transaction/render-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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");

Expand All @@ -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";
}

0 comments on commit 86c4fc6

Please sign in to comment.