-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: use last selected payment detail instead of deducing from approval amount #37409
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: use last selected payment detail instead of deducing from approval amount #37409
Conversation
… error couldn't happen
…-subscription-after-confirm
…-subscription-after-confirm
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [ddcfa60]
UI Startup Metrics (1273 ± 93 ms)
|
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [aa69533]
UI Startup Metrics (1261 ± 82 ms)
|
Builds ready [55fb0b6]
UI Startup Metrics (1242 ± 106 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
| plan: RECURRING_INTERVALS.month, | ||
| paymentTokenAddress: '0x1234567890123456789012345678901234567890', | ||
| type: PAYMENT_TYPES.byCrypto, | ||
| }; |
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.
Bug: Mismatched Token Addresses Break Test Token Display
The test data has mismatched token addresses. The paymentTokenAddress in mockLastUsedPaymentDetail does not align with the token address defined in mockSubscriptionPricing. This causes selectedTokenPrice to be undefined, which means the test might not accurately reflect the component's intended behavior or display the correct token symbol.
| decodeResponse?.pending || | ||
| !decimals || | ||
| productPricePending; | ||
| const isLoading = decodeResponse?.pending || !decimals; |
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.
Bug: Cross-Chain Token Price Mismatch and Selection Flaw
The selectedTokenPrice logic now flattens tokens across chains and matches only by address, risking incorrect token selection. This also creates a mismatch where selectedTokenPrice is derived from the last used payment token, but the EstimatedChanges component uses the current transaction's token, potentially displaying incorrect token details for the transaction.
…val amount (#37409) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> Fix subscription crypto approval screen loading flicker by using lastSelectedPaymentDetail instead of deducting from transaction approval amount [](https://codespaces.new/MetaMask/metamask-extension/pull/37409?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: fix subscription crypto approval screen loading flicker ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to shield plan screen 2. Select crypto payment method 3. Crypto approval transaction confirm screen should only show loading once ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Use cached last-selected payment method to render Shield crypto approval pricing and token, removing the deduction-from-approval logic and updating tests. > > - **Confirmations UI (Shield crypto approval)**: > - Derives `productPrice` and token info from cached `lastSelectedPaymentMethod` and pricing (`useSubscriptionPricing`, `useSubscriptionProductPlans`, `useSubscriptionPaymentMethods`). > - Computes `approvalAmount` via decoded data + asset `decimals`, simplifies loading state, and passes `productPrice`/`tokenSymbol` to child components. > - **Hooks**: > - Removes `useShieldSubscriptionPricingFromTokenApproval` and associated imports/logic from `useSubscriptionPricing`. > - **Tests**: > - Updates `shield-subscription-approve.test.tsx` to mock pricing and `lastSelectedPaymentMethod`; verifies monthly pricing/trial and UI sections. > - Cleans up `useSubscriptionPricing.test.ts` by removing tests for the deleted hook; retains tests for pricing, product plans, and payment methods. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 55fb0b6. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Chaitanya Potti <[email protected]>
Builds ready [0602d99]
UI Startup Metrics (1211 ± 97 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [efacdee]
UI Startup Metrics (1232 ± 116 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Description
Fix subscription crypto approval screen loading flicker by using lastSelectedPaymentDetail instead of deducting from transaction approval amount
Changelog
CHANGELOG entry: fix subscription crypto approval screen loading flicker
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Use cached last-selected payment details and pricing to render the Shield crypto approval screen, removing approval-amount deduction logic and its tests.
useShieldSubscriptionPricingFromTokenApprovalwith selector-driven data: readlastSelectedPaymentMethod, pricing, plans, and crypto payment method to deriveproductPriceand token info.approvalAmountviauseMemo; simplify loading state (no async price deduction).productPriceandtokenSymboltoEstimatedChanges; retainBillingDetailswhenproductPriceexists.useShieldSubscriptionPricingFromTokenApprovalfromuseSubscriptionPricing.ts.pricingandlastSelectedPaymentMethodin state and assert rendered pricing/trial details.Written by Cursor Bugbot for commit efacdee. This will update automatically on new commits. Configure here.