New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support onCancel #1175
feat: support onCancel #1175
Conversation
🦋 Changeset detectedLatest commit: a616e7f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/blockstack/stacks-wallet-web/Gh7Q9M1SdedhXRfA7PVyED9cDwvB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I think this is really fantastic! Just left a couple comments and then will do a follow up review after you've made updates
b90ce2a
to
6672918
Compare
src/extension/message-types.ts
Outdated
// export interface TxResult extends SponsoredFinishedTxPayload { | ||
// txId?: string; | ||
// } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this bc I think it was just left by mistake?
I addressed code comments and will put up the related PR in |
6672918
to
43b51ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set up connect and the extension this morning and ran through these changes.
I think it'd be better to reject
the promise when the user cancels, rather than altering the resolve
data. This is a small change, and just requires reject
ing in the inpage.ts
file
transactionRequest: async transactionRequest => {
const event = new CustomEvent<TransactionRequestEventDetails>(DomEventName.transactionRequest, {
detail: { transactionRequest },
});
document.dispatchEvent(event);
return new Promise((resolve, reject) => {
const handleMessage = (event: MessageEvent<TransactionResponseMessage>) => {
console.log('message in inpage.ts', event);
if (!isValidEvent(event, Methods.transactionResponse)) return;
if (event.data.payload?.transactionRequest !== transactionRequest) return;
window.removeEventListener('message', handleMessage);
if (event.data.payload.transactionResponse.cancel) {
reject(event.data.payload.transactionResponse);
return;
}
resolve(event.data.payload.transactionResponse);
};
window.addEventListener('message', handleMessage);
});
},
Also there are two scenarios I noticed where the callback isn't fired:
- Logged out state where you need to enter your password
- When signed in, but there are async actions running and you close before they finish
We need to find an earlier way to set up the close listener, even before the transaction page.
window.addEventListener('beforeunload', handleUnmount); | ||
return () => window.removeEventListener('beforeunload', handleUnmount); | ||
}, [handleUnmount]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only component I found during auth that doesn't use the PopupContainer
so not great to have duplicate code here. Can this be wrapped in the PopupContainer
? Why is this a Screen
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 from me, can make other changes later. Per comment, as some of these decisions are temporary, a comment wouldn't go a miss.
Just circled back and remembered this, maybe I should use this approach at least for now and change the conditional check in |
f68fc59
to
f19ab3c
Compare
f19ab3c
to
1aafe6a
Compare
1aafe6a
to
29f828e
Compare
Tests are going to fail here until it points at the changes in |
29f828e
to
1d988d2
Compare
1d988d2
to
1437d45
Compare
1437d45
to
8ac1fe5
Compare
8ac1fe5
to
a616e7f
Compare
Description
This PR adds the ability for the developer to use an
onCancel
callback function fromconnect
when a user closes/cancels a transaction window.This is PR is in
Draft
status bc the callback is working, but I'm not sure what we actually want to do with the transaction during this process or what (if any) data we would want to return to the developer in theonCancel
callback?For details refer to issue #959
connect
PR: hirosystems/connect#122Type of Change
Does this introduce a breaking change?
No.
Are documentation updates required?
No.
Testing information
TBD.
Checklist