Skip to content

Commit 80f846d

Browse files
committed
refactor: rename wallet category to type
1 parent d257aec commit 80f846d

4 files changed

Lines changed: 32 additions & 30 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import type { Bip44Account } from '../bip44';
99
import type { AccountGroup } from '../group';
1010
import type { AccountProvider } from '../provider';
1111
import type { AccountSelector } from '../selector';
12-
import { AccountWalletCategory } from '../wallet';
12+
import { AccountWalletType } from '../wallet';
1313

1414
const MULTICHAIN_ACCOUNT_ID_REGEX = new RegExp(
15-
`^${AccountWalletCategory.Entropy}:.*/(?<groupIndex>\\d+)$`,
15+
`^${AccountWalletType.Entropy}:.*/(?<groupIndex>\\d+)$`,
1616
'u',
1717
);
1818

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import type { AccountGroupId } from '../group';
1313
import { toDefaultAccountGroupId } from '../group';
1414
import type { AccountProvider } from '../provider';
1515
import type { AccountWallet } from '../wallet';
16-
import { AccountWalletCategory } from '../wallet';
16+
import { AccountWalletType } from '../wallet';
1717

1818
/**
1919
* Multichain account wallet ID.
2020
*/
2121
export type MultichainAccountWalletId =
22-
`${AccountWalletCategory.Entropy}:${EntropySourceId}`;
22+
`${AccountWalletType.Entropy}:${EntropySourceId}`;
2323

