Skip to content

Commit

Permalink
Merge branch 'main' into switch-to-codefi-price-api
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Dec 1, 2023
2 parents 1302cc3 + 646c734 commit 6e9c8d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/assets-controllers/src/TokenRatesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,33 @@ describe('TokenRatesController', () => {
expect(controller.state.contractExchangeRatesByChainId).toStrictEqual({});
});

it('should not update state when disabled', async () => {
const tokenAddress = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359';
const controller = new TokenRatesController(
{
interval: 100,
chainId: '0x2',
ticker: 'ticker',
selectedAddress: '0xdeadbeef',
onPreferencesStateChange: jest.fn(),
onTokensStateChange: jest.fn(),
onNetworkStateChange: jest.fn(),
getNetworkClientById: jest.fn(),
tokenPricesService: buildMockTokenPricesService(),
},
{ disabled: true },
);
expect(controller.state.contractExchangeRatesByChainId).toStrictEqual({});

await controller.updateExchangeRatesByChainId({
chainId: '0x1',
nativeCurrency: 'ETH',
tokenContractAddresses: [tokenAddress],
});

expect(controller.state.contractExchangeRatesByChainId).toStrictEqual({});
});

it('should update exchange rates when native currency is supported by the Price API', async () => {
const tokenPricesService = buildMockTokenPricesService({
fetchTokenPrices: fetchTokenPricesWithIncreasingPriceForEachToken,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class TokenRatesController extends PollingControllerV1<
nativeCurrency: string;
tokenContractAddresses: Hex[];
}) {
if (!tokenContractAddresses.length) {
if (tokenContractAddresses.length === 0 || this.disabled) {
return;
}
const newContractExchangeRates = await this.fetchAndMapExchangeRates({
Expand Down

0 comments on commit 6e9c8d1

Please sign in to comment.