Skip to content

Commit 79a10c6

Browse files
authored
perf: accounts improvements (#15194)
## **Description** > [!CAUTION] > Requires this PR to be merged first: > - [x] #14913 Upgrade controllers to use the new accounts perf improvements, notably: - MetaMask/core#5735 - MetaMask/core#5732 - MetaMask/core#5714 ## **Related issues** N/A ## **Manual testing steps** 1. Create a Solana account 2. It should run faster ## **Screenshots/Recordings** ### **Before** ### **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.
1 parent 0662d38 commit 79a10c6

File tree

6 files changed

+118
-139
lines changed

6 files changed

+118
-139
lines changed

app/core/Engine/Engine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ export class Engine {
441441
'AccountsController:setSelectedAccount',
442442
'AccountsController:getAccountByAddress',
443443
'AccountsController:setAccountName',
444+
'AccountsController:setAccountNameAndSelectAccount',
444445
'AccountsController:listMultichainAccounts',
445446
'SnapController:handleRequest',
446447
SnapControllerGetSnapAction,

app/core/SnapKeyring/SnapKeyring.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const mockSetSelectedAccount = jest.fn();
2929
const mockRemoveAccountHelper = jest.fn();
3030
const mockGetAccountByAddress = jest.fn();
3131
const mockSetAccountName = jest.fn();
32+
const mockSetAccountNameAndSelectAccount = jest.fn();
3233
const mockSnapControllerHandleRequest = jest.fn();
3334
const mockListMultichainAccounts = jest.fn();
3435

@@ -84,6 +85,7 @@ const createControllerMessenger = ({
8485
'AccountsController:getAccountByAddress',
8586
'AccountsController:listMultichainAccounts',
8687
'AccountsController:setAccountName',
88+
'AccountsController:setAccountNameAndSelectAccount',
8789
],
8890
allowedEvents: [],
8991
});
@@ -108,6 +110,8 @@ const createControllerMessenger = ({
108110
return mockSetSelectedAccount(params);
109111
case 'AccountsController:setAccountName':
110112
return mockSetAccountName.mockReturnValue(null)(params);
113+
case 'AccountsController:setAccountNameAndSelectAccount':
114+
return mockSetAccountNameAndSelectAccount.mockReturnValue(null)(params);
111115
case 'AccountsController:listMultichainAccounts':
112116
return mockListMultichainAccounts.mockReturnValue([])();
113117
case 'SnapController:handleRequest':
@@ -217,7 +221,7 @@ describe('Snap Keyring Methods', () => {
217221
]);
218222
expect(mockPersisKeyringHelper).toHaveBeenCalledTimes(1);
219223
expect(mockGetAccounts).toHaveBeenCalledTimes(1);
220-
expect(mockSetAccountName).not.toHaveBeenCalled();
224+
expect(mockSetAccountNameAndSelectAccount).not.toHaveBeenCalled();
221225
expect(mockEndFlow).toHaveBeenCalledWith([{ id: mockFlowId }]);
222226

223227
// Wait for any pending promises (including the account finalization which tracks the event)
@@ -256,8 +260,8 @@ describe('Snap Keyring Methods', () => {
256260
true,
257261
]);
258262
expect(mockGetAccounts).toHaveBeenCalledTimes(1);
259-
expect(mockSetAccountName).toHaveBeenCalledTimes(1);
260-
expect(mockSetAccountName).toHaveBeenCalledWith([
263+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledTimes(1);
264+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledWith([
261265
mockAccount.id,
262266
mockNameSuggestion,
263267
]);
@@ -398,8 +402,8 @@ describe('Snap Keyring Methods', () => {
398402

399403
// Verify that the account was created and named
400404
expect(mockPersisKeyringHelper).toHaveBeenCalledTimes(1);
401-
expect(mockSetAccountName).toHaveBeenCalledTimes(1);
402-
expect(mockSetAccountName).toHaveBeenCalledWith([
405+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledTimes(1);
406+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledWith([
403407
mockAccount.id,
404408
mockNameSuggestion,
405409
]);
@@ -433,8 +437,8 @@ describe('Snap Keyring Methods', () => {
433437

434438
// Verify that the account was created and named
435439
expect(mockPersisKeyringHelper).toHaveBeenCalledTimes(1);
436-
expect(mockSetAccountName).toHaveBeenCalledTimes(1);
437-
expect(mockSetAccountName).toHaveBeenCalledWith([
440+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledTimes(1);
441+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledWith([
438442
mockAccount.id,
439443
mockNameSuggestion,
440444
]);
@@ -480,8 +484,8 @@ describe('Snap Keyring Methods', () => {
480484

481485
// Verify that the account was created and named
482486
expect(mockPersisKeyringHelper).toHaveBeenCalledTimes(1);
483-
expect(mockSetAccountName).toHaveBeenCalledTimes(1);
484-
expect(mockSetAccountName).toHaveBeenCalledWith([
487+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledTimes(1);
488+
expect(mockSetAccountNameAndSelectAccount).toHaveBeenCalledWith([
485489
mockAccount.id,
486490
mockNameSuggestion,
487491
]);

app/core/SnapKeyring/SnapKeyring.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ class SnapKeyringImpl implements SnapKeyringCallbacks {
173173
// (e.g. renaming the account, select the account, etc...)
174174

175175
// Set the selected account to the new account
176-
this.#messenger.call(
177-
'AccountsController:setSelectedAccount',
178-
accountId,
179-
);
180-
181176
if (accountName) {
182177
this.#messenger.call(
183-
'AccountsController:setAccountName',
178+
'AccountsController:setAccountNameAndSelectAccount',
184179
accountId,
185180
accountName,
186181
);
182+
} else {
183+
this.#messenger.call(
184+
'AccountsController:setSelectedAccount',
185+
accountId,
186+
);
187187
}
188188

189189
// Track successful account addition

app/core/SnapKeyring/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GetSubjectMetadata } from '@metamask/permission-controller';
55
import {
66
AccountsControllerGetAccountByAddressAction,
77
AccountsControllerSetAccountNameAction,
8+
AccountsControllerSetAccountNameAndSelectAccountAction,
89
AccountsControllerSetSelectedAccountAction,
910
AccountsControllerListMultichainAccountsAction,
1011
} from '@metamask/accounts-controller';
@@ -38,6 +39,7 @@ export type SnapKeyringBuilderAllowActions =
3839
| AccountsControllerGetAccountByAddressAction
3940
| AccountsControllerListMultichainAccountsAction
4041
| AccountsControllerSetAccountNameAction
42+
| AccountsControllerSetAccountNameAndSelectAccountAction
4143
| SnapControllerHandleRequestActionType
4244
| SnapControllerGetSnapActionType;
4345

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,20 @@
158158
"@keystonehq/metamask-airgapped-keyring": "^0.15.2",
159159
"@keystonehq/ur-decoder": "^0.12.2",
160160
"@ledgerhq/react-native-hw-transport-ble": "^6.33.2",
161-
"@metamask/accounts-controller": "^27.0.0",
161+
"@metamask/accounts-controller": "^28.0.0",
162162
"@metamask/address-book-controller": "^6.0.3",
163163
"@metamask/app-metadata-controller": "^1.0.0",
164164
"@metamask/approval-controller": "^7.1.3",
165-
"@metamask/assets-controllers": "^60.0.0",
165+
"@metamask/assets-controllers": "^61.0.0",
166166
"@metamask/base-controller": "^8.0.0",
167167
"@metamask/bitcoin-wallet-snap": "^0.9.0",
168-
"@metamask/bridge-controller": "^20.0.0",
169-
"@metamask/bridge-status-controller": "^16.0.0",
168+
"@metamask/bridge-controller": "^21.0.0",
169+
"@metamask/bridge-status-controller": "^18.0.0",
170170
"@metamask/chain-agnostic-permission": "^0.3.0",
171171
"@metamask/composable-controller": "^11.0.0",
172172
"@metamask/controller-utils": "^11.7.0",
173173
"@metamask/design-tokens": "^7.0.0",
174-
"@metamask/earn-controller": "^0.12.0",
174+
"@metamask/earn-controller": "^0.13.0",
175175
"@metamask/eip1193-permission-middleware": "^0.1.0",
176176
"@metamask/eth-hd-keyring": "^12.1.0",
177177
"@metamask/eth-json-rpc-filters": "^9.0.0",
@@ -189,22 +189,22 @@
189189
"@metamask/json-rpc-middleware-stream": "^8.0.7",
190190
"@metamask/key-tree": "^10.1.1",
191191
"@metamask/keyring-api": "^17.4.0",
192-
"@metamask/keyring-controller": "^21.0.4",
192+
"@metamask/keyring-controller": "^21.0.6",
193193
"@metamask/keyring-internal-api": "^4.0.3",
194194
"@metamask/keyring-snap-client": "^4.0.1",
195195
"@metamask/logging-controller": "^6.0.4",
196196
"@metamask/message-signing-snap": "^1.1.1",
197197
"@metamask/metamask-eth-abis": "3.1.1",
198198
"@metamask/multichain-network-controller": "^0.4.0",
199-
"@metamask/multichain-transactions-controller": "^0.8.0",
199+
"@metamask/multichain-transactions-controller": "^0.10.0",
200200
"@metamask/network-controller": "^23.2.0",
201-
"@metamask/notification-services-controller": "^6.0.0",
201+
"@metamask/notification-services-controller": "^7.0.0",
202202
"@metamask/permission-controller": "^11.0.6",
203203
"@metamask/phishing-controller": "^12.4.1",
204204
"@metamask/post-message-stream": "^9.0.0",
205205
"@metamask/ppom-validator": "0.36.0",
206206
"@metamask/preferences-controller": "^17.0.0",
207-
"@metamask/profile-sync-controller": "^12.0.0",
207+
"@metamask/profile-sync-controller": "^13.0.0",
208208
"@metamask/react-native-actionsheet": "2.4.2",
209209
"@metamask/react-native-button": "^3.0.0",
210210
"@metamask/react-native-payments": "^2.0.0",
@@ -215,7 +215,7 @@
215215
"@metamask/scure-bip39": "^2.1.0",
216216
"@metamask/sdk-communication-layer": "0.29.0-wallet",
217217
"@metamask/selected-network-controller": "^22.0.0",
218-
"@metamask/signature-controller": "^27.1.0",
218+
"@metamask/signature-controller": "^28.0.0",
219219
"@metamask/slip44": "^4.1.0",
220220
"@metamask/smart-transactions-controller": "^16.3.1",
221221
"@metamask/snaps-controllers": "^11.2.3",
@@ -228,7 +228,7 @@
228228
"@metamask/swappable-obj-proxy": "^2.1.0",
229229
"@metamask/swaps-controller": "^13.1.0",
230230
"@metamask/token-search-discovery-controller": "^3.1.0",
231-
"@metamask/transaction-controller": "54.0.0",
231+
"@metamask/transaction-controller": "55.0.0",
232232
"@metamask/utils": "^11.2.0",
233233
"@ngraveio/bc-ur": "^1.1.6",
234234
"@noble/hashes": "^1.7.1",

0 commit comments

Comments
 (0)