Skip to content

Commit 0951323

Browse files
committed
feat(account-api): add wallet.status
1 parent caa080a commit 0951323

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

packages/account-api/CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add wallet `status` ([#367](https://github.com/MetaMask/accounts/pull/367))
13+
1014
## [0.10.0]
1115

1216
### Added

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import type { MultichainAccountGroup } from './group';
77
import type { Bip44Account } from '../bip44';
88
import type { AccountWallet } from '../wallet';
9-
import { AccountWalletType } from '../wallet';
9+
import { AccountWalletStatus, AccountWalletType } from '../wallet';
1010

1111
/**
1212
* Multichain account wallet ID.
@@ -28,6 +28,34 @@ export type ParsedMultichainAccountWalletId = {
2828
subId: string;
2929
};
3030

31+
/**
32+
* Wallet status.
33+
*
34+
* Those status are used to report in which "state" the wallet is currently
35+
* in. All of those operations cannot run concurrently, thus, the wallet
36+
* cannot have multiple status at once.
37+
*/
38+
export const MultichainAccountWalletStatus = {
39+
...AccountWalletStatus,
40+
41+
/**
42+
* Discovery is in progress for this wallet. New account groups will be
43+
* automatically added based on the account provider discovery result.
44+
*/
45+
DiscoveryInProgress: 'discovery-in-progress',
46+
/**
47+
* Alignment is in progress for this wallet. Account groups will be
48+
* automatically updated based on the active account providers.
49+
*/
50+
AlignmentInProgress: 'alignment-in-progress',
51+
/**
52+
* An on-going operation (creating/deleting) is in progress for this
53+
* wallet. Account groups will either be created or deleted during
54+
* this operation.
55+
*/
56+
OperationInProgress: 'operation-in-progress',
57+
} as const;
58+
3159
/**
3260
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
3361
* group index).
@@ -50,6 +78,11 @@ export type MultichainAccountWallet<
5078
*/
5179
get entropySource(): EntropySourceId;
5280

81+
/**
82+
* Multichain account wallet status.
83+
*/
84+
get status(): (typeof MultichainAccountWalletStatus)[keyof typeof MultichainAccountWalletStatus];
85+
5386
/**
5487
* Gets multichain account for a given index.
5588
*

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ export type AccountWalletId = `${AccountWalletType}:${string}`;
3030
export const ACCOUNT_WALLET_ID_REGEX =
3131
/^(?<walletType>entropy|keyring|snap):(?<walletSubId>.+)$/u;
3232

33+
/**
34+
* Wallet status.
35+
*
36+
* Those status are used to report in which "state" the wallet is currently
37+
* in. All of those operations cannot run concurrently, thus, the wallet
38+
* cannot have multiple status at once.
39+
*/
40+
export const AccountWalletStatus = {
41+
/**
42+
* The wallet is not initialized yet.
43+
*/
44+
Uninitialized: 'uninitialized',
45+
/**
46+
* The wallet is ready to run any operation.
47+
*/
48+
Ready: 'ready',
49+
} as const;
50+
3351
/**
3452
* Parsed account wallet ID with its wallet type and sub-ID.
3553
*/
@@ -52,6 +70,11 @@ export type AccountWallet<Account extends KeyringAccount> = {
5270
*/
5371
get type(): AccountWalletType;
5472

73+
/**
74+
* Account wallet status.
75+
*/
76+
get status(): (typeof AccountWalletStatus)[keyof typeof AccountWalletStatus];
77+
5578
/**
5679
* Gets account group for a given ID.
5780
*

0 commit comments

Comments
 (0)