From a08f3939ec7e53f4320312f558723a7d4576d7ed Mon Sep 17 00:00:00 2001 From: George Weiler Date: Fri, 24 Oct 2025 20:38:45 +0000 Subject: [PATCH] chore(runway): cherry-pick fix(ramps): cp-7.58.0 do not throw when user details fetch is 401 (#21633) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR fixes a bug where an error would display for users who's token has expired. Now they are silently logged out instead of throwing an error that is displayed to the user. ## **Changelog** CHANGELOG entry: fixed bug where an error message was incorrectly displayed to the user on the deposit page ## **Related issues** Fixes: https://github.com/MetaMask/metamask-mobile/issues/21642 ## **Manual testing steps** ```gherkin Feature: User Error Fix Scenario: logged-out user should not see error message Given user token has expired When user visits the deposit page Then user should not see an error ``` ## **Screenshots/Recordings** ### **Before** Screenshot 2025-10-24 at 11 58 22 AM ### **After** ## **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. --- > [!NOTE] > `useDepositUser` now logs out without throwing on 401 while still throwing for non-401 errors; tests updated to reflect new behavior. > > - **Hooks**: > - `useDepositUser`: On `401`, log and call `logoutFromProvider(false)` without rethrowing; other errors continue to throw. > - **Tests**: > - Update 401 test to expect no throw and verify logout call; minor setup adjustments to align with new behavior. > > Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 54d5e236df6f0ed155492275e884a015310c4a41. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot). Co-authored-by: Pedro Pablo Aste Kompen --- .../UI/Ramp/Deposit/hooks/useDepositUser.test.ts | 8 +++----- app/components/UI/Ramp/Deposit/hooks/useDepositUser.ts | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/components/UI/Ramp/Deposit/hooks/useDepositUser.test.ts b/app/components/UI/Ramp/Deposit/hooks/useDepositUser.test.ts index 442048e192e8..98cbb3d7cfb2 100644 --- a/app/components/UI/Ramp/Deposit/hooks/useDepositUser.test.ts +++ b/app/components/UI/Ramp/Deposit/hooks/useDepositUser.test.ts @@ -271,7 +271,7 @@ describe('useDepositUser', () => { expect(mockFetchUserDetails).toHaveBeenCalled(); }); - it('logs out and throws on 401 error', async () => { + it('logs out but does not throw on 401 error', async () => { const error401 = Object.assign(new Error('Unauthorized'), { status: 401, }) as AxiosError; @@ -284,13 +284,11 @@ describe('useDepositUser', () => { ); mockFetchUserDetails.mockRejectedValue(error401); - setupMockSdkMethod({ data: mockUserDetails }); + setupMockSdkMethod(); const { result } = renderHook(() => useDepositUser()); - await expect(result.current.fetchUserDetails()).rejects.toThrow( - 'Unauthorized', - ); + await result.current.fetchUserDetails(); expect(mockLogoutFromProvider).toHaveBeenCalledWith(false); }); diff --git a/app/components/UI/Ramp/Deposit/hooks/useDepositUser.ts b/app/components/UI/Ramp/Deposit/hooks/useDepositUser.ts index 77a5e794f8e9..82f05fcf1c5c 100644 --- a/app/components/UI/Ramp/Deposit/hooks/useDepositUser.ts +++ b/app/components/UI/Ramp/Deposit/hooks/useDepositUser.ts @@ -22,8 +22,9 @@ export function useDepositUser() { if ((error as AxiosError).status === 401) { Logger.log('useDepositUser: 401 error, clearing authentication'); await logoutFromProvider(false); + } else { + throw error; } - throw error; } }, [fetchUserDetails, logoutFromProvider]);