@metamask-previews/account-tree-controller 0.7.0-preview-e4e5ca5c → 0.7.0-preview-115d10e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
+ - Add `AccountTreeGroup.{get,select}` selectors ([#6248](https://github.com/MetaMask/core/pull/6248))
12
13
  - Add persistence support for user customizations ([#6221](https://github.com/MetaMask/core/pull/6221))
13
14
  - New `accountGroupsMetadata` (of new type `AccountTreeGroupPersistedMetadata`) and `accountWalletsMetadata` (of new type `AccountTreeWalletPersistedMetadata`) state properties to persist custom names, pinning, and hiding states.
14
15
  - Custom names and metadata survive controller initialization and tree rebuilds.
@@ -23,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
24
 
24
25
  ### Changed
25
26
 
26
- - **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))
27
+ - **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))
27
28
  - **BREAKING:** Move `wallet.metadata.type` tag to `wallet` node ([#6214](https://github.com/MetaMask/core/pull/6214))
28
29
  - This `type` can be used as a tag to strongly-type (tagged-union) the `AccountWalletObject`.
29
30
  - Defaults to the EVM account from a group when using `setSelectedAccountGroup` ([#6208](https://github.com/MetaMask/core/pull/6208))
package/dist/group.cjs CHANGED
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _AccountTreeGroup_instances, _AccountTreeGroup_messenger, _AccountTreeGroup_group, _AccountTreeGroup_wallet, _AccountTreeGroup_getAccount;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AccountTreeGroup = exports.DEFAULT_ACCOUNT_GROUP_NAME = void 0;
16
+ const account_api_1 = require("@metamask/account-api");
16
17
  exports.DEFAULT_ACCOUNT_GROUP_NAME = 'Default';
17
18
  /**
18
19
  * Account group coming from the {@link AccountTreeController}.
@@ -56,6 +57,12 @@ class AccountTreeGroup {
56
57
  // A group always have at least one account.
57
58
  return __classPrivateFieldGet(this, _AccountTreeGroup_instances, "m", _AccountTreeGroup_getAccount).call(this, accountIds[0]);
58
59
  }
60
+ get(selector) {
61
+ return (0, account_api_1.selectOne)(this.getAccounts(), selector);
62
+ }
63
+ select(selector) {
64
+ return (0, account_api_1.select)(this.getAccounts(), selector);
65
+ }
59
66
  }
60
67
  exports.AccountTreeGroup = AccountTreeGroup;
61
68
  _AccountTreeGroup_messenger = new WeakMap(), _AccountTreeGroup_group = new WeakMap(), _AccountTreeGroup_wallet = new WeakMap(), _AccountTreeGroup_instances = new WeakSet(), _AccountTreeGroup_getAccount = function _AccountTreeGroup_getAccount(id) {
@@ -1 +1 @@
1
- {"version":3,"file":"group.cjs","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AA+Ba,QAAA,0BAA0B,GAAW,SAAS,CAAC;AA6D5D;;GAEG;AACH,MAAa,gBAAgB;IAO3B,YAAY,EACV,SAAS,EACT,MAAM,EACN,KAAK,GAKN;;QAdQ,8CAA2C;QAE3C,0CAA2B;QAE3B,2CAA2B;QAWlC,uBAAA,IAAI,+BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2BAAU,KAAK,MAAA,CAAC;QACpB,uBAAA,IAAI,4BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,uBAAA,IAAI,+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AccountGroup, AccountGroupId } from '@metamask/account-api';\nimport type { AccountId } from '@metamask/accounts-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { UpdatableField, ExtractFieldValues } from './type-utils.js';\nimport type { AccountTreeControllerMessenger } from './types';\nimport type { AccountTreeWallet } from './wallet';\n\n/**\n * Persisted metadata for account groups (stored in controller state for persistence/sync).\n */\nexport type AccountTreeGroupPersistedMetadata = {\n /** Custom name set by user, overrides default naming logic */\n name?: UpdatableField<string>;\n /** Whether this group is pinned in the UI */\n pinned?: UpdatableField<boolean>;\n /** Whether this group is hidden in the UI */\n hidden?: UpdatableField<boolean>;\n};\n\n/**\n * Tree metadata for account groups (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeGroupMetadata = Required<\n ExtractFieldValues<AccountTreeGroupPersistedMetadata>\n>;\n\nexport const DEFAULT_ACCOUNT_GROUP_NAME: string = 'Default';\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountGroupObject<\n Type extends {\n type: AccountGroupType;\n id: AccountGroupId;\n accounts: AccountId[];\n metadata: AccountTreeGroupMetadata;\n },\n> = Type;\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupMultichainAccountObject = {\n type: AccountGroupType.MultichainAccount;\n id: MultichainAccountGroupId;\n // Blockchain Accounts (at least 1 account per multichain-accounts):\n accounts: [AccountId, ...AccountId[]];\n metadata: AccountTreeGroupMetadata & {\n entropy: {\n groupIndex: number;\n };\n };\n};\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupSingleAccountObject = {\n type: AccountGroupType.SingleAccount;\n id: AccountGroupId;\n // Blockchain Accounts (1 account per group):\n accounts: [AccountId];\n metadata: AccountTreeGroupMetadata;\n};\n\n/**\n * Account group object.\n */\nexport type AccountGroupObject = IsAccountGroupObject<\n AccountGroupMultichainAccountObject | AccountGroupSingleAccountObject\n>;\n\nexport type AccountGroupObjectOf<GroupType extends AccountGroupType> = Extract<\n | {\n type: AccountGroupType.MultichainAccount;\n object: AccountGroupMultichainAccountObject;\n }\n | {\n type: AccountGroupType.SingleAccount;\n object: AccountGroupSingleAccountObject;\n },\n { type: GroupType }\n>['object'];\n\n/**\n * Account group coming from the {@link AccountTreeController}.\n */\nexport class AccountTreeGroup implements AccountGroup<InternalAccount> {\n readonly #messenger: AccountTreeControllerMessenger;\n\n readonly #group: AccountGroupObject;\n\n readonly #wallet: AccountTreeWallet;\n\n constructor({\n messenger,\n wallet,\n group,\n }: {\n messenger: AccountTreeControllerMessenger;\n wallet: AccountTreeWallet;\n group: AccountGroupObject;\n }) {\n this.#messenger = messenger;\n this.#group = group;\n this.#wallet = wallet;\n }\n\n get id(): AccountGroupId {\n return this.#group.id;\n }\n\n get wallet(): AccountTreeWallet {\n return this.#wallet;\n }\n\n get type(): AccountGroupType {\n return this.#group.type;\n }\n\n get name(): string {\n return this.#group.metadata.name;\n }\n\n getAccountIds(): [InternalAccount['id'], ...InternalAccount['id'][]] {\n return this.#group.accounts;\n }\n\n getAccount(id: string): InternalAccount | undefined {\n return this.#messenger.call('AccountsController:getAccount', id);\n }\n\n #getAccount(id: string): InternalAccount {\n const account = this.getAccount(id);\n\n if (!account) {\n throw new Error(`Unable to get account with ID: \"${id}\"`);\n }\n return account;\n }\n\n getAccounts(): InternalAccount[] {\n return this.#group.accounts.map((id) => this.#getAccount(id));\n }\n\n getOnlyAccount(): InternalAccount {\n const accountIds = this.getAccountIds();\n\n if (accountIds.length > 1) {\n throw new Error('Group contains more than 1 account');\n }\n\n // A group always have at least one account.\n return this.#getAccount(accountIds[0]);\n }\n}\n"]}
1
+ {"version":3,"file":"group.cjs","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAK+B;AAgClB,QAAA,0BAA0B,GAAW,SAAS,CAAC;AA6D5D;;GAEG;AACH,MAAa,gBAAgB;IAO3B,YAAY,EACV,SAAS,EACT,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AAA,uBAAS,EAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,QAA0C;QAC/C,OAAO,IAAA,oBAAM,EAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;CACF;AA5ED,4CA4EC;kPA/Ba,EAAU;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;KAC3D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n select,\n selectOne,\n type AccountGroupType,\n type MultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type {\n AccountGroup,\n AccountGroupId,\n AccountSelector,\n} from '@metamask/account-api';\nimport type { AccountId } from '@metamask/accounts-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { UpdatableField, ExtractFieldValues } from './type-utils.js';\nimport type { AccountTreeControllerMessenger } from './types';\nimport type { AccountTreeWallet } from './wallet';\n\n/**\n * Persisted metadata for account groups (stored in controller state for persistence/sync).\n */\nexport type AccountTreeGroupPersistedMetadata = {\n /** Custom name set by user, overrides default naming logic */\n name?: UpdatableField<string>;\n /** Whether this group is pinned in the UI */\n pinned?: UpdatableField<boolean>;\n /** Whether this group is hidden in the UI */\n hidden?: UpdatableField<boolean>;\n};\n\n/**\n * Tree metadata for account groups (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeGroupMetadata = Required<\n ExtractFieldValues<AccountTreeGroupPersistedMetadata>\n>;\n\nexport const DEFAULT_ACCOUNT_GROUP_NAME: string = 'Default';\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountGroupObject<\n Type extends {\n type: AccountGroupType;\n id: AccountGroupId;\n accounts: AccountId[];\n metadata: AccountTreeGroupMetadata;\n },\n> = Type;\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupMultichainAccountObject = {\n type: AccountGroupType.MultichainAccount;\n id: MultichainAccountGroupId;\n // Blockchain Accounts (at least 1 account per multichain-accounts):\n accounts: [AccountId, ...AccountId[]];\n metadata: AccountTreeGroupMetadata & {\n entropy: {\n groupIndex: number;\n };\n };\n};\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupSingleAccountObject = {\n type: AccountGroupType.SingleAccount;\n id: AccountGroupId;\n // Blockchain Accounts (1 account per group):\n accounts: [AccountId];\n metadata: AccountTreeGroupMetadata;\n};\n\n/**\n * Account group object.\n */\nexport type AccountGroupObject = IsAccountGroupObject<\n AccountGroupMultichainAccountObject | AccountGroupSingleAccountObject\n>;\n\nexport type AccountGroupObjectOf<GroupType extends AccountGroupType> = Extract<\n | {\n type: AccountGroupType.MultichainAccount;\n object: AccountGroupMultichainAccountObject;\n }\n | {\n type: AccountGroupType.SingleAccount;\n object: AccountGroupSingleAccountObject;\n },\n { type: GroupType }\n>['object'];\n\n/**\n * Account group coming from the {@link AccountTreeController}.\n */\nexport class AccountTreeGroup implements AccountGroup<InternalAccount> {\n readonly #messenger: AccountTreeControllerMessenger;\n\n readonly #group: AccountGroupObject;\n\n readonly #wallet: AccountTreeWallet;\n\n constructor({\n messenger,\n wallet,\n group,\n }: {\n messenger: AccountTreeControllerMessenger;\n wallet: AccountTreeWallet;\n group: AccountGroupObject;\n }) {\n this.#messenger = messenger;\n this.#group = group;\n this.#wallet = wallet;\n }\n\n get id(): AccountGroupId {\n return this.#group.id;\n }\n\n get wallet(): AccountTreeWallet {\n return this.#wallet;\n }\n\n get type(): AccountGroupType {\n return this.#group.type;\n }\n\n get name(): string {\n return this.#group.metadata.name;\n }\n\n getAccountIds(): [InternalAccount['id'], ...InternalAccount['id'][]] {\n return this.#group.accounts;\n }\n\n getAccount(id: string): InternalAccount | undefined {\n return this.#messenger.call('AccountsController:getAccount', id);\n }\n\n #getAccount(id: string): InternalAccount {\n const account = this.getAccount(id);\n\n if (!account) {\n throw new Error(`Unable to get account with ID: \"${id}\"`);\n }\n return account;\n }\n\n getAccounts(): InternalAccount[] {\n return this.#group.accounts.map((id) => this.#getAccount(id));\n }\n\n getOnlyAccount(): InternalAccount {\n const accountIds = this.getAccountIds();\n\n if (accountIds.length > 1) {\n throw new Error('Group contains more than 1 account');\n }\n\n // A group always have at least one account.\n return this.#getAccount(accountIds[0]);\n }\n\n get(selector: AccountSelector<InternalAccount>): InternalAccount | undefined {\n return selectOne(this.getAccounts(), selector);\n }\n\n select(selector: AccountSelector<InternalAccount>): InternalAccount[] {\n return select(this.getAccounts(), selector);\n }\n}\n"]}
package/dist/group.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AccountGroupType, MultichainAccountGroupId } from "@metamask/account-api";
2
- import type { AccountGroup, AccountGroupId } from "@metamask/account-api";
1
+ import { type AccountGroupType, type MultichainAccountGroupId } from "@metamask/account-api";
2
+ import type { AccountGroup, AccountGroupId, AccountSelector } from "@metamask/account-api";
3
3
  import type { AccountId } from "@metamask/accounts-controller";
4
4
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
5
  import type { UpdatableField, ExtractFieldValues } from "./type-utils.cjs";
@@ -85,6 +85,8 @@ export declare class AccountTreeGroup implements AccountGroup<InternalAccount> {
85
85
  getAccount(id: string): InternalAccount | undefined;
86
86
  getAccounts(): InternalAccount[];
87
87
  getOnlyAccount(): InternalAccount;
88
+ get(selector: AccountSelector<InternalAccount>): InternalAccount | undefined;
89
+ select(selector: AccountSelector<InternalAccount>): InternalAccount[];
88
90
  }
89
91
  export {};
90
92
  //# sourceMappingURL=group.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.cts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,8BAA8B;AAC/B,O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,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAanD,WAAW,IAAI,eAAe,EAAE;IAIhC,cAAc,IAAI,eAAe;IAWjC,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,SAAS;IAI5E,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,eAAe,CAAC,GAAG,eAAe,EAAE;CAGtE"}
package/dist/group.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AccountGroupType, MultichainAccountGroupId } from "@metamask/account-api";
2
- import type { AccountGroup, AccountGroupId } from "@metamask/account-api";
1
+ import { type AccountGroupType, type MultichainAccountGroupId } from "@metamask/account-api";
2
+ import type { AccountGroup, AccountGroupId, AccountSelector } from "@metamask/account-api";
3
3
  import type { AccountId } from "@metamask/accounts-controller";
4
4
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
5
  import type { UpdatableField, ExtractFieldValues } from "./type-utils.mjs";
@@ -85,6 +85,8 @@ export declare class AccountTreeGroup implements AccountGroup<InternalAccount> {
85
85
  getAccount(id: string): InternalAccount | undefined;
86
86
  getAccounts(): InternalAccount[];
87
87
  getOnlyAccount(): InternalAccount;
88
+ get(selector: AccountSelector<InternalAccount>): InternalAccount | undefined;
89
+ select(selector: AccountSelector<InternalAccount>): InternalAccount[];
88
90
  }
89
91
  export {};
90
92
  //# sourceMappingURL=group.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.mts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,8BAA8B;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,sCAAsC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,yBAAwB;AAC1E,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AE,eAAe,CAAC,eAAe,CAAC,GAAG,eAAe,EAAE;CAGtE"}
package/dist/group.mjs CHANGED
@@ -10,6 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _AccountTreeGroup_instances, _AccountTreeGroup_messenger, _AccountTreeGroup_group, _AccountTreeGroup_wallet, _AccountTreeGroup_getAccount;
13
+ import { select, selectOne } from "@metamask/account-api";
13
14
  export const DEFAULT_ACCOUNT_GROUP_NAME = 'Default';
14
15
  /**
15
16
  * Account group coming from the {@link AccountTreeController}.
@@ -53,6 +54,12 @@ export class AccountTreeGroup {
53
54
  // A group always have at least one account.
54
55
  return __classPrivateFieldGet(this, _AccountTreeGroup_instances, "m", _AccountTreeGroup_getAccount).call(this, accountIds[0]);
55
56
  }
57
+ get(selector) {
58
+ return selectOne(this.getAccounts(), selector);
59
+ }
60
+ select(selector) {
61
+ return select(this.getAccounts(), selector);
62
+ }
56
63
  }
57
64
  _AccountTreeGroup_messenger = new WeakMap(), _AccountTreeGroup_group = new WeakMap(), _AccountTreeGroup_wallet = new WeakMap(), _AccountTreeGroup_instances = new WeakSet(), _AccountTreeGroup_getAccount = function _AccountTreeGroup_getAccount(id) {
58
65
  const account = this.getAccount(id);
@@ -1 +1 @@
1
- {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+BA,MAAM,CAAC,MAAM,0BAA0B,GAAW,SAAS,CAAC;AA6D5D;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAO3B,YAAY,EACV,SAAS,EACT,MAAM,EACN,KAAK,GAKN;;QAdQ,8CAA2C;QAE3C,0CAA2B;QAE3B,2CAA2B;QAWlC,uBAAA,IAAI,+BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2BAAU,KAAK,MAAA,CAAC;QACpB,uBAAA,IAAI,4B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ourcesContent":["import type {\n AccountGroupType,\n MultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type { AccountGroup, AccountGroupId } from '@metamask/account-api';\nimport type { AccountId } from '@metamask/accounts-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { UpdatableField, ExtractFieldValues } from './type-utils.js';\nimport type { AccountTreeControllerMessenger } from './types';\nimport type { AccountTreeWallet } from './wallet';\n\n/**\n * Persisted metadata for account groups (stored in controller state for persistence/sync).\n */\nexport type AccountTreeGroupPersistedMetadata = {\n /** Custom name set by user, overrides default naming logic */\n name?: UpdatableField<string>;\n /** Whether this group is pinned in the UI */\n pinned?: UpdatableField<boolean>;\n /** Whether this group is hidden in the UI */\n hidden?: UpdatableField<boolean>;\n};\n\n/**\n * Tree metadata for account groups (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeGroupMetadata = Required<\n ExtractFieldValues<AccountTreeGroupPersistedMetadata>\n>;\n\nexport const DEFAULT_ACCOUNT_GROUP_NAME: string = 'Default';\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountGroupObject<\n Type extends {\n type: AccountGroupType;\n id: AccountGroupId;\n accounts: AccountId[];\n metadata: AccountTreeGroupMetadata;\n },\n> = Type;\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupMultichainAccountObject = {\n type: AccountGroupType.MultichainAccount;\n id: MultichainAccountGroupId;\n // Blockchain Accounts (at least 1 account per multichain-accounts):\n accounts: [AccountId, ...AccountId[]];\n metadata: AccountTreeGroupMetadata & {\n entropy: {\n groupIndex: number;\n };\n };\n};\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupSingleAccountObject = {\n type: AccountGroupType.SingleAccount;\n id: AccountGroupId;\n // Blockchain Accounts (1 account per group):\n accounts: [AccountId];\n metadata: AccountTreeGroupMetadata;\n};\n\n/**\n * Account group object.\n */\nexport type AccountGroupObject = IsAccountGroupObject<\n AccountGroupMultichainAccountObject | AccountGroupSingleAccountObject\n>;\n\nexport type AccountGroupObjectOf<GroupType extends AccountGroupType> = Extract<\n | {\n type: AccountGroupType.MultichainAccount;\n object: AccountGroupMultichainAccountObject;\n }\n | {\n type: AccountGroupType.SingleAccount;\n object: AccountGroupSingleAccountObject;\n },\n { type: GroupType }\n>['object'];\n\n/**\n * Account group coming from the {@link AccountTreeController}.\n */\nexport class AccountTreeGroup implements AccountGroup<InternalAccount> {\n readonly #messenger: AccountTreeControllerMessenger;\n\n readonly #group: AccountGroupObject;\n\n readonly #wallet: AccountTreeWallet;\n\n constructor({\n messenger,\n wallet,\n group,\n }: {\n messenger: AccountTreeControllerMessenger;\n wallet: AccountTreeWallet;\n group: AccountGroupObject;\n }) {\n this.#messenger = messenger;\n this.#group = group;\n this.#wallet = wallet;\n }\n\n get id(): AccountGroupId {\n return this.#group.id;\n }\n\n get wallet(): AccountTreeWallet {\n return this.#wallet;\n }\n\n get type(): AccountGroupType {\n return this.#group.type;\n }\n\n get name(): string {\n return this.#group.metadata.name;\n }\n\n getAccountIds(): [InternalAccount['id'], ...InternalAccount['id'][]] {\n return this.#group.accounts;\n }\n\n getAccount(id: string): InternalAccount | undefined {\n return this.#messenger.call('AccountsController:getAccount', id);\n }\n\n #getAccount(id: string): InternalAccount {\n const account = this.getAccount(id);\n\n if (!account) {\n throw new Error(`Unable to get account with ID: \"${id}\"`);\n }\n return account;\n }\n\n getAccounts(): InternalAccount[] {\n return this.#group.accounts.map((id) => this.#getAccount(id));\n }\n\n getOnlyAccount(): InternalAccount {\n const accountIds = this.getAccountIds();\n\n if (accountIds.length > 1) {\n throw new Error('Group contains more than 1 account');\n }\n\n // A group always have at least one account.\n return this.#getAccount(accountIds[0]);\n }\n}\n"]}
1
+ {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,MAAM,EACN,SAAS,EAGV,8BAA8B;AAgC/B,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,iEAAY,MAAhB,IAAI,EAAa,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,GAAG,CAAC,QAA0C;QAC5C,OAAO,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,QAA0C;QAC/C,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;CACF;kPA/Ba,EAAU;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;KAC3D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n select,\n selectOne,\n type AccountGroupType,\n type MultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type {\n AccountGroup,\n AccountGroupId,\n AccountSelector,\n} from '@metamask/account-api';\nimport type { AccountId } from '@metamask/accounts-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { UpdatableField, ExtractFieldValues } from './type-utils.js';\nimport type { AccountTreeControllerMessenger } from './types';\nimport type { AccountTreeWallet } from './wallet';\n\n/**\n * Persisted metadata for account groups (stored in controller state for persistence/sync).\n */\nexport type AccountTreeGroupPersistedMetadata = {\n /** Custom name set by user, overrides default naming logic */\n name?: UpdatableField<string>;\n /** Whether this group is pinned in the UI */\n pinned?: UpdatableField<boolean>;\n /** Whether this group is hidden in the UI */\n hidden?: UpdatableField<boolean>;\n};\n\n/**\n * Tree metadata for account groups (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeGroupMetadata = Required<\n ExtractFieldValues<AccountTreeGroupPersistedMetadata>\n>;\n\nexport const DEFAULT_ACCOUNT_GROUP_NAME: string = 'Default';\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountGroupObject<\n Type extends {\n type: AccountGroupType;\n id: AccountGroupId;\n accounts: AccountId[];\n metadata: AccountTreeGroupMetadata;\n },\n> = Type;\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupMultichainAccountObject = {\n type: AccountGroupType.MultichainAccount;\n id: MultichainAccountGroupId;\n // Blockchain Accounts (at least 1 account per multichain-accounts):\n accounts: [AccountId, ...AccountId[]];\n metadata: AccountTreeGroupMetadata & {\n entropy: {\n groupIndex: number;\n };\n };\n};\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupSingleAccountObject = {\n type: AccountGroupType.SingleAccount;\n id: AccountGroupId;\n // Blockchain Accounts (1 account per group):\n accounts: [AccountId];\n metadata: AccountTreeGroupMetadata;\n};\n\n/**\n * Account group object.\n */\nexport type AccountGroupObject = IsAccountGroupObject<\n AccountGroupMultichainAccountObject | AccountGroupSingleAccountObject\n>;\n\nexport type AccountGroupObjectOf<GroupType extends AccountGroupType> = Extract<\n | {\n type: AccountGroupType.MultichainAccount;\n object: AccountGroupMultichainAccountObject;\n }\n | {\n type: AccountGroupType.SingleAccount;\n object: AccountGroupSingleAccountObject;\n },\n { type: GroupType }\n>['object'];\n\n/**\n * Account group coming from the {@link AccountTreeController}.\n */\nexport class AccountTreeGroup implements AccountGroup<InternalAccount> {\n readonly #messenger: AccountTreeControllerMessenger;\n\n readonly #group: AccountGroupObject;\n\n readonly #wallet: AccountTreeWallet;\n\n constructor({\n messenger,\n wallet,\n group,\n }: {\n messenger: AccountTreeControllerMessenger;\n wallet: AccountTreeWallet;\n group: AccountGroupObject;\n }) {\n this.#messenger = messenger;\n this.#group = group;\n this.#wallet = wallet;\n }\n\n get id(): AccountGroupId {\n return this.#group.id;\n }\n\n get wallet(): AccountTreeWallet {\n return this.#wallet;\n }\n\n get type(): AccountGroupType {\n return this.#group.type;\n }\n\n get name(): string {\n return this.#group.metadata.name;\n }\n\n getAccountIds(): [InternalAccount['id'], ...InternalAccount['id'][]] {\n return this.#group.accounts;\n }\n\n getAccount(id: string): InternalAccount | undefined {\n return this.#messenger.call('AccountsController:getAccount', id);\n }\n\n #getAccount(id: string): InternalAccount {\n const account = this.getAccount(id);\n\n if (!account) {\n throw new Error(`Unable to get account with ID: \"${id}\"`);\n }\n return account;\n }\n\n getAccounts(): InternalAccount[] {\n return this.#group.accounts.map((id) => this.#getAccount(id));\n }\n\n getOnlyAccount(): InternalAccount {\n const accountIds = this.getAccountIds();\n\n if (accountIds.length > 1) {\n throw new Error('Group contains more than 1 account');\n }\n\n // A group always have at least one account.\n return this.#getAccount(accountIds[0]);\n }\n\n get(selector: AccountSelector<InternalAccount>): InternalAccount | undefined {\n return selectOne(this.getAccounts(), selector);\n }\n\n select(selector: AccountSelector<InternalAccount>): InternalAccount[] {\n return select(this.getAccounts(), selector);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/account-tree-controller",
3
- "version": "0.7.0-preview-e4e5ca5c",
3
+ "version": "0.7.0-preview-115d10e",
4
4
  "description": "Controller to group account together based on some pre-defined rules",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -53,10 +53,10 @@
53
53
  "lodash": "^4.17.21"
54
54
  },
55
55
  "devDependencies": {
56
- "@metamask/account-api": "^0.7.0",
56
+ "@metamask/account-api": "^0.9.0",
57
57
  "@metamask/accounts-controller": "^32.0.1",
58
58
  "@metamask/auto-changelog": "^3.4.4",
59
- "@metamask/keyring-api": "^19.0.0",
59
+ "@metamask/keyring-api": "^20.0.0",
60
60
  "@metamask/keyring-controller": "^22.1.0",
61
61
  "@metamask/providers": "^22.1.0",
62
62
  "@metamask/snaps-controllers": "^14.0.1",
@@ -70,7 +70,7 @@
70
70
  "webextension-polyfill": "^0.12.0"
71
71
  },
72
72
  "peerDependencies": {
73
- "@metamask/account-api": "^0.7.0",
73
+ "@metamask/account-api": "^0.9.0",
74
74
  "@metamask/accounts-controller": "^32.0.0",
75
75
  "@metamask/keyring-controller": "^22.0.0",
76
76
  "@metamask/providers": "^22.0.0",