From d5e877fae4c229ae26bbcc13ef6a8adac49a7794 Mon Sep 17 00:00:00 2001 From: xavikh Date: Fri, 15 Mar 2024 11:57:09 +0100 Subject: [PATCH] Add user rejected alert --- hooks/usePermit.ts | 30 +++++++++++++------- plugins/lockToVote/hooks/useProposalVeto.tsx | 1 - 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/hooks/usePermit.ts b/hooks/usePermit.ts index f4b8124f..cd058884 100644 --- a/hooks/usePermit.ts +++ b/hooks/usePermit.ts @@ -32,7 +32,7 @@ export function usePermit() { }); const [nonceResult, nameResult, versionResult] = erc20data || []; - const { signTypedDataAsync: permitSign, status: permitSignStatus } = useSignTypedData(); + const { signTypedDataAsync: permitSign, status: permitSignStatus, error: permitSignError } = useSignTypedData(); useEffect(() => { switch (permitSignStatus) { @@ -40,7 +40,13 @@ export function usePermit() { case "pending": return; case "error": - addAlert("Could not sign the permit", { type: "error", timeout: 1500 }); + if (permitSignError?.message?.startsWith("User rejected the request")) { + addAlert("Transaction rejected by the user", { + timeout: 4 * 1000, + }); + } else { + addAlert("Could not sign the permit", { type: "error", timeout: 1500 }); + } return; case "success": addAlert("Permit signed", { type: "success", timeout: 1500 }); @@ -81,15 +87,19 @@ export function usePermit() { deadline, }; - let sig = await permitSign({ - account: account_address, - types, - domain, - primaryType: 'Permit', - message, - }); + try { + let sig = await permitSign({ + account: account_address, + types, + domain, + primaryType: 'Permit', + message, + }); - return hexToSignature(sig); + return hexToSignature(sig); + } catch (e) { + return; + } }; return { diff --git a/plugins/lockToVote/hooks/useProposalVeto.tsx b/plugins/lockToVote/hooks/useProposalVeto.tsx index bd05aee5..8406e0dd 100644 --- a/plugins/lockToVote/hooks/useProposalVeto.tsx +++ b/plugins/lockToVote/hooks/useProposalVeto.tsx @@ -61,7 +61,6 @@ export function useProposalVeto(proposalId: string) { timeout: 4 * 1000, }); } else { - console.error(vetoingError); addAlert("Could not create the veto", { type: "error" }); } return;