diff --git a/packages/accounts-controller/CHANGELOG.md b/packages/accounts-controller/CHANGELOG.md index 812cb46320..77d4ee763a 100644 --- a/packages/accounts-controller/CHANGELOG.md +++ b/packages/accounts-controller/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- **BREAKING:** Re-publish `SnapAccountService:account{AssetList,Balances,Transactions}Updated` events as `AccountsController:account{AssetList,Balances,Transactions}Updated` events ([#8978](https://github.com/MetaMask/core/pull/8978)) + - Now requires `SnapAccountService:account{AssetList,Balances,Transactions}Updated` events to be registered on the messenger. + - No longer requires `SnapKeyring:account{AssetList,Balances,Transactions}Updated` events to be registered on the messenger. + ## [38.1.2] ### Changed diff --git a/packages/accounts-controller/src/AccountsController.test.ts b/packages/accounts-controller/src/AccountsController.test.ts index 939c27df91..1df8dfbf46 100644 --- a/packages/accounts-controller/src/AccountsController.test.ts +++ b/packages/accounts-controller/src/AccountsController.test.ts @@ -328,9 +328,9 @@ function buildAccountsControllerMessenger( ], events: [ 'KeyringController:stateChange', - 'SnapKeyring:accountAssetListUpdated', - 'SnapKeyring:accountBalancesUpdated', - 'SnapKeyring:accountTransactionsUpdated', + 'SnapAccountService:accountAssetListUpdated', + 'SnapAccountService:accountBalancesUpdated', + 'SnapAccountService:accountTransactionsUpdated', 'MultichainNetworkController:networkDidChange', ], }); @@ -2144,7 +2144,7 @@ describe('AccountsController', () => { return { messenger, account, accountsController }; }; - it('re-publishes keyring events: SnapKeyring:accountBalancesUpdated', () => { + it('re-publishes keyring events: SnapAccountService:accountBalancesUpdated', () => { const { account, messenger } = setupTest(); const payload: AccountBalancesUpdatedEventPayload = { @@ -2163,11 +2163,11 @@ describe('AccountsController', () => { 'AccountsController:accountBalancesUpdated', mockRePublishedCallback, ); - messenger.publish('SnapKeyring:accountBalancesUpdated', payload); + messenger.publish('SnapAccountService:accountBalancesUpdated', payload); expect(mockRePublishedCallback).toHaveBeenCalledWith(payload); }); - it('re-publishes keyring events: SnapKeyring:accountAssetListUpdated', () => { + it('re-publishes keyring events: SnapAccountService:accountAssetListUpdated', () => { const { account, messenger } = setupTest(); const payload: AccountAssetListUpdatedEventPayload = { @@ -2184,11 +2184,11 @@ describe('AccountsController', () => { 'AccountsController:accountAssetListUpdated', mockRePublishedCallback, ); - messenger.publish('SnapKeyring:accountAssetListUpdated', payload); + messenger.publish('SnapAccountService:accountAssetListUpdated', payload); expect(mockRePublishedCallback).toHaveBeenCalledWith(payload); }); - it('re-publishes keyring events: SnapKeyring:accountTransactionsUpdated', () => { + it('re-publishes keyring events: SnapAccountService:accountTransactionsUpdated', () => { const { account, messenger } = setupTest(); const payload: AccountTransactionsUpdatedEventPayload = { @@ -2225,7 +2225,10 @@ describe('AccountsController', () => { 'AccountsController:accountTransactionsUpdated', mockRePublishedCallback, ); - messenger.publish('SnapKeyring:accountTransactionsUpdated', payload); + messenger.publish( + 'SnapAccountService:accountTransactionsUpdated', + payload, + ); expect(mockRePublishedCallback).toHaveBeenCalledWith(payload); }); }); diff --git a/packages/accounts-controller/src/AccountsController.ts b/packages/accounts-controller/src/AccountsController.ts index e5216b49b1..4c1004df74 100644 --- a/packages/accounts-controller/src/AccountsController.ts +++ b/packages/accounts-controller/src/AccountsController.ts @@ -38,7 +38,12 @@ import { cloneDeep } from 'lodash'; import { AccountsControllerMethodActions } from './AccountsController-method-action-types'; import { projectLogger as log } from './logger'; -import type { MultichainNetworkControllerNetworkDidChangeEvent } from './types'; +import type { + MultichainNetworkControllerNetworkDidChangeEvent, + SnapAccountServiceAccountAssetListUpdatedEvent, + SnapAccountServiceAccountBalancesUpdatedEvent, + SnapAccountServiceAccountTransactionsUpdatedEvent, +} from './types'; import type { AccountsControllerStrictState } from './typing'; import type { HdSnapKeyringAccount } from './utils'; import { @@ -212,9 +217,9 @@ export type AccountsControllerAccountAssetListUpdatedEvent = { */ export type AllowedEvents = | KeyringControllerStateChangeEvent - | SnapKeyringAccountAssetListUpdatedEvent - | SnapKeyringAccountBalancesUpdatedEvent - | SnapKeyringAccountTransactionsUpdatedEvent + | SnapAccountServiceAccountAssetListUpdatedEvent + | SnapAccountServiceAccountBalancesUpdatedEvent + | SnapAccountServiceAccountTransactionsUpdatedEvent | MultichainNetworkControllerNetworkDidChangeEvent; /** @@ -1279,7 +1284,7 @@ export class AccountsController extends BaseController< ); this.messenger.subscribe( - 'SnapKeyring:accountAssetListUpdated', + 'SnapAccountService:accountAssetListUpdated', (snapAccountEvent) => this.#handleOnSnapKeyringAccountEvent( 'AccountsController:accountAssetListUpdated', @@ -1288,7 +1293,7 @@ export class AccountsController extends BaseController< ); this.messenger.subscribe( - 'SnapKeyring:accountBalancesUpdated', + 'SnapAccountService:accountBalancesUpdated', (snapAccountEvent) => this.#handleOnSnapKeyringAccountEvent( 'AccountsController:accountBalancesUpdated', @@ -1297,7 +1302,7 @@ export class AccountsController extends BaseController< ); this.messenger.subscribe( - 'SnapKeyring:accountTransactionsUpdated', + 'SnapAccountService:accountTransactionsUpdated', (snapAccountEvent) => this.#handleOnSnapKeyringAccountEvent( 'AccountsController:accountTransactionsUpdated', diff --git a/packages/accounts-controller/src/types.ts b/packages/accounts-controller/src/types.ts index 1ee9421ec4..85678bb26e 100644 --- a/packages/accounts-controller/src/types.ts +++ b/packages/accounts-controller/src/types.ts @@ -1,6 +1,11 @@ // This file contains duplicate code from MultichainNetworkController.ts to avoid circular dependencies // It should be refactored to avoid duplication +import { + SnapKeyringAccountAssetListUpdatedEvent, + SnapKeyringAccountBalancesUpdatedEvent, + SnapKeyringAccountTransactionsUpdatedEvent, +} from '@metamask/eth-snap-keyring'; import type { CaipChainId } from '@metamask/keyring-api'; import type { NetworkClientId } from '@metamask/network-controller'; @@ -8,3 +13,18 @@ export type MultichainNetworkControllerNetworkDidChangeEvent = { type: `MultichainNetworkController:networkDidChange`; payload: [NetworkClientId | CaipChainId]; }; + +export type SnapAccountServiceAccountBalancesUpdatedEvent = { + type: `SnapAccountService:accountBalancesUpdated`; + payload: SnapKeyringAccountBalancesUpdatedEvent['payload']; +}; + +export type SnapAccountServiceAccountTransactionsUpdatedEvent = { + type: `SnapAccountService:accountTransactionsUpdated`; + payload: SnapKeyringAccountTransactionsUpdatedEvent['payload']; +}; + +export type SnapAccountServiceAccountAssetListUpdatedEvent = { + type: `SnapAccountService:accountAssetListUpdated`; + payload: SnapKeyringAccountAssetListUpdatedEvent['payload']; +};