Skip to content

Conversation

@tuna1207
Copy link
Member

@tuna1207 tuna1207 commented Nov 6, 2025

Description

Previously in shield plan screen, when user change plan, the selected token approval amount didn't get updated hence user will see outdated approval amount in the confirmation screen
This PR reset the selected token when plan change to get correct latest approval amount

Open in GitHub Codespaces

Changelog

CHANGELOG entry: fix incorrect token approval amount when change shield plan

Related issues

Fixes:

Manual testing steps

  1. shield plan page
  2. select a plan and go to confirm page
  3. go back and select a different plan
  4. go to confirm page should reflect the new approval amount

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • 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.

Note

Refactors token balance hook to return {availableTokenBalances, pending, error} and updates Shield Plan to await balances and reset selected token on plan change, ensuring approval amounts reflect the selected plan.

  • Hooks:
    • useAvailableTokenBalances
      • Now returns { availableTokenBalances, pending, error } instead of just an array.
      • Replaces local state/effect with useAsyncResult for fetching approval amounts.
      • Handles missing price/token map by returning empty results; logs when token info is absent.
  • Shield Plan Page:
    • Consumes pending from useAvailableTokenBalances and delays token selection until ready.
    • Resets selectedToken when selectedPlan changes.
    • Only reuses last-used token when it matches the last-used plan.
    • Maintains defaulting payment method to crypto when a token is selected.

Written by Cursor Bugbot for commit f31aec5. This will update automatically on new commits. Configure here.

@metamaskbot metamaskbot added the team-web3auth Web3Auth team label Nov 6, 2025
@tuna1207 tuna1207 marked this pull request as ready for review November 6, 2025 15:49
@github-actions github-actions bot added the size-M label Nov 6, 2025
getAvailableTokenBalances();
}, [price, productType, paymentChainTokenMap, validTokenBalances]);
return availableTokens;
}, [price, paymentChainTokenMap, validTokenBalances]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Stale Data from Missing Dependency in Async Call

Missing productType in the useAsyncResult dependency array. The async function uses productType on line 125 (getSubscriptionCryptoApprovalAmount call), but it's not included in the dependency array on line 160. The old code (using useEffect) had productType in its dependencies. Without it, if productType changes, the async function won't re-execute with the new value, leading to stale data being used for approval amount calculations.

Fix in Cursor Fix in Web

@metamaskbot
Copy link
Collaborator

Builds ready [50a1e6e]
UI Startup Metrics (1205 ± 90 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup1205104414609012721346
load104290812608311181163
domContentLoaded103690512568211081157
domInteractive2113114161752
firstPaint64685122441510651155
backgroundConnect2262152647229238
firstReactRender25184352835
getState2174992538
initialActions001001
loadScripts816685102982884935
setupStore1062331118
numNetworkReqs1367620673
BrowserifyPower User HomeuiStartup19411714255423621292554
load1024897142817412271428
domContentLoaded1017889141717312191417
domInteractive311587256587
firstPaint43115012223349021222
backgroundConnect24022529517247295
firstReactRender29254042940
getState18014823222199232
initialActions002112
loadScripts78767111321629911132
setupStore1292741127
numNetworkReqs1167324762170247
WebpackStandard HomeuiStartup8206941134928251060
load60455091982596848
domContentLoaded59754190579591832
domInteractive15115081441
firstPaint19857909190199738
backgroundConnect241176142655
firstReactRender28176293337
getState1053341216
initialActions001001
loadScripts59453989477589822
setupStore1052731217
numNetworkReqs1367619871
WebpackPower User HomeuiStartup12461134154613512711546
load644568908106711908
domContentLoaded63156387299694872
domInteractive221269163369
firstPaint33058802266586802
backgroundConnect52161945247194
firstReactRender25232922729
getState14710516518161165
initialActions001011
loadScripts62756186296683862
setupStore1062661126
numNetworkReqs1086817141165171
FirefoxBrowserifyStandard HomeuiStartup15111315192111315761720
load1285112515768813461419
domContentLoaded1285112415768813461419
domInteractive1223436160127266
firstPaint------
backgroundConnect4726133215395
firstReactRender26216462742
getState8412412818
initialActions001001
loadScripts1257109815458313181374
setupStore1263351327
numNetworkReqs1265814755
BrowserifyPower User HomeuiStartup23502078274820625462748
load12841111166218814121662
domContentLoaded12841110166218814121662
domInteractive19577616179303616
firstPaint------
backgroundConnect952839793126397
firstReactRender422967115067
getState1358619433173194
initialActions101111
loadScripts12571090163818513601638
setupStore27797294097
numNetworkReqs1336921762204217
WebpackStandard HomeuiStartup16351481202213116661944
load14061247173010414521650
domContentLoaded14061247173010414511650
domInteractive1063234350113201
firstPaint------
backgroundConnect49252302954115
firstReactRender29237692942
getState94488722
initialActions001001
loadScripts1375123017029814151564
setupStore15687131350
numNetworkReqs1367017766
WebpackPower User HomeuiStartup24962106340935226553409
load15621328201520616952015
domContentLoaded15621326201520616942015
domInteractive16672470120287470
firstPaint------
backgroundConnect953225373143253
firstReactRender33284753647
getState1156417328140173
initialActions106116
loadScripts15241305192018816491920
setupStore26967163867
numNetworkReqs1306131588206315
📊 Page Load Benchmark Results

Current Commit: 50a1e6e | Date: 11/6/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±53ms) 🟡 | historical mean value: 1.04s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 727ms (±51ms) 🟢 | historical mean value: 728ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 78ms (±14ms) 🟢 | historical mean value: 77ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 53ms 1.01s 1.35s 1.06s 1.35s
domContentLoaded 727ms 51ms 701ms 1.01s 740ms 1.01s
firstPaint 78ms 14ms 60ms 204ms 84ms 204ms
firstContentfulPaint 78ms 14ms 60ms 204ms 84ms 204ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 58 Bytes (0%)
  • ui: 166 Bytes (0%)
  • common: 20 Bytes (0%)

