Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
3 changes: 2 additions & 1 deletion packages/account-tree-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `AccountTreeGroup.{get,select}` selectors ([#6248](https://github.com/MetaMask/core/pull/6248))
- Add persistence support for user customizations ([#6221](https://github.com/MetaMask/core/pull/6221))
- New `accountGroupsMetadata` (of new type `AccountTreeGroupPersistedMetadata`) and `accountWalletsMetadata` (of new type `AccountTreeWalletPersistedMetadata`) state properties to persist custom names, pinning, and hiding states.
- Custom names and metadata survive controller initialization and tree rebuilds.
Expand All @@ -23,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **BREAKING:** Bump peer dependency `@metamask/account-api` from `^0.3.0` to `^0.7.0` ([#6214](https://github.com/MetaMask/core/pull/6214)), ([#6216](https://github.com/MetaMask/core/pull/6216)), ([#6222](https://github.com/MetaMask/core/pull/6222))
- **BREAKING:** Bump peer dependency `@metamask/account-api` from `^0.3.0` to `^0.9.0` ([#6214](https://github.com/MetaMask/core/pull/6214)), ([#6216](https://github.com/MetaMask/core/pull/6216)), ([#6222](https://github.com/MetaMask/core/pull/6222)), ([#6248](https://github.com/MetaMask/core/pull/6248))
- **BREAKING:** Move `wallet.metadata.type` tag to `wallet` node ([#6214](https://github.com/MetaMask/core/pull/6214))
- This `type` can be used as a tag to strongly-type (tagged-union) the `AccountWalletObject`.
- Defaults to the EVM account from a group when using `setSelectedAccountGroup` ([#6208](https://github.com/MetaMask/core/pull/6208))
Expand Down
6 changes: 3 additions & 3 deletions packages/account-tree-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"@metamask/account-api": "^0.7.0",
"@metamask/account-api": "^0.9.0",
"@metamask/accounts-controller": "^32.0.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-api": "^19.0.0",
"@metamask/keyring-api": "^20.0.0",
"@metamask/keyring-controller": "^22.1.0",
"@metamask/providers": "^22.1.0",
"@metamask/snaps-controllers": "^14.0.1",
Expand All @@ -70,7 +70,7 @@
"webextension-polyfill": "^0.12.0"
},
"peerDependencies": {
"@metamask/account-api": "^0.7.0",
"@metamask/account-api": "^0.9.0",
"@metamask/accounts-controller": "^32.0.0",
"@metamask/keyring-controller": "^22.0.0",
"@metamask/providers": "^22.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,11 @@ describe('AccountTreeController', () => {
});

describe('AccountTreeGroup', () => {
it('gets accounts from an account group', () => {
const { controller } = setup({
accounts: [MOCK_HD_ACCOUNT_1],
const setupGroup = ({
accounts = [MOCK_HD_ACCOUNT_1],
}: { accounts?: InternalAccount[] } = {}) => {
const { controller, mocks } = setup({
accounts,
keyrings: [MOCK_HD_KEYRING_1],
});
controller.init();
Expand All @@ -1143,6 +1145,13 @@ describe('AccountTreeController', () => {
expect(groups).toHaveLength(1);

const group = groups[0];

return { group, controller, mocks };
};

it('gets accounts from an account group', () => {
const { group } = setupGroup();

expect(group.id).toBeDefined();
expect(group.wallet).toBeDefined();
expect(group.name).toBeDefined();
Expand All @@ -1155,16 +1164,7 @@ describe('AccountTreeController', () => {
});

it('throws if an account cannot be resolved', () => {
const { controller, mocks } = setup({
accounts: [MOCK_HD_ACCOUNT_1],
keyrings: [MOCK_HD_KEYRING_1],
});
controller.init();

const wallets = controller.getAccountWallets();
const wallet = wallets[0];
const groups = wallet.getAccountGroups();
const group = groups[0];
const { group, mocks } = setupGroup();

const accountIds = group.getAccountIds();
expect(accountIds).toHaveLength(1);
Expand All @@ -1175,45 +1175,46 @@ describe('AccountTreeController', () => {
);
});

it('gets the only account from a group', () => {
const rootMessenger = getRootMessenger();
const messenger = getAccountTreeControllerMessenger(rootMessenger);
it('gets one account using a selector', () => {
const { group } = setupGroup();

const account = MOCK_HD_ACCOUNT_1;
const wallet = new AccountTreeWallet({
messenger,
wallet: {
id: toAccountWalletId(AccountWalletType.Keyring, KeyringTypes.simple),
type: AccountWalletType.Keyring,
groups: {},
metadata: {
name: '',
keyring: {
type: KeyringTypes.simple,
},
},
},
});
const group = new AccountTreeGroup({
messenger,
wallet,
group: {
id: toAccountGroupId(wallet.id, 'bad'),
type: AccountGroupType.SingleAccount,
accounts: [account.id],
metadata: {
name: '',
pinned: false,
hidden: false,
},
},
expect(group.get({ scopes: [EthScope.Mainnet] })).toBe(MOCK_HD_ACCOUNT_1);
});

it('gets no account if selector did not match', () => {
const { group } = setupGroup();

expect(group.get({ scopes: [SolScope.Mainnet] })).toBeUndefined();
});

it('throws if too many accounts are matching selector', () => {
const { group } = setupGroup({
accounts: [MOCK_HD_ACCOUNT_2, MOCK_HD_ACCOUNT_2],
});

rootMessenger.registerActionHandler(
'AccountsController:getAccount',
() => account,
expect(() => group.get({ scopes: [EthScope.Mainnet] })).toThrow(
'Too many account candidates, expected 1, got: 2',
);
expect(group.getOnlyAccount()).toBe(account);
});

it('selects accounts using a selector', () => {
const { group } = setupGroup();

expect(group.select({ scopes: [EthScope.Mainnet] })).toStrictEqual([
MOCK_HD_ACCOUNT_1,
]);
});

it('selects no account if selector did not match', () => {
const { group } = setupGroup();

expect(group.select({ scopes: [SolScope.Mainnet] })).toStrictEqual([]);
});

it('gets the only account from a group', () => {
const { group } = setupGroup({ accounts: [MOCK_HARDWARE_ACCOUNT_1] });

expect(group.getOnlyAccount()).toBe(MOCK_HARDWARE_ACCOUNT_1);
});

it('throws if the group has more than 1 account when calling getOnlyAccount', () => {
Expand Down
20 changes: 17 additions & 3 deletions packages/account-tree-controller/src/group.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import {
select,
selectOne,
type AccountGroupType,
type MultichainAccountGroupId,
} from '@metamask/account-api';
import type {
AccountGroupType,
MultichainAccountGroupId,
AccountGroup,
AccountGroupId,
AccountSelector,
} from '@metamask/account-api';
import type { AccountGroup, AccountGroupId } from '@metamask/account-api';
import type { AccountId } from '@metamask/accounts-controller';
import type { InternalAccount } from '@metamask/keyring-internal-api';

Expand Down Expand Up @@ -161,4 +167,12 @@ export class AccountTreeGroup implements AccountGroup<InternalAccount> {
// A group always have at least one account.
return this.#getAccount(accountIds[0]);
}

get(selector: AccountSelector<InternalAccount>): InternalAccount | undefined {
return selectOne(this.getAccounts(), selector);
}

select(selector: AccountSelector<InternalAccount>): InternalAccount[] {
return select(this.getAccounts(), selector);
}
}
6 changes: 6 additions & 0 deletions packages/accounts-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/keyring-api` from `^19.0.0` to `^20.0.0` ([#6248](https://github.com/MetaMask/core/pull/6248))
- Bump `@metamask/keyring-internal-api` from `^7.0.0` to `^8.0.0` ([#6248](https://github.com/MetaMask/core/pull/6248))
- Bump `@metamask/eth-snap-keyring` from `^14.0.0` to `^16.0.0` ([#6248](https://github.com/MetaMask/core/pull/6248))

### Fixed

- Stop updating `selectedAccount` unnecesarily ([#6218](https://github.com/MetaMask/core/pull/6218))
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
"dependencies": {
"@ethereumjs/util": "^9.1.0",
"@metamask/base-controller": "^8.0.1",
"@metamask/eth-snap-keyring": "^14.0.0",
"@metamask/keyring-api": "^19.0.0",
"@metamask/keyring-internal-api": "^7.0.0",
"@metamask/eth-snap-keyring": "^16.0.0",
"@metamask/keyring-api": "^20.0.0",
"@metamask/keyring-internal-api": "^8.0.0",
"@metamask/keyring-utils": "^3.1.0",
"@metamask/snaps-sdk": "^9.0.0",
"@metamask/snaps-utils": "^11.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/keyring-api` from `^19.0.0` to `^20.0.0` ([#6248](https://github.com/MetaMask/core/pull/6248))

### Fixed

- Use a narrow selector when listening to `CurrencyRateController:stateChange` ([#6217](https://github.com/MetaMask/core/pull/6217))
Expand Down
6 changes: 3 additions & 3 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@metamask/contract-metadata": "^2.4.0",
"@metamask/controller-utils": "^11.11.0",
"@metamask/eth-query": "^4.0.0",
"@metamask/keyring-api": "^19.0.0",
"@metamask/keyring-api": "^20.0.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/polling-controller": "^14.0.0",
"@metamask/rpc-errors": "^7.0.2",
Expand All @@ -83,8 +83,8 @@
"@metamask/auto-changelog": "^3.4.4",
"@metamask/ethjs-provider-http": "^0.3.0",
"@metamask/keyring-controller": "^22.1.0",
"@metamask/keyring-internal-api": "^7.0.0",
"@metamask/keyring-snap-client": "^6.0.0",
"@metamask/keyring-internal-api": "^8.0.0",
"@metamask/keyring-snap-client": "^7.0.0",
"@metamask/network-controller": "^24.0.1",
"@metamask/permission-controller": "^11.0.6",
"@metamask/phishing-controller": "^13.1.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/keyring-api` from `^19.0.0` to `^20.0.0` ([#6248](https://github.com/MetaMask/core/pull/6248))

## [37.1.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@metamask/base-controller": "^8.0.1",
"@metamask/controller-utils": "^11.11.0",
"@metamask/gas-fee-controller": "^24.0.0",
"@metamask/keyring-api": "^19.0.0",
"@metamask/keyring-api": "^20.0.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/multichain-network-controller": "^0.11.0",
"@metamask/polling-controller": "^14.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/bridge-status-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/keyring-api` from `^19.0.0` to `^20.0.0` ([#6248](https://github.com/MetaMask/core/pull/6248))

### Fixed

- Make sure to pass the `requireApproval` for ERC20 approvals ([#6204](https://github.com/MetaMask/core/pull/6204))
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-status-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@metamask/base-controller": "^8.0.1",
"@metamask/controller-utils": "^11.11.0",
"@metamask/keyring-api": "^19.0.0",
"@metamask/keyring-api": "^20.0.0",
"@metamask/polling-controller": "^14.0.0",
"@metamask/superstruct": "^3.1.0",
"@metamask/utils": "^11.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-agnostic-permission/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-internal-api": "^7.0.0",
"@metamask/keyring-internal-api": "^8.0.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Bump `@metamask/keyring-api` from `^18.0.0` to `^19.0.0` ([#6146](https://github.com/MetaMask/core/pull/6146))
- Bump `@metamask/keyring-internal-api` from `^6.2.0` to `^7.0.0` ([#6146](https://github.com/MetaMask/core/pull/6146))
- Bump `@metamask/keyring-api` from `^18.0.0` to `^20.0.0` ([#6146](https://github.com/MetaMask/core/pull/6146)), ([#6248](https://github.com/MetaMask/core/pull/6248))
- Bump `@metamask/keyring-internal-api` from `^6.2.0` to `^8.0.0` ([#6146](https://github.com/MetaMask/core/pull/6146)), ([#6248](https://github.com/MetaMask/core/pull/6248))
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [22.1.0]
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"@metamask/eth-hd-keyring": "^12.0.0",
"@metamask/eth-sig-util": "^8.2.0",
"@metamask/eth-simple-keyring": "^10.0.0",
"@metamask/keyring-api": "^19.0.0",
"@metamask/keyring-internal-api": "^7.0.0",
"@metamask/keyring-api": "^20.0.0",
"@metamask/keyring-internal-api": "^8.0.0",
"@metamask/utils": "^11.4.2",
"async-mutex": "^0.5.0",
"ethereumjs-wallet": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/multichain-account-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- **BREAKING:** Use `KeyringAccount` instead of `InternalAccount` ([#6227](https://github.com/MetaMask/core/pull/6227))
- **BREAKING:** Bump peer dependency `@metamask/account-api` from `^0.3.0` to `^0.7.0` ([#6214](https://github.com/MetaMask/core/pull/6214)), ([#6216](https://github.com/MetaMask/core/pull/6216)), ([#6222](https://github.com/MetaMask/core/pull/6222))
- **BREAKING:** Bump peer dependency `@metamask/account-api` from `^0.3.0` to `^0.9.0` ([#6214](https://github.com/MetaMask/core/pull/6214)), ([#6216](https://github.com/MetaMask/core/pull/6216)), ([#6222](https://github.com/MetaMask/core/pull/6222)), ([#6248](https://github.com/MetaMask/core/pull/6248))
- **BREAKING:** Rename `MultichainAccount` to `MultichainAccountGroup` ([#6216](https://github.com/MetaMask/core/pull/6216)), ([#6219](https://github.com/MetaMask/core/pull/6219))
- The naming was confusing and since a `MultichainAccount` is also an `AccountGroup` it makes sense to have the suffix there too.
- **BREAKING:** Rename `getMultichainAccount*` to `getMultichainAccountGroup*` ([#6216](https://github.com/MetaMask/core/pull/6216)), ([#6219](https://github.com/MetaMask/core/pull/6219))
Expand Down
12 changes: 6 additions & 6 deletions packages/multichain-account-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
},
"dependencies": {
"@metamask/base-controller": "^8.0.1",
"@metamask/eth-snap-keyring": "^14.0.0",
"@metamask/keyring-api": "^19.0.0",
"@metamask/keyring-internal-api": "^7.0.0",
"@metamask/keyring-snap-client": "^6.0.0",
"@metamask/eth-snap-keyring": "^16.0.0",
"@metamask/keyring-api": "^20.0.0",
"@metamask/keyring-internal-api": "^8.0.0",
"@metamask/keyring-snap-client": "^7.0.0",
"@metamask/keyring-utils": "^3.1.0",
"@metamask/snaps-sdk": "^9.0.0",
"@metamask/snaps-utils": "^11.0.0",
"@metamask/superstruct": "^3.1.0"
},
"devDependencies": {
"@metamask/account-api": "^0.7.0",
"@metamask/account-api": "^0.9.0",
"@metamask/accounts-controller": "^32.0.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-controller": "^22.1.0",
Expand All @@ -76,7 +76,7 @@
"webextension-polyfill": "^0.12.0"
},
"peerDependencies": {
"@metamask/account-api": "^0.7.0",
"@metamask/account-api": "^0.9.0",
"@metamask/accounts-controller": "^32.0.0",
"@metamask/keyring-controller": "^22.0.0",
"@metamask/providers": "^22.0.0",
Expand Down
Loading
Loading