2424
/**
2525
* A multichain account wallet that holds multiple multichain accounts (one multichain account per
@@ -104,12 +104,12 @@ export class MultichainAccountWallet<
104104
}
105105

106106
/**
107-
* Gets the multichain account wallet category, which is always {@link AccountWalletCategory.Entropy}.
107+
* Gets the multichain account wallet type, which is always {@link AccountWalletType.Entropy}.
108108
*
109-
* @returns The multichain account wallet category.
109+
* @returns The multichain account wallet type.
110110
*/
111-
get category(): AccountWalletCategory.Entropy {
112-
return AccountWalletCategory.Entropy;
111+
get type(): AccountWalletType.Entropy {
112+
return AccountWalletType.Entropy;
113113
}
114114

115115
/**
@@ -184,5 +184,5 @@ export class MultichainAccountWallet<
184184
export function toMultichainAccountWalletId(
185185
entropySource: EntropySourceId,
186186
): MultichainAccountWalletId {
187-
return `${AccountWalletCategory.Entropy}:${entropySource}`;
187+
return `${AccountWalletType.Entropy}:${entropySource}`;
188188
}

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@ import type { KeyringAccount } from '@metamask/keyring-api';
33
// Circular import are allowed when using `import type`.
44
import type { AccountGroup, AccountGroupId } from './group';
55

6-
export enum AccountWalletCategory {
6+
/**
7+
* Wallet type.
8+
*
9+
* Each wallet types groups accounts using different criterias.
10+
*/
11+
export enum AccountWalletType {
712
/**
8-
* Category for wallets that group accounts based on their
9-
* entropy source.
13+
* Wallet grouping accounts based on their entropy source.
1014
*/
1115
Entropy = 'entropy',
1216

1317
/**
14-
* Category for wallets that group accounts based on their
15-
* keyring's type.
18+
* Wallet grouping accounts based on their keyring's type.
1619
*/
1720
Keyring = 'keyring',
1821

1922
/**
20-
* Category for wallets that group accounts associated with an
21-
* account management Snap.
23+
* Wallet grouping accounts associated with an account management Snap.
2224
*/
2325
Snap = 'snap',
2426
}
2527

2628
/**
2729
* Account wallet ID.
2830
*/
29-
export type AccountWalletId = `${AccountWalletCategory}:${string}`;
31+
export type AccountWalletId = `${AccountWalletType}:${string}`;
3032

3133
/**
3234
* Account wallet that can hold multiple account groups.
@@ -38,9 +40,9 @@ export type AccountWallet<Account extends KeyringAccount> = {
3840
get id(): AccountWalletId;
3941

4042
/**
41-
* Account wallet category.
43+
* Account wallet type.
4244
*/
43-
get category(): AccountWalletCategory;
45+
get type(): AccountWalletType;
4446

4547
/**
4648
* Gets account group for a given ID.
@@ -59,15 +61,15 @@ export type AccountWallet<Account extends KeyringAccount> = {
5961
};
6062

6163
/**
62-
* Convert a unique ID to a wallet ID for a given category.
64+
* Convert a unique ID to a wallet ID for a given type.
6365
*
64-
* @param category - A wallet category.
66+
* @param type - A wallet type.
6567
* @param id - A unique ID.
6668
* @returns A wallet ID.
6769
*/
6870
export function toAccountWalletId(
69-
category: AccountWalletCategory,
71+
type: AccountWalletType,
7072
id: string,
7173
): AccountWalletId {
72-
return `${category}:${id}`;
74+
return `${type}:${id}`;
7375
}

packages/account-api/src/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import type {
2929
Bip44Account,
3030
} from './api';
3131
import {
32-
AccountWalletCategory,
32+
AccountWalletType,
3333
toAccountGroupId,
3434
toAccountWalletId,
3535
toDefaultAccountGroupId,
@@ -688,7 +688,7 @@ describe('index', () => {
688688
await setupMultichainAccountWallet();
689689

690690
const groupId: AccountGroupId = toAccountGroupId(
691-
toAccountWalletId(AccountWalletCategory.Keyring, 'bad-keyring-id'),
691+
toAccountWalletId(AccountWalletType.Keyring, 'bad-keyring-id'),
692692
'bad-index',
693693
);
694694
const group: AccountGroup<MockedAccount> | undefined =
@@ -711,16 +711,16 @@ describe('index', () => {
711711
// test AccountGroup too!
712712
const wallet = await setupMultichainAccountWallet();
713713

714-
expect(wallet.category).toBe(AccountWalletCategory.Entropy);
714+
expect(wallet.type).toBe(AccountWalletType.Entropy);
715715
expect(wallet.id).toStrictEqual(
716-
toAccountWalletId(AccountWalletCategory.Entropy, wallet.entropySource),
716+
toAccountWalletId(AccountWalletType.Entropy, wallet.entropySource),
717717
);
718718
});
719719
});
720720

721721
describe('toAccountGroupId', () => {
722722
it('converts an account wallet id and a unique id to a group id', () => {
723-
const walletId = toAccountWalletId(AccountWalletCategory.Keyring, 'test');
723+
const walletId = toAccountWalletId(AccountWalletType.Keyring, 'test');
724724
const groupId = toAccountGroupId(walletId, 'test');
725725

726726
expect(groupId.startsWith(walletId)).toBe(true);
@@ -729,7 +729,7 @@ describe('index', () => {
729729

730730
describe('toDefaultAccountGroupId', () => {
731731
it('converts an account wallet id and to the default group id', () => {
732-
const walletId = toAccountWalletId(AccountWalletCategory.Keyring, 'test');
732+
const walletId = toAccountWalletId(AccountWalletType.Keyring, 'test');
733733
const groupId = toDefaultAccountGroupId(walletId);
734734

735735
expect(groupId.startsWith(walletId)).toBe(true);
@@ -738,7 +738,7 @@ describe('index', () => {
738738

739739
describe('getGroupIndexFromMultichainAccountId', () => {
740740
it('throws if it cannot extract group index', () => {
741-
const walletId = toAccountWalletId(AccountWalletCategory.Keyring, 'test');
741+
const walletId = toAccountWalletId(AccountWalletType.Keyring, 'test');
742742
const groupId = toAccountGroupId(walletId, 'test');
743743

744744
expect(() =>

0 commit comments

Comments
 (0)