@metamaskbot
Copy link
Collaborator

Builds ready [f31aec5]
UI Startup Metrics (1206 ± 119 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyStandard HomeuiStartup1206962151611912781420
load1033836130610710901221
domContentLoaded1025831129510710841217
domInteractive2114113141952
firstPaint68284130541510601208
backgroundConnect20517229126219258
firstReactRender22165152332
getState1975392438
initialActions001001
loadScripts8286511061978871007
setupStore1062221114
numNetworkReqs1367620674
BrowserifyPower User HomeuiStartup18761572237023521082370
load1032888153520312971535
domContentLoaded1024881150319812881503
domInteractive291574184874
firstPaint860194154240713021542
backgroundConnect2312212579236257
firstReactRender28253842838
getState17115220816181208
initialActions001011
loadScripts800661127119610561271
setupStore14103881238
numNetworkReqs1397332288242322
WebpackStandard HomeuiStartup821704117881829966
load602557100271606730
domContentLoaded59654997468601718
domInteractive16115591443
firstPaint188571013179193576
backgroundConnect231175132453
firstReactRender29186183438
getState1161821214
initialActions001001
loadScripts59354696366599707
setupStore1163141318
numNetworkReqs1367319670
WebpackPower User HomeuiStartup11971041175319912231753
load599521870105643870
domContentLoaded57750678589604785
domInteractive211253143353
firstPaint38377788255608788
backgroundConnect721630485162304
firstReactRender26232712627
getState1247515324138153
initialActions001001
loadScripts57350477887596778
setupStore1063681036
numNetworkReqs1257122853166228
FirefoxBrowserifyStandard HomeuiStartup14531283182310015091670
load1239110214057513091356
domContentLoaded1239110214057513091355
domInteractive1203333056122218
firstPaint------
backgroundConnect4225144204789
firstReactRender25214142535
getState74384715
initialActions001001
loadScripts1215108713737112841331
setupStore1375171227
numNetworkReqs1266415755
BrowserifyPower User HomeuiStartup27312322373840129703738
load15501265203025418482030
domContentLoaded15501264202925518472029
domInteractive22796665189301665
firstPaint------
backgroundConnect11732370114149370
firstReactRender463271115471
getState1448621439191214
initialActions506816168
loadScripts15141240198624717721986
setupStore63753412550534
numNetworkReqs1347130773204307
WebpackStandard HomeuiStartup17101530229414717552079
load14491289186810014921633
domContentLoaded14491289186710014921633
domInteractive1053239948112175
firstPaint------
backgroundConnect57292934059122
firstReactRender32248293346
getState11421823740
initialActions001001
loadScripts1412125718379514611589
setupStore17874121649
numNetworkReqs1366918767
WebpackPower User HomeuiStartup25362210295023727942950
load15311266185517116561855
domContentLoaded15301266185417116561854
domInteractive17337541150301541
firstPaint------
backgroundConnect88372577284257
firstReactRender44316295262
getState1396119243181192
initialActions106116
loadScripts15021243180016616261800
setupStore3571444531144
numNetworkReqs1326731474191314
📊 Page Load Benchmark Results

Current Commit: f31aec5 | Date: 11/7/2025

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±39ms) 🟡 | historical mean value: 1.03s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 722ms (±36ms) 🟢 | historical mean value: 718ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 77ms (±14ms) 🟢 | historical mean value: 76ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 39ms 1.01s 1.32s 1.07s 1.32s
domContentLoaded 722ms 36ms 699ms 990ms 732ms 990ms
firstPaint 77ms 14ms 60ms 200ms 88ms 200ms
firstContentfulPaint 77ms 14ms 60ms 200ms 88ms 200ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 669 Bytes (0.01%)
  • ui: 3.48 KiB (0.05%)
  • common: 62 Bytes (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants