Skip to content

Commit 6e9c8d1

Browse files
committed
Merge branch 'main' into switch-to-codefi-price-api
2 parents 1302cc3 + 646c734 commit 6e9c8d1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/assets-controllers/src/TokenRatesController.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,33 @@ describe('TokenRatesController', () => {
10391039
expect(controller.state.contractExchangeRatesByChainId).toStrictEqual({});
10401040
});
10411041

1042+
it('should not update state when disabled', async () => {
1043+
const tokenAddress = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359';
1044+
const controller = new TokenRatesController(
1045+
{
1046+
interval: 100,
1047+
chainId: '0x2',
1048+
ticker: 'ticker',
1049+
selectedAddress: '0xdeadbeef',
1050+
onPreferencesStateChange: jest.fn(),
1051+
onTokensStateChange: jest.fn(),
1052+
onNetworkStateChange: jest.fn(),
1053+
getNetworkClientById: jest.fn(),
1054+
tokenPricesService: buildMockTokenPricesService(),
1055+
},
1056+
{ disabled: true },
1057+
);
1058+
expect(controller.state.contractExchangeRatesByChainId).toStrictEqual({});
1059+
1060+
await controller.updateExchangeRatesByChainId({
1061+
chainId: '0x1',
1062+
nativeCurrency: 'ETH',
1063+
tokenContractAddresses: [tokenAddress],
1064+
});
1065+
1066+
expect(controller.state.contractExchangeRatesByChainId).toStrictEqual({});
1067+
});
1068+
10421069
it('should update exchange rates when native currency is supported by the Price API', async () => {
10431070
const tokenPricesService = buildMockTokenPricesService({
10441071
fetchTokenPrices: fetchTokenPricesWithIncreasingPriceForEachToken,

packages/assets-controllers/src/TokenRatesController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export class TokenRatesController extends PollingControllerV1<
387387
nativeCurrency: string;
388388
tokenContractAddresses: Hex[];
389389
}) {
390-
if (!tokenContractAddresses.length) {
390+
if (tokenContractAddresses.length === 0 || this.disabled) {
391391
return;
392392
}
393393
const newContractExchangeRates = await this.fetchAndMapExchangeRates({

0 commit comments

Comments
 (0)