-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: name being out of sync in account list (#26542)
## **Description** This PR fixes the issue where the account name being created in the connect account flow is out of sync. <!-- 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? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26542?quickstart=1) ## **Related issues** Fixes: [25846](#25846) ## **Manual testing steps** 1. Create a snap/hw account 2. Go to test dapp 3. Click connect 4. Click on create new account 5. See that the suggested name is Account 3 6. Create the new account 7. See in the list that there is `Account 3` in the list ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** https://github.com/user-attachments/assets/9c0d511a-a84a-4da8-80e5-4dbadbb7cee6 <!-- [screenshots/recordings] --> ### **After** https://github.com/user-attachments/assets/daf22aed-593f-4e81-8535-11a26cd5e4fc <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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-extension/blob/develop/.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.
- Loading branch information
1 parent
084768a
commit 6ed72f0
Showing
4 changed files
with
143 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
ui/components/app/modals/new-account-modal/new-account-modal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import thunk from 'redux-thunk'; | ||
import { waitFor, fireEvent } from '@testing-library/react'; | ||
import configureStore from 'redux-mock-store'; | ||
import { renderWithProvider } from '../../../../../test/jest'; | ||
import mockState from '../../../../../test/data/mock-state.json'; | ||
import messages from '../../../../../app/_locales/en/messages.json'; | ||
import NewAccountModal from './new-account-modal.container'; | ||
|
||
const mockOnCreateNewAccount = jest.fn(); | ||
const mockNewAccountNumber = 2; | ||
const mockNewMetamaskState = { | ||
...mockState.metamask, | ||
currentLocale: 'en', | ||
}; | ||
const mockAddress = '0x1234567890'; | ||
|
||
const mockSubmitRequestToBackground = jest.fn().mockImplementation((method) => { | ||
switch (method) { | ||
case 'addNewAccount': | ||
return mockAddress; | ||
case 'setAccountLabel': | ||
return {}; | ||
case 'getState': | ||
return mockNewMetamaskState; | ||
default: | ||
return {}; | ||
} | ||
}); | ||
|
||
jest.mock('../../../../store/background-connection', () => ({ | ||
...jest.requireActual('../../../../store/background-connection'), | ||
submitRequestToBackground: (method: string, args: unknown) => | ||
mockSubmitRequestToBackground(method, args), | ||
})); | ||
|
||
const renderModal = ( | ||
props = { | ||
onCreateNewAccount: mockOnCreateNewAccount, | ||
newAccountNumber: mockNewAccountNumber, | ||
}, | ||
) => { | ||
const state = { | ||
...mockState, | ||
metamask: { | ||
...mockState.metamask, | ||
currentLocale: 'en', | ||
}, | ||
appState: { | ||
...mockState.appState, | ||
modal: { | ||
...mockState.appState.modal, | ||
modalState: { | ||
name: 'NEW_ACCOUNT', | ||
props, | ||
}, | ||
}, | ||
}, | ||
}; | ||
const middlewares = [thunk]; | ||
const mockStore = configureStore(middlewares); | ||
const store = mockStore(state); | ||
|
||
return { | ||
render: renderWithProvider(<NewAccountModal />, store), | ||
store, | ||
}; | ||
}; | ||
|
||
describe('NewAccountModal', () => { | ||
it('calls forceUpdateMetamaskState after adding account', async () => { | ||
const { render } = renderModal(); | ||
const { getByText } = render; | ||
const addAccountButton = getByText(messages.save.message); | ||
expect(addAccountButton).toBeInTheDocument(); | ||
|
||
fireEvent.click(addAccountButton); | ||
|
||
await waitFor(() => { | ||
expect(mockSubmitRequestToBackground).toHaveBeenNthCalledWith( | ||
2, | ||
'getState', | ||
undefined, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters