Skip to content

Commit

Permalink
chore: rely in MultichainAssetsController for the accountAdded event
Browse files Browse the repository at this point in the history
  • Loading branch information
zone-live committed Feb 7, 2025
1 parent 1adbaff commit 3f5b7fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,6 @@ describe('BalancesController', () => {
);
});

it('updates balances when "AccountsController:accountAdded" is fired', async () => {
const { controller, messenger, mockListMultichainAccounts } =
setupController({
mocks: {
listMultichainAccounts: [],
},
});

mockListMultichainAccounts.mockReturnValue([mockBtcAccount]);
messenger.publish('AccountsController:accountAdded', mockBtcAccount);

await waitForAllPromises();

expect(controller.state).toStrictEqual({
balances: {
[mockBtcAccount.id]: mockBalanceResult,
},
});
});

it('updates balances when "AccountsController:accountRemoved" is fired', async () => {
const { controller, messenger } = setupController();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ export class MultichainBalancesController extends BaseController<
});
}

this.messagingSystem.subscribe(
'AccountsController:accountAdded',
(account: InternalAccount) => this.#handleOnAccountAdded(account),
);
this.messagingSystem.subscribe(
'AccountsController:accountRemoved',
(account: string) => this.#handleOnAccountRemoved(account),
Expand All @@ -179,6 +175,9 @@ export class MultichainBalancesController extends BaseController<
(balanceUpdate: AccountBalancesUpdatedEventPayload) =>
this.#handleOnAccountBalancesUpdated(balanceUpdate),
);
// TODO: Maybe add a MultichainAssetsController:accountAssetListUpdated event instead of using the entire state.
// Since MultichainAssetsController already listens for the AccountsController:accountAdded, we can rely in it for that event
// and not listen for it also here, in this controller, since it would be redundant
this.messagingSystem.subscribe(
'MultichainAssetsController:stateChange',
async (assetsState: MultichainAssetsControllerState) => {
Expand Down Expand Up @@ -285,19 +284,6 @@ export class MultichainBalancesController extends BaseController<
);
}

/**
* Handles changes when a new account has been added.
*
* @param account - The new account being added.
*/
async #handleOnAccountAdded(account: InternalAccount): Promise<void> {
if (!this.#isNonEvmAccount(account)) {
return;
}

await this.updateBalance(account.id);
}

/**
* Handles balance updates received from the AccountsController.
*
Expand Down

0 comments on commit 3f5b7fc

Please sign in to comment.