Commit 5dfa0b8
fix: surface api errors and improve resend UX on OTP screen (MetaMask#26727)
<!--
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**
The OTP screen was showing a generic fallback error regardless of what
the API returned. This PR surfaces the actual Transak error messages to
the user on both OTP submission and resend failures.
The resend button state was also changed: instead of starting in the
"resend" state (waiting for the user to trigger a resend), the screen
now starts directly in cooldown mode because the OTP was already sent
when the user lands on this screen. The cooldown is also bumped from 30s
to 60s to match the actual resend window.
## **Changelog**
CHANGELOG entry: Fixed OTP error messages to show the actual error from
the server instead of a generic fallback.
## **Related issues**
Fixes: TRAM-3291
## **Manual testing steps**
```gherkin
Feature: OTP error display
Scenario: user submits an invalid OTP code
Given the user is on the OTP screen after starting a buy flow
When the user enters a wrong 6-digit code
Then the error message from the server is displayed instead of a generic one
Scenario: user lands on the OTP screen
Given the user navigated to the OTP screen
Then a 60-second cooldown is immediately shown
And the resend button is not visible until the cooldown ends
Scenario: user tries to resend after cooldown
Given the 60-second cooldown has elapsed
When the user taps the resend button
Then a new OTP is sent
And a new 60-second cooldown starts
```
## **Screenshots/Recordings**
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
Surface error without reseting the countdown:
https://github.com/user-attachments/assets/d09b03d5-44f1-4448-8805-e8d7c18f43b1
Countdown starts as soon as user navigates to OTP screen:
https://github.com/user-attachments/assets/56016104-ad20-46d0-b7fb-88e88e066507
## **Pre-merge author checklist**
- [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.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes OTP resend timing/state handling and error surfacing on a
critical ramp authentication step; mistakes could prevent users from
resending or understanding failures.
>
> **Overview**
> **Improves OTP resend UX in the ramp native flow.** The OTP screen now
starts in a *60s cooldown* (was 30s) since an OTP is already sent on
entry, and the initial UI/snapshot reflects the cooldown text instead of
an immediate resend link.
>
> **Resend failures now show user-facing API errors.** `handleResend` no
longer transitions to a `resendError`/"contact support" UI state on API
failure; it sets the screen `error` using `parseUserFacingError` with a
fallback translation key, and tests add coverage for both message and
no-message resend failures.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
a6a1749. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: AxelGes <axelges9@gmail.com>1 parent cb287f7 commit 5dfa0b8
3 files changed
Lines changed: 59 additions & 32 deletions
File tree
- app/components/UI/Ramp/Views/NativeFlow
- __snapshots__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
304 | 310 | | |
305 | 311 | | |
306 | 312 | | |
| |||
315 | 321 | | |
316 | 322 | | |
317 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
318 | 330 | | |
319 | 331 | | |
320 | 332 | | |
| |||
370 | 382 | | |
371 | 383 | | |
372 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
373 | 425 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
| 102 | + | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
| |||
396 | 398 | | |
397 | 399 | | |
398 | 400 | | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | 401 | | |
407 | 402 | | |
408 | 403 | | |
| |||
Lines changed: 1 addition & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | | - | |
| 432 | + | |
433 | 433 | | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | 434 | | |
455 | 435 | | |
456 | 436 | | |
| |||
0 commit comments