Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ describe('MultichainAssetsRatesController', () => {
expect(snapHandler).not.toHaveBeenCalled();
});

it('does not update conversion rates if the assets are empty', async () => {
const { controller, messenger } = setupController();

const snapSpy = jest.fn().mockResolvedValue({ conversionRates: {} });
messenger.registerActionHandler('SnapController:handleRequest', snapSpy);

// Publish a selectedAccountChange event.
// @ts-expect-error-next-line
messenger.publish('MultichainAssetsController:stateChange', {
accountsAssets: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (happy to ignore since this is a test).
Could we satisfy the type by using the defaultState from the controller? Or is the types quite complex?

const mockNewState = { ...defaultState }
mockNewState.accountAssets = { account: [] }
messenger.publish('MultichainAssetsController:stateChange', mockNewState)

account3: [],
},
});

expect(snapSpy).not.toHaveBeenCalled();
expect(controller.state.conversionRates).toStrictEqual({});
});

it('resumes update tokens rates when the keyring is unlocked', async () => {
const { controller, messenger } = setupController();
messenger.publish('KeyringController:lock');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ export class MultichainAssetsRatesController extends StaticIntervalPollingContro
for (const account of accounts) {
const assets = this.#getAssetsForAccount(account.id);

if (assets?.length === 0) {
continue;
}

// Build the conversions array
const conversions = this.#buildConversions(assets);

Expand Down
Loading