diff --git a/unlock-app/src/components/interface/checkout/main/Returning.tsx b/unlock-app/src/components/interface/checkout/main/Returning.tsx index 84c90ba73c1..7ae80525ef2 100644 --- a/unlock-app/src/components/interface/checkout/main/Returning.tsx +++ b/unlock-app/src/components/interface/checkout/main/Returning.tsx @@ -25,12 +25,12 @@ interface Props { export function Returning({ checkoutService, onClose, communication }: Props) { const config = useConfig() - const { - paywallConfig, - lock, - messageToSign: signedMessage, - } = useSelector(checkoutService, (state) => state.context) + const { paywallConfig, lock, messageToSign } = useSelector( + checkoutService, + (state) => state.context + ) const { account, getWalletService } = useAuth() + const [signedMessage, setSignedMessage] = useState(messageToSign) const [hasMessageToSign, setHasMessageToSign] = useState( !signedMessage && paywallConfig.messageToSign ) @@ -46,6 +46,7 @@ export function Returning({ checkoutService, onClose, communication }: Props) { 'personal_sign' ) setIsSigningMessage(false) + setSignedMessage({ address: account!, signature }) checkoutService.send({ type: 'SIGN_MESSAGE', signature, @@ -126,7 +127,7 @@ export function Returning({ checkoutService, onClose, communication }: Props) { }`} > onClose()} + onClick={() => onClose(signedMessage)} returnLabel="Return" checkoutService={checkoutService} /> diff --git a/unlock-app/src/components/interface/checkout/main/checkoutMachine.ts b/unlock-app/src/components/interface/checkout/main/checkoutMachine.ts index f7d678b9263..6e97b044013 100644 --- a/unlock-app/src/components/interface/checkout/main/checkoutMachine.ts +++ b/unlock-app/src/components/interface/checkout/main/checkoutMachine.ts @@ -679,6 +679,9 @@ export const checkoutMachine = createMachine( }, RETURNING: { on: { + SIGN_MESSAGE: { + actions: ['signMessage'], + }, MAKE_ANOTHER_PURCHASE: [ { target: 'METADATA', diff --git a/unlock-app/src/components/interface/checkout/main/index.tsx b/unlock-app/src/components/interface/checkout/main/index.tsx index 511aaaafc28..ab238aa1c92 100644 --- a/unlock-app/src/components/interface/checkout/main/index.tsx +++ b/unlock-app/src/components/interface/checkout/main/index.tsx @@ -78,6 +78,9 @@ export function Checkout({ } }, [account, communication]) + const messageToSignSignature = messageToSign?.signature + const messageToSignSigner = messageToSign?.address + const onClose = useCallback( (params: Record = {}) => { // Reset the Paywall State! @@ -90,14 +93,17 @@ export function Checkout({ redirect.searchParams.append('error', 'access-denied') } - if (paywallConfig.messageToSign && !messageToSign) { - redirect.searchParams.append('error', 'user did not sign message') - } + if (!params.signature) { + if (paywallConfig.messageToSign && !messageToSignSignature) { + redirect.searchParams.append('error', 'user did not sign message') + } - if (messageToSign) { - redirect.searchParams.append('signature', messageToSign.signature) - redirect.searchParams.append('address', messageToSign.address) + if (messageToSignSignature) { + redirect.searchParams.append('signature', messageToSignSignature) + redirect.searchParams.append('address', messageToSignSigner) + } } + for (const [key, value] of Object.entries(params)) { redirect.searchParams.append(key, value) } @@ -109,13 +115,14 @@ export function Checkout({ } }, [ + checkoutService, handleClose, redirectURI, communication, mint, - messageToSign, paywallConfig.messageToSign, - checkoutService, + messageToSignSignature, + messageToSignSigner, ] )