Commit 9991a94
authored
fix(rewards): musd calculator (#30160)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until this PR meets the canonical
Definition of Ready For Review in `docs/readme/ready-for-review.md`.
In short: the template must be materially complete (not just section
titles
present), all status checks must be currently passing, and the only
expected
follow-up commits must be reviewer-driven.
-->
## **Description**
https://consensyssoftware.atlassian.net/browse/RWDS-1294
https://consensyssoftware.atlassian.net/browse/RWDS-1295
https://consensyssoftware.atlassian.net/browse/RWDS-1297
- Updated the mUSD calculator screen container to align better with
other Rewards views and avoid unnecessary nested keyboard handling.
- Moved keyboard handling into MusdCalculatorTab with
KeyboardAwareScrollView so the amount input stays visible while editing.
- Simplified calculator state: raw string for the text input, numeric
amount for slider and earnings calculations.
- Normalized amount input to strip decorations, limit to two decimal
places, and cap values at 10,000.
- Reused the shared formatUsd utility instead of local fiat
formatter/BigNumber wiring.
- Refactored slider gesture handling to separate tap and pan behavior,
fixing resets when tapping or long-pressing the slider.
- Removed unnecessary input focus/end-edit/submit handlers.
- Removed unnecessary useMemo usage for simple labels and earnings
calculations.
- Added regression tests for keyboard-aware behavior, input
normalization, amount capping, and slider reset cases.
<!--
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?
-->
## **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: null
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: my feature name
Scenario: user [verb for user action]
Given [describe expected initial app state]
When user [verb for user action]
Then [describe expected outcome]
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
https://github.com/user-attachments/assets/0a80bef1-8dfa-41db-a41e-8a1432a005b8
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
<!--
Every checklist item must be consciously assessed before marking this PR
as
"Ready for review". A checked box means you deliberately considered that
responsibility, not that you literally performed every action listed.
Unchecked boxes are ambiguous: they are not an implicit "N/A" and they
are not
a silent "skip". See `docs/readme/ready-for-review.md` for the full
checklist
semantics.
-->
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
#### Performance checks (if applicable)
- [x] I've tested on Android
- Ideally on a mid-range device; emulator is acceptable
- [x] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [x] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).
## **Pre-merge reviewer checklist**
<!--
Reviewer checklist items follow the same semantics as the author
checklist: an
unchecked box is ambiguous, a checked box means the reviewer consciously
assessed that responsibility. See `docs/readme/ready-for-review.md`.
-->
- [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]
> **Medium Risk**
> Moderate risk because it refactors slider gesture handling and amount
parsing/formatting, which can affect user-entered values and earnings
calculations across iOS/Android keyboard behavior.
>
> **Overview**
> Improves the mUSD calculator UX by **moving keyboard avoidance into
the tab** via `KeyboardAwareScrollView` and simplifying the view
container (removing the outer `KeyboardAvoidingView` and adjusting
padding).
>
> Refactors `MusdCalculatorTab` to keep **raw numeric input state**, cap
input at `MAX_AMOUNT`, and limit decimals to 2, while switching all USD
display to the shared `formatUsd` helper.
>
> Reworks slider interactions to use **simultaneous tap + pan gestures**
(instead of `Pressable` press handling) to prevent unintended slider
resets, and adds/updates tests to cover keyboard-aware props, input
normalization/capping, and gesture regression cases.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c3d9209. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent ec66ea6 commit 9991a94
4 files changed
Lines changed: 242 additions & 150 deletions
File tree
- app/components/UI/Rewards
- Views
- components/Tabs/MusdCalculatorTab
Lines changed: 0 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 69 | | |
77 | 70 | | |
78 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
22 | | - | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 28 | + | |
37 | 29 | | |
38 | 30 | | |
39 | 31 | | |
| |||
Lines changed: 125 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
19 | 33 | | |
20 | 34 | | |
21 | 35 | | |
| |||
32 | 46 | | |
33 | 47 | | |
34 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
35 | 56 | | |
36 | 57 | | |
37 | 58 | | |
| |||
60 | 81 | | |
61 | 82 | | |
62 | 83 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
69 | 96 | | |
70 | 97 | | |
71 | 98 | | |
| |||
90 | 117 | | |
91 | 118 | | |
92 | 119 | | |
| 120 | + | |
93 | 121 | | |
| 122 | + | |
94 | 123 | | |
95 | 124 | | |
96 | 125 | | |
| |||
114 | 143 | | |
115 | 144 | | |
116 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
117 | 160 | | |
118 | 161 | | |
119 | 162 | | |
| |||
159 | 202 | | |
160 | 203 | | |
161 | 204 | | |
162 | | - | |
163 | | - | |
| 205 | + | |
| 206 | + | |
164 | 207 | | |
165 | 208 | | |
166 | 209 | | |
167 | 210 | | |
168 | 211 | | |
169 | | - | |
| 212 | + | |
170 | 213 | | |
171 | 214 | | |
172 | 215 | | |
| |||
183 | 226 | | |
184 | 227 | | |
185 | 228 | | |
186 | | - | |
187 | 229 | | |
188 | 230 | | |
189 | 231 | | |
190 | 232 | | |
191 | 233 | | |
192 | 234 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | 235 | | |
200 | 236 | | |
201 | | - | |
| 237 | + | |
202 | 238 | | |
203 | 239 | | |
204 | 240 | | |
205 | | - | |
206 | 241 | | |
207 | 242 | | |
208 | 243 | | |
209 | | - | |
210 | | - | |
| 244 | + | |
| 245 | + | |
211 | 246 | | |
212 | 247 | | |
213 | 248 | | |
214 | | - | |
| 249 | + | |
215 | 250 | | |
216 | 251 | | |
217 | 252 | | |
218 | | - | |
219 | 253 | | |
220 | 254 | | |
221 | 255 | | |
222 | | - | |
223 | | - | |
| 256 | + | |
| 257 | + | |
224 | 258 | | |
225 | 259 | | |
226 | 260 | | |
227 | 261 | | |
228 | 262 | | |
229 | 263 | | |
230 | 264 | | |
231 | | - | |
232 | 265 | | |
233 | 266 | | |
234 | 267 | | |
| |||
240 | 273 | | |
241 | 274 | | |
242 | 275 | | |
243 | | - | |
244 | | - | |
| 276 | + | |
| 277 | + | |
245 | 278 | | |
246 | 279 | | |
247 | 280 | | |
248 | 281 | | |
249 | | - | |
| 282 | + | |
250 | 283 | | |
251 | 284 | | |
252 | 285 | | |
| |||
261 | 294 | | |
262 | 295 | | |
263 | 296 | | |
| 297 | + | |
264 | 298 | | |
265 | 299 | | |
266 | 300 | | |
267 | 301 | | |
268 | 302 | | |
269 | 303 | | |
270 | | - | |
| 304 | + | |
271 | 305 | | |
272 | 306 | | |
273 | 307 | | |
274 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
275 | 370 | | |
276 | 371 | | |
277 | 372 | | |
| |||
282 | 377 | | |
283 | 378 | | |
284 | 379 | | |
285 | | - | |
| 380 | + | |
286 | 381 | | |
287 | 382 | | |
288 | 383 | | |
0 commit comments