Skip to content

Commit

Permalink
Update Permit2 hook to work with ERC-6492
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed May 31, 2024
1 parent a8ff911 commit 026bdf9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions shared/src/hooks/UsePermit2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ export function usePermit2(chain: Chain, token: Token, owner: Address, spender:
resetSignature();
}, [resetSignature, permitTransferFrom]);

// parse signature, in case encoded with extra ERC-6492 data
const parsedSignature = useMemo(() => {
if (!signature) return;
return parseErc6492Signature(signature).signature;
}, [signature]);

let state: Permit2State;
let action: (() => void) | undefined;

Expand All @@ -279,7 +285,7 @@ export function usePermit2(chain: Chain, token: Token, owner: Address, spender:
} else if (isAskingUserToSign) {
state = Permit2State.ASKING_USER_TO_SIGN;
action = undefined;
} else if (signature === undefined) {
} else if (parsedSignature === undefined) {
state = Permit2State.READY_TO_SIGN;
action = () =>
signTypedData({
Expand All @@ -300,7 +306,7 @@ export function usePermit2(chain: Chain, token: Token, owner: Address, spender:
amount,
nonce,
deadline,
signature: signature as `0x${string}` | undefined,
signature: parsedSignature,
},
};
}

0 comments on commit 026bdf9

Please sign in to comment.