Skip to content

Commit 4083743

Browse files
authored
refactor(account-api)!: move get/select in AccountGroup type (#343)
Moving the `get` and `select` methods on the `AccountGroup` type. Allowing to make `AccountGroup` more generic. We want to be able to query/select the underlying accounts even when you're dealing with a "single-account group". This way you can handle both single-account and multichain-account group the same way.
1 parent 7033e0b commit 4083743

3 files changed

Lines changed: 22 additions & 18 deletions

File tree

packages/account-api/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add `assertIsBip44Account` ([#339](https://github.com/MetaMask/accounts/pull/339))
1313

14+
### Changed
15+
16+
- **BREAKING:** Move `get` and `select` methods to the `AccountGroup` type ([#343](https://github.com/MetaMask/accounts/pull/343))
17+
1418
## [0.7.0]
1519

1620
### Added

packages/account-api/src/api/group.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { KeyringAccount } from '@metamask/keyring-api';
22

33
// Circular import are allowed when using `import type`.
4+
import type { AccountSelector } from './selector';
45
import type {
56
AccountWallet,
67
AccountWalletId,
@@ -67,6 +68,23 @@ export type AccountGroup<Account extends KeyringAccount> = {
6768
* @returns The account or undefined if not found.
6869
*/
6970
getAccount(id: Account['id']): Account | undefined;
71+
72+
/**
73+
* Query an account matching the selector.
74+
*
75+
* @param selector - Query selector.
76+
* @returns The account matching the selector or undefined if not matching.
77+
* @throws If multiple accounts match the selector.
78+
*/
79+
get(selector: AccountSelector<Account>): Account | undefined;
80+
81+
/**
82+
* Query accounts matching the selector.
83+
*
84+
* @param selector - Query selector.
85+
* @returns The accounts matching the selector.
86+
*/
87+
select(selector: AccountSelector<Account>): Account[];
7088
};
7189

7290
/**

packages/account-api/src/api/multichain/group.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
} from './wallet';
77
import type { Bip44Account } from '../bip44';
88
import type { AccountGroup, AccountGroupType } from '../group';
9-
import type { AccountSelector } from '../selector';
109
import { AccountWalletType } from '../wallet';
1110

1211
const MULTICHAIN_ACCOUNT_GROUP_ID_REGEX = new RegExp(
@@ -44,23 +43,6 @@ export type MultichainAccountGroup<
4443
* Multichain account group index.
4544
*/
4645
get index(): number;
47-
48-
/**
49-
* Query an account matching the selector.
50-
*
51-
* @param selector - Query selector.
52-
* @returns The account matching the selector or undefined if not matching.
53-
* @throws If multiple accounts match the selector.
54-
*/
55-
get(selector: AccountSelector<Account>): Account | undefined;
56-
57-
/**
58-
* Query accounts matching the selector.
59-
*
60-
* @param selector - Query selector.
61-
* @returns The accounts matching the selector.
62-
*/
63-
select(selector: AccountSelector<Account>): Account[];
6446
};
6547

6648
/**

0 commit comments

Comments
 (0)