-
-
Notifications
You must be signed in to change notification settings - Fork 268
feat: Add types for post-quote (withdrawal) flows #7773
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
Conversation
5160a5d to
3cbc8b4
Compare
Add type definitions for the withdrawal-to-any-token feature: - Add `isPostQuote` and `selectedToken` to TransactionData - Add `UpdateSelectedTokenRequest` type - Add `TransactionPayControllerSetIsPostQuoteAction` action type - Add `TransactionPayControllerUpdateSelectedTokenAction` action type - Add `isPostQuote` to MetamaskPayMetadata in transaction-controller - Export new types from index.ts These types enable withdrawal flows where users can select a destination token different from the withdrawal's native token.
3cbc8b4 to
9dc045f
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
| export type TransactionPayControllerSetIsPostQuoteAction = { | ||
| type: `${typeof CONTROLLER_NAME}:setIsPostQuote`; | ||
| handler: (transactionId: string, isPostQuote: boolean) => void; | ||
| }; |
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.
New action types lack corresponding handler registrations
Medium Severity
The new action types TransactionPayControllerUpdateSelectedTokenAction and TransactionPayControllerSetIsPostQuoteAction are added to the TransactionPayControllerActions union and exported, but no handlers are registered in TransactionPayController. Existing actions like setIsMaxAmount and updatePaymentToken follow a pattern where they're defined in types, have corresponding controller methods, and handlers are registered via messenger.registerActionHandler. The new action types break this pattern — calling them via the messenger will fail at runtime.
Additional Locations (1)
| * - For deposits (isPostQuote=false): This is the SOURCE/payment token | ||
| * - For withdrawals (isPostQuote=true): This is the DESTINATION token | ||
| */ | ||
| selectedToken?: TransactionPaymentToken; |
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.
I wouldn't bother renaming this yet until the entire feature is done, given the breaking change, and refactor needed in the clients.
Though we can still update the JSDoc to clarify it's broader use.
| }; | ||
|
|
||
| /** Request to update the selected token for a transaction (used for withdrawals). */ | ||
| export type UpdateSelectedTokenRequest = { |
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.
Also here, wouldn't bother with a new action type yet as we can refactor later with a dedicated breaking change PR.
| /** | ||
| * Whether this is a post-quote transaction (e.g., withdrawal flow). | ||
| * When true, the selectedToken represents the destination token, | ||
| * and the quote source is derived from the transaction's native token. |
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 isn't quite true, the source would be whatever the original transaction generated / it's output.
| * Used for Predict/Perps withdrawals where funds flow: | ||
| * withdrawal → bridge/swap → destination token | ||
| */ | ||
| isPostQuote?: boolean; |
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.
I'd usually recommend against a type only PR as easier to judge it's value when it's being utilised in new logic.
|
Closing in favor of #7783 |
Explanation
Add type definitions for the withdrawal-to-any-token feature:
isPostQuoteandselectedTokento TransactionDataUpdateSelectedTokenRequesttypeTransactionPayControllerSetIsPostQuoteActionaction typeTransactionPayControllerUpdateSelectedTokenActionaction typeisPostQuoteto MetamaskPayMetadata in transaction-controllerThese types enable withdrawal flows where users can select a destination token different from the withdrawal's native token.
References
Checklist
Note
Low Risk
Type-only additions across
transaction-controllerandtransaction-pay-controller; low runtime risk but may require downstream updates wherepaymentTokensemantics are assumed.Overview
Enables post-quote (withdrawal) flows by extending
TransactionPayControllerstate withTransactionData.isPostQuoteandselectedToken, while markingpaymentTokenas deprecated for backward compatibility.Adds new messenger action typings (
TransactionPayController:setIsPostQuote,TransactionPayController:updateSelectedToken) plusUpdateSelectedTokenRequest, and exports these new types fromtransaction-pay-controller.Extends
transaction-controller’sMetamaskPayMetadatawith an optionalisPostQuoteflag and updates both packages’ changelogs accordingly.Written by Cursor Bugbot for commit 9dc045f. This will update automatically on new commits. Configure here.