Skip to content

Commit

Permalink
fix(unlock-app): fixing event signature on returning state (#14848)
Browse files Browse the repository at this point in the history
  • Loading branch information
julien51 authored Oct 17, 2024
1 parent 569f507 commit 347e261
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
13 changes: 7 additions & 6 deletions unlock-app/src/components/interface/checkout/main/Returning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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,
Expand Down Expand Up @@ -126,7 +127,7 @@ export function Returning({ checkoutService, onClose, communication }: Props) {
}`}
>
<ReturningButton
onClick={() => onClose()}
onClick={() => onClose(signedMessage)}
returnLabel="Return"
checkoutService={checkoutService}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ export const checkoutMachine = createMachine(
},
RETURNING: {
on: {
SIGN_MESSAGE: {
actions: ['signMessage'],
},
MAKE_ANOTHER_PURCHASE: [
{
target: 'METADATA',
Expand Down
23 changes: 15 additions & 8 deletions unlock-app/src/components/interface/checkout/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export function Checkout({
}
}, [account, communication])

const messageToSignSignature = messageToSign?.signature
const messageToSignSigner = messageToSign?.address

const onClose = useCallback(
(params: Record<string, string> = {}) => {
// Reset the Paywall State!
Expand All @@ -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)
}
Expand All @@ -109,13 +115,14 @@ export function Checkout({
}
},
[
checkoutService,
handleClose,
redirectURI,
communication,
mint,
messageToSign,
paywallConfig.messageToSign,
checkoutService,
messageToSignSignature,
messageToSignSigner,
]
)

Expand Down

0 comments on commit 347e261

Please sign in to comment.