Commit 7df31cf
authored
feat: add logout button to BasicInfo error banner for Transak phone already registered error (MetaMask#22183)
## **Description**
This PR adds a logout button to the BasicInfo screen's error banner when
users encounter Transak error code 2020 (phone number already registered
with a different email). This allows users to logout and return to the
email input screen to authenticate with the correct email address.
**What is the reason for the change?**
When users authenticate with the wrong email in the Transak deposit
flow, if they enter a phone number that's already registered to a
different email, they see an error message but have no way to logout and
try again with the correct email. This forces them to restart the entire
app or navigate to settings to logout manually.
**What is the improvement/solution?**
- Added error code 2020 detection from Transak API response structure
- Added localized error message that extracts and displays the
registered email
- Added "Log in with email" button in the error banner that appears only
for error code 2020
- Clicking the button clears authentication and navigates back to email
input screen
- Reuses existing logout functionality and localization strings
- Added comprehensive test coverage
## **Changelog**
CHANGELOG entry: Added logout button to Transak deposit flow when phone
number is already registered
## **Related issues**
Fixes:
[TRAM-2799](https://consensyssoftware.atlassian.net/browse/TRAM-2799)
## **Manual testing steps**
### Option 1: Testing with Real Transak (E2E Validation)
```gherkin
Feature: Logout on Transak phone already registered error
Scenario: user logs out when encountering phone already registered error
Given user has authenticated with email A in Transak deposit flow
And user navigates to BasicInfo screen
And user enters a phone number already registered to email B
When user submits the form
Then error banner displays with message "This phone number is already in use by {masked_email}. Log in using this email to continue."
And "Log in with email" button is visible in the error banner
When user clicks the "Log in with email" button
Then user is logged out from Transak
And user is navigated back to the email input screen
And user can now enter the correct email to authenticate
```
**Note:** Requires two Transak accounts with the same phone number
registered to different emails.
---
### Option 2: Testing with Mock Error (Quick Validation)
**1. Add temporary mock** in `BasicInfo.tsx` around line 212:
```typescript
try {
// TEMPORARY: Simulate Transak error code 2020
const mockError = Object.assign(new Error('API Error'), {
error: {
errorCode: 2020,
message: 'This phone number is already registered. It has been used by an account created with k****@pedalsup.com. Login with this email to continue.',
},
});
throw mockError;
// Comment out original code for testing:
// setLoading(true);
// const { ssn, ...formDataWithoutSsn } = formData;
// await postKycForm({ personalDetails: { ... } });
```
**2. Run on simulator:**
```bash
yarn watch
# Press 'i' for iOS or 'a' for Android
```
**3. Test the flow:**
- Navigate to Deposit → Verify Identity → BasicInfo
- Fill in form with any valid data
- Click "Continue"
- ✅ Verify error banner shows: "This phone number is already in use by
k****@pedalsup.com. Log in using this email to continue."
- ✅ Verify button shows: "Log in with email"
- Click the button
- ✅ Verify navigation back to email input screen
- ✅ Verify no console errors
**4. Clean up:** Remove the mock code before committing
## **Screenshots/Recordings**
### **Before**
Error banner without logout button - user had no way to logout and try
with correct email
<img width="787" height="1704" alt="image"
src="https://github.com/user-attachments/assets/58285702-078c-4c00-99b9-d36300e6649e"
/>
### **After**
**Error Object From Transak**
<img width="2174" height="1330" alt="image"
src="https://github.com/user-attachments/assets/3c175ebd-3df9-4447-8fac-3a3cbcca8e34"
/>
**Error banner with "Log in with email" button as shown in design
mockup**
https://github.com/user-attachments/assets/476ae836-beaf-454b-9806-9350920f3cfb
## **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.
[TRAM-2799]:
https://consensyssoftware.atlassian.net/browse/TRAM-2799?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds detection of Transak error 2020 on BasicInfo, displaying a
localized message with the masked email and a "Log in with email" action
that logs out and navigates to EnterEmail.
>
> - **Deposit › Verify Identity (`BasicInfo.tsx`)**:
> - Detects Transak API `error.errorCode === 2020` (phone already
registered).
> - Extracts masked email from `error.message` and shows localized error
`deposit.basic_info.phone_already_registered`.
> - Displays BannerAlert action button "Log in with email" (`testID:
"basic-info-logout-button"`).
> - On click, calls `logoutFromProvider(false)` and navigates to
`...createEnterEmailNavDetails()`.
> - Resets error/UI flags on retry and field changes; integrates
`logoutFromProvider` from `useDepositSDK`.
> - **Tests (`BasicInfo.test.tsx`)**:
> - Adds cases for: showing logout button on `2020` errors, formatting
message with email, no action for generic errors, successful logout +
navigation, and graceful logout failure logging.
> - **Localization (`locales/languages/en.json`)**:
> - Adds `deposit.basic_info.phone_already_registered` and
`deposit.basic_info.login_with_email`; keeps `unexpected_error`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
6bf8336. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 36df852 commit 7df31cf
3 files changed
Lines changed: 294 additions & 8 deletions
File tree
- app/components/UI/Ramp/Deposit/Views/BasicInfo
- locales/languages
Lines changed: 231 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 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 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
376 | 607 | | |
Lines changed: 60 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
| 77 | + | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| |||
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| 202 | + | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
| |||
227 | 230 | | |
228 | 231 | | |
229 | 232 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
235 | 261 | | |
236 | 262 | | |
237 | 263 | | |
| |||
240 | 266 | | |
241 | 267 | | |
242 | 268 | | |
243 | | - | |
244 | 269 | | |
245 | 270 | | |
246 | 271 | | |
247 | 272 | | |
248 | 273 | | |
249 | 274 | | |
| 275 | + | |
250 | 276 | | |
251 | 277 | | |
252 | 278 | | |
253 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
254 | 295 | | |
255 | 296 | | |
256 | 297 | | |
| |||
262 | 303 | | |
263 | 304 | | |
264 | 305 | | |
| 306 | + | |
265 | 307 | | |
266 | 308 | | |
267 | 309 | | |
| |||
298 | 340 | | |
299 | 341 | | |
300 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
301 | 354 | | |
302 | 355 | | |
303 | 356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
776 | 776 | | |
777 | 777 | | |
778 | 778 | | |
779 | | - | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
780 | 782 | | |
781 | 783 | | |
782 | 784 | | |
| |||
0 commit comments