Skip to content

Commit

Permalink
fix: minting with session key
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalavedra committed Aug 8, 2024
1 parent 28a425b commit ed39f9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit ed39f9d

Please sign in to comment.