Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions packages/account-tree-controller/src/AccountTreeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
AccountGroupType,
AccountSelector,
MultichainAccountWalletId,
MultichainAccountGroup,
Bip44Account,
} from '@metamask/account-api';
import type { MultichainAccountWalletStatus } from '@metamask/account-api';
import { type AccountId } from '@metamask/accounts-controller';
import type { StateMetadata } from '@metamask/base-controller';
import { BaseController } from '@metamask/base-controller';
import type { TraceCallback } from '@metamask/controller-utils';
import { isEvmAccountType } from '@metamask/keyring-api';
import { isEvmAccountType, KeyringAccount } from '@metamask/keyring-api';

Check failure on line 16 in packages/account-tree-controller/src/AccountTreeController.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Imports "KeyringAccount" are only used as type
import type { InternalAccount } from '@metamask/keyring-internal-api';

import type { BackupAndSyncEmitAnalyticsEventParams } from './backup-and-sync/analytics';
Expand Down Expand Up @@ -223,6 +225,20 @@
},
);

this.messagingSystem.subscribe(
'MultichainAccountService:multichainAccountGroupCreated',
(group) => {
this.#handleMultichainAccountGroupCreatedOrUpdated(group);
},
);

this.messagingSystem.subscribe(
'MultichainAccountService:multichainAccountGroupUpdated',
(group) => {
this.#handleMultichainAccountGroupCreatedOrUpdated(group);
},
);

this.#registerMessageHandlers();
}

Expand Down Expand Up @@ -616,6 +632,18 @@
}
}

/**
* Handles multichain account group created/updated event from
* the MultichainAccountService.
*
* @param group - Multichain account group being that got created or updated.
*/
#handleMultichainAccountGroupCreatedOrUpdated(
group: MultichainAccountGroup<Bip44Account<KeyringAccount>>,
): void {
this.#backupAndSyncService.enqueueSingleGroupSync(group.id);
}

/**
* Helper method to prune a group if it holds no accounts and additionally
* prune the wallet if it holds no groups. This action should take place
Expand Down Expand Up @@ -705,11 +733,6 @@

// Map group ID to its containing wallet ID for efficient direct access
this.#groupIdToWalletId.set(groupId, walletId);

// Trigger atomic sync for new group (only for entropy wallets)
if (wallet.type === AccountWalletType.Entropy) {
this.#backupAndSyncService.enqueueSingleGroupSync(groupId);
}
} else {
group.accounts.push(account.id);
}
Expand Down
10 changes: 9 additions & 1 deletion packages/account-tree-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ import type {
AccountWalletObject,
AccountTreeWalletPersistedMetadata,
} from './wallet';
import type { MultichainAccountServiceWalletStatusChangeEvent } from '../../multichain-account-service/src/types';
import type {
MultichainAccountServiceGetMultichainAccountWalletsAction,
MultichainAccountServiceMultichainAccountGroupCreatedEvent,
MultichainAccountServiceMultichainAccountGroupUpdatedEvent,
MultichainAccountServiceWalletStatusChangeEvent,
} from '../../multichain-account-service/src/types';

// Backward compatibility aliases using indexed access types
/**
Expand Down Expand Up @@ -126,6 +131,7 @@ export type AllowedActions =
| UserStorageController.UserStorageControllerPerformSetStorage
| UserStorageController.UserStorageControllerPerformBatchSetStorage
| AuthenticationController.AuthenticationControllerGetSessionProfile
| MultichainAccountServiceGetMultichainAccountWalletsAction
| MultichainAccountServiceCreateMultichainAccountGroupAction;

export type AccountTreeControllerActions =
Expand Down Expand Up @@ -166,6 +172,8 @@ export type AllowedEvents =
| AccountsControllerAccountRemovedEvent
| AccountsControllerSelectedAccountChangeEvent
| UserStorageController.UserStorageControllerStateChangeEvent
| MultichainAccountServiceMultichainAccountGroupCreatedEvent
| MultichainAccountServiceMultichainAccountGroupUpdatedEvent
| MultichainAccountServiceWalletStatusChangeEvent;

export type AccountTreeControllerEvents =
Expand Down
Loading