Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8c88b08
fix: type error
montelaidev May 20, 2024
059fe12
feat: add selectedEvmAccountChange event
montelaidev May 20, 2024
ade1ce8
feat: update getSelectedAccount to have optional chainId parameter
montelaidev May 20, 2024
61068cf
feat: add mocks
montelaidev May 21, 2024
9cfa922
fix: update btc address in test
montelaidev May 21, 2024
4e8f8a2
chore: add keyring-api to assets-controller
montelaidev May 21, 2024
115fadf
fix: update getSelectedAccount tests
montelaidev May 21, 2024
6927777
feat: add optional arg to listAccounts
montelaidev May 21, 2024
6690e98
feat: update AccountTracker to use account id
montelaidev May 21, 2024
9445c20
refactor: update TokenBalanceController to use account id
montelaidev May 21, 2024
32ceafa
refactor: Update TokenDetectionController to use account id
montelaidev May 21, 2024
a11976d
refactor: Update TokenRatesController to use account id
montelaidev May 21, 2024
449bc00
refactor: update TokensController to use account id
montelaidev May 21, 2024
ecae96f
refactor: update TransactionController and IncomingTransactionHelper …
montelaidev May 21, 2024
f541860
refactor: update nft controller to use account id
montelaidev May 21, 2024
98a3348
fix: transaction controller integration test
montelaidev May 21, 2024
fb18486
fix: lint remove duplicate test
montelaidev May 21, 2024
29137ce
fix: tokens controller unused var
montelaidev May 21, 2024
b2ae223
fix: lint in type
montelaidev May 21, 2024
02390cc
Merge remote-tracking branch 'origin/main' into fix/ap381/add-multi-c…
montelaidev May 23, 2024
4f42b74
Merge remote-tracking branch 'origin/main' into fix/ap381/add-multi-c…
montelaidev May 27, 2024
4351ebe
fix: lint
montelaidev May 27, 2024
1f4ca13
Merge remote-tracking branch 'origin/main' into fix/ap381/add-multi-c…
montelaidev May 29, 2024
e01842d
chore: bump keyring-api to 6.3.1
danroc May 31, 2024
98615f1
Merge remote-tracking branch 'origin/main' into fix/ap381/add-multi-c…
montelaidev Jun 3, 2024
8e70896
Merge remote-tracking branch 'origin/main' into fix/ap381/add-multi-c…
montelaidev Jun 3, 2024
4d01011
Merge remote-tracking branch 'origin/feature/balances-controller' int…
montelaidev Jun 3, 2024
b8208ed
fix: mock
montelaidev Jun 3, 2024
05766ed
Merge remote-tracking branch 'origin/main' into fix/ap381/add-multi-c…
montelaidev Jun 4, 2024
782bd36
fix: remove mock export
montelaidev Jun 4, 2024
97a639a
chore: fix yarn lock
montelaidev Jun 4, 2024
b8c3947
Merge remote-tracking branch 'origin/main' into fix/ap381/add-multi-c…
montelaidev Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions packages/accounts-controller/src/AccountsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2023,33 +2023,6 @@ describe('AccountsController', () => {
`Account Id "${accountId}" not found`,
);
});

it('handle the edge case of undefined accountId during onboarding', async () => {
const { accountsController } = setupAccountsController({
initialState: {
internalAccounts: {
accounts: { [mockAccount.id]: mockAccount },
selectedAccount: mockAccount.id,
},
},
});

// @ts-expect-error forcing undefined accountId
expect(accountsController.getAccountExpect(undefined)).toStrictEqual({
id: '',
address: '',
options: {},
methods: [],
type: EthAccountType.Eoa,
metadata: {
name: '',
keyring: {
type: '',
},
importTime: 0,
},
});
});
});

describe('setSelectedAccount', () => {
Expand Down Expand Up @@ -2113,6 +2086,32 @@ describe('AccountsController', () => {
mockNonEvmAccount,
);
});

it('handle the edge case of undefined accountId during onboarding', async () => {
const { accountsController } = setupAccountsController({
initialState: {
internalAccounts: {
accounts: {},
selectedAccount: '',
},
},
});

expect(accountsController.getSelectedAccount()).toStrictEqual({
id: '',
address: '',
options: {},
methods: [],
type: EthAccountType.Eoa,
metadata: {
name: '',
keyring: {
type: '',
},
importTime: 0,
},
});
});
});

describe('setAccountName', () => {
Expand Down
28 changes: 14 additions & 14 deletions packages/accounts-controller/src/AccountsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,22 @@ export class AccountsController extends BaseController<
* @throws An error if the account ID is not found.
*/
getAccountExpect(accountId: string): InternalAccount {
const account = this.getAccount(accountId);
if (account === undefined) {
throw new Error(`Account Id "${accountId}" not found`);
}
return account;
}

/**
* Returns the last selected evm account.
*
* @returns The selected internal account.
*/
getSelectedAccount(): InternalAccount {
// Edge case where the extension is setup but the srp is not yet created
// certain ui elements will query the selected address before any accounts are created.
if (!accountId) {
if (this.state.internalAccounts.selectedAccount === '') {
return {
id: '',
address: '',
Expand All @@ -284,19 +297,6 @@ export class AccountsController extends BaseController<
};
}

const account = this.getAccount(accountId);
if (account === undefined) {
throw new Error(`Account Id "${accountId}" not found`);
}
return account;
}

/**
* Returns the last selected evm account.
*
* @returns The selected internal account.
*/
getSelectedAccount(): InternalAccount {
const selectedAccount = this.getAccountExpect(
this.state.internalAccounts.selectedAccount,
);
Expand Down
8 changes: 6 additions & 2 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@
"@metamask/contract-metadata": "^2.4.0",
"@metamask/controller-utils": "^11.0.0",
"@metamask/eth-query": "^4.0.0",
"@metamask/keyring-api": "^6.4.0",
"@metamask/keyring-controller": "^17.0.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/network-controller": "^19.0.0",
"@metamask/polling-controller": "^8.0.0",
"@metamask/preferences-controller": "^13.0.0",
"@metamask/rpc-errors": "^6.2.1",
"@metamask/snaps-sdk": "^4.2.0",
"@metamask/snaps-utils": "^7.4.0",
"@metamask/utils": "^8.3.0",
"@types/bn.js": "^5.1.5",
"@types/uuid": "^8.3.0",
Expand All @@ -73,11 +76,11 @@
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/ethjs-provider-http": "^0.3.0",
"@metamask/keyring-api": "^6.4.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
"@types/node": "^16.18.54",
"deepmerge": "^4.2.2",
"immer": "^9.0.6",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"nock": "^13.3.1",
Expand All @@ -92,7 +95,8 @@
"@metamask/approval-controller": "^7.0.0",
"@metamask/keyring-controller": "^17.0.0",
"@metamask/network-controller": "^19.0.0",
"@metamask/preferences-controller": "^13.0.0"
"@metamask/preferences-controller": "^13.0.0",
"@metamask/snaps-controllers": "^8.1.1"
},
"engines": {
"node": "^18.18 || >=20"
Expand Down
Loading