Skip to content

Commit

Permalink
fix: create invalidator actions after render
Browse files Browse the repository at this point in the history
  • Loading branch information
pbkompasz committed Aug 22, 2024
1 parent 7945889 commit b34821f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { decodePermits } from "@ubiquibot/permit-generation/handlers";
import { Permit } from "@ubiquibot/permit-generation/types";
import { app, AppState } from "../app-state";
import { buttonControllers, toaster } from "../toaster";
import { checkRenderInvalidatePermitAdminControl, checkRenderMakeClaimControl } from "../web3/erc20-permit";
import { checkRenderInvalidatePermitAdminControl, checkRenderMakeClaimControl, createInvalidatorActions } from "../web3/erc20-permit";
import { setClaimMessage } from "./set-claim-message";
import { useRpcHandler } from "../web3/use-rpc-handler";
import { renderTransaction } from "./render-transaction";
Expand Down Expand Up @@ -128,4 +128,5 @@ async function displayRewardsWithDetails() {
// The first claim's table is populated last
await renderTransaction(app.claims[0], tableEl);
displayRewardDetails(tableEl);
createInvalidatorActions();
}
58 changes: 30 additions & 28 deletions static/scripts/rewards/web3/erc20-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,36 +267,38 @@ export async function checkRenderInvalidatePermitAdminControl(app: AppState) {
}
}

for (let i = 0; i < app.claims.length; i++) {
const claim = app.claims[i];
const table = document.getElementById(claim.nonce) as HTMLElement;
const invalidateButton = table.querySelector(".invalidator");
if (!invalidateButton) {
console.log("Error initializing invalidator");
break;
}
invalidateButton.addEventListener("click", async function invalidateButtonClickHandler() {
try {
const isClaimed = await isNonceClaimed(claim);
if (isClaimed) {
toaster.create("error", `This reward has already been claimed or invalidated.`);
buttonControllers[claim.nonce].hideInvalidator();
return;
}
export function createInvalidatorActions() {
for (let i = 0; i < app.claims.length; i++) {
const claim = app.claims[i];
const table = document.getElementById(claim.nonce) as HTMLElement;
const invalidateButton = table.querySelector(".invalidator");
if (!invalidateButton) {
console.log("Error initializing invalidator");
break;
}
invalidateButton.addEventListener("click", async function invalidateButtonClickHandler() {
try {
const isClaimed = await isNonceClaimed(claim);
if (isClaimed) {
toaster.create("error", `This reward has already been claimed or invalidated.`);
buttonControllers[claim.nonce].hideInvalidator();
return;
}

if (!app.signer) return;
await invalidateNonce(app.signer, claim.nonce);
} catch (error: unknown) {
if (error instanceof Error) {
const e = error as unknown as MetaMaskError;
console.error(e);
errorToast(e, e.reason);
return;
if (!app.signer) return;
await invalidateNonce(app.signer, claim.nonce);
} catch (error: unknown) {
if (error instanceof Error) {
const e = error as unknown as MetaMaskError;
console.error(e);
errorToast(e, e.reason);
return;
}
}
}
toaster.create("info", "Nonce invalidation transaction sent");
buttonControllers[claim.nonce].hideInvalidator();
});
toaster.create("info", "Nonce invalidation transaction sent");
buttonControllers[claim.nonce].hideInvalidator();
});
}
}

//mimics https://github.com/Uniswap/permit2/blob/a7cd186948b44f9096a35035226d7d70b9e24eaf/src/SignatureTransfer.sol#L150
Expand Down

0 comments on commit b34821f

Please sign in to comment.