From ed39f9d63aba8fb606575c20c7daca1c8609b212 Mon Sep 17 00:00:00 2001 From: Jaume Alavedra Date: Thu, 8 Aug 2024 12:07:57 +0200 Subject: [PATCH] fix: minting with session key --- .../Sessions/CreateSessionButton.tsx | 2 +- ...toSession.tsx => MintNFTButtonSession.tsx} | 32 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) rename examples/apps/auth-sample/src/components/Sessions/{MintNFTButtoSession.tsx => MintNFTButtonSession.tsx} (73%) diff --git a/examples/apps/auth-sample/src/components/Sessions/CreateSessionButton.tsx b/examples/apps/auth-sample/src/components/Sessions/CreateSessionButton.tsx index 3e9b0218..f8dfc6e0 100644 --- a/examples/apps/auth-sample/src/components/Sessions/CreateSessionButton.tsx +++ b/examples/apps/auth-sample/src/components/Sessions/CreateSessionButton.tsx @@ -4,7 +4,7 @@ import {EmbeddedState} from '@openfort/openfort-js'; import Loading from '../Loading'; import openfort from '../../utils/openfortConfig'; import {ethers} from 'ethers'; -import MintNFTSessionButton from './MintNFTButtoSession'; +import MintNFTSessionButton from './MintNFTButtonSession'; const sessionMethods = [ {id: '1hour', title: '1 Hour'}, diff --git a/examples/apps/auth-sample/src/components/Sessions/MintNFTButtoSession.tsx b/examples/apps/auth-sample/src/components/Sessions/MintNFTButtonSession.tsx similarity index 73% rename from examples/apps/auth-sample/src/components/Sessions/MintNFTButtoSession.tsx rename to examples/apps/auth-sample/src/components/Sessions/MintNFTButtonSession.tsx index 9c40a2f3..eb1e6846 100644 --- a/examples/apps/auth-sample/src/components/Sessions/MintNFTButtoSession.tsx +++ b/examples/apps/auth-sample/src/components/Sessions/MintNFTButtonSession.tsx @@ -28,25 +28,21 @@ const MintNFTSessionButton: React.FC<{ } const collectResponseJSON = await collectResponse.json(); - if (collectResponseJSON.data?.nextAction) { - const message = arrayify( - collectResponseJSON.data.nextAction.payload.userOperationHash - ); - const sessionSigner = new ethers.Wallet(sessionKey); - const signature = await sessionSigner?.signMessage(message); - if (!signature) { - throw new Error('Failed to sign message with session key'); - } - - const response = await openfort.sendSignatureTransactionIntentRequest( - collectResponseJSON.transactionIntentId, - null, - signature - ); - return response?.response?.transactionHash ?? null; - } else { - return collectResponseJSON.userOperationHash; + const message = arrayify( + collectResponseJSON.nextAction.payload.userOperationHash + ); + const sessionSigner = new ethers.Wallet(sessionKey); + const signature = await sessionSigner?.signMessage(message); + if (!signature) { + throw new Error('Failed to sign message with session key'); } + + const response = await openfort.sendSignatureTransactionIntentRequest( + collectResponseJSON.transactionIntentId, + null, + signature + ); + return response?.response?.transactionHash ?? null; }, [sessionKey]); const handleMintNFT = async () => {