Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not call the snap to get rates if assets are empty #5370

Merged
merged 3 commits into from
Feb 21, 2025
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