11import type { KeyringAccount } from '@metamask/keyring-api' ;
22
33// Circular import are allowed when using `import type`.
4+ import type { Bip44Account } from './bip44' ;
45import type { AccountGroup , AccountGroupId } from './group' ;
6+ import type { MultichainAccountWallet } from './multichain' ;
57
68/**
79 * Wallet type.
@@ -37,7 +39,7 @@ export const ACCOUNT_WALLET_ID_REGEX =
3739 * in. All of those operations cannot run concurrently, thus, the wallet
3840 * cannot have multiple status at once.
3941 */
40- export type BaseAccountWalletStatus =
42+ export type AccountWalletStatus =
4143 /**
4244 * The wallet is not initialized yet.
4345 */
@@ -47,20 +49,6 @@ export type BaseAccountWalletStatus =
4749 */
4850 | 'ready' ;
4951
50- /**
51- * Wallet status.
52- *
53- * Those status are used to report in which "state" the wallet is currently
54- * in. All of those operations cannot run concurrently, thus, the wallet
55- * cannot have multiple status at once.
56- */
57- export type AccountWalletStatus =
58- | BaseAccountWalletStatus
59- /**
60- * The wallet is running an operation.
61- */
62- | `in-progress:${string } `;
63-
6452/**
6553 * Parsed account wallet ID with its wallet type and sub-ID.
6654 */
@@ -70,19 +58,14 @@ export type ParsedAccountWalletId = {
7058} ;
7159
7260/**
73- * Account wallet that can hold multiple account groups.
61+ * Keyring account wallet that can hold multiple account groups.
7462 */
75- export type AccountWallet < Account extends KeyringAccount > = {
63+ export type BaseAccountWallet < Account extends KeyringAccount > = {
7664 /**
7765 * Account wallet ID.
7866 */
7967 get id ( ) : AccountWalletId ;
8068
81- /**
82- * Account wallet type.
83- */
84- get type ( ) : AccountWalletType ;
85-
8669 /**
8770 * Account wallet status.
8871 */
@@ -104,6 +87,50 @@ export type AccountWallet<Account extends KeyringAccount> = {
10487 getAccountGroups ( ) : AccountGroup < Account > [ ] ;
10588} ;
10689
90+ /**
91+ * Keyring account wallet that can hold multiple account groups.
92+ */
93+ export type KeyringAccountWallet < Account extends KeyringAccount > =
94+ BaseAccountWallet < Account > & {
95+ /**
96+ * Keyring account wallet type.
97+ */
98+ get type ( ) : AccountWalletType . Keyring ;
99+ } ;
100+
101+ /**
102+ * Snap keyring account wallet that can hold multiple account groups.
103+ */
104+ export type SnapAccountWallet < Account extends KeyringAccount > =
105+ BaseAccountWallet < Account > & {
106+ /**
107+ * Snap account wallet type.
108+ */
109+ get type ( ) : AccountWalletType . Snap ;
110+ } ;
111+
112+ /**
113+ * Type constraint for a {@link AccountGroupObject}. If one of its union-members
114+ * does not match this contraint, {@link AccountGroupObject} will resolve
115+ * to `never`.
116+ */
117+ type IsAccountWallet <
118+ Wallet extends BaseAccountWallet < Account > & {
119+ get type ( ) : AccountWalletType ;
120+ } ,
121+ Account extends KeyringAccount ,
122+ > = Wallet ;
123+
124+ /**
125+ * Account wallet that can hold multiple account groups.
126+ */
127+ export type AccountWallet < Account extends KeyringAccount > = IsAccountWallet <
128+ | KeyringAccountWallet < Account >
129+ | SnapAccountWallet < Account >
130+ | MultichainAccountWallet < Bip44Account < Account > > ,
131+ Account
132+ > ;
133+
107134/**
108135 * Type utility to compute a constrained {@link AccountWalletId} type given a
109136 * specifc {@link AccountWalletType}.
0 commit comments