diff --git a/packages/assets-controllers/src/TokenListController.test.ts b/packages/assets-controllers/src/TokenListController.test.ts index ca7c556d1f7..02a30c67d3a 100644 --- a/packages/assets-controllers/src/TokenListController.test.ts +++ b/packages/assets-controllers/src/TokenListController.test.ts @@ -1295,13 +1295,13 @@ describe('TokenListController', () => { }); describe('executePoll', () => { - it('should call fetchTokenList with the correct chainId', async () => { + it('should call token service fetchTokenList function with the correct chainId', async () => { nock(tokenService.TOKEN_END_POINT_API) .get(`/tokens/${convertHexToDecimal(ChainId.sepolia)}`) .reply(200, sampleSepoliaTokenList) .persist(); - const spy = jest.spyOn(tokenService, 'fetchTokenList'); + const spy = jest.spyOn(tokenService, 'fetchTokenListByChainId'); const controllerMessenger = getControllerMessenger(); controllerMessenger.registerActionHandler( 'NetworkController:getNetworkClientById', @@ -1337,7 +1337,7 @@ describe('TokenListController', () => { it('should start polling against the token list API at the interval passed to the constructor', async () => { jest.useFakeTimers(); const pollingIntervalTime = 1000; - const spy = jest.spyOn(tokenService, 'fetchTokenList'); + const spy = jest.spyOn(tokenService, 'fetchTokenListByChainId'); const controllerMessenger = getControllerMessenger(); controllerMessenger.registerActionHandler( @@ -1387,7 +1387,7 @@ describe('TokenListController', () => { }; const fetchTokenListSpy = jest - .spyOn(tokenService, 'fetchTokenList') + .spyOn(tokenService, 'fetchTokenListByChainId') .mockImplementation(async (chainId) => { switch (chainId) { case ChainId.sepolia: diff --git a/packages/assets-controllers/src/TokenListController.ts b/packages/assets-controllers/src/TokenListController.ts index 66b3a38e6b7..da31c728fd6 100644 --- a/packages/assets-controllers/src/TokenListController.ts +++ b/packages/assets-controllers/src/TokenListController.ts @@ -16,7 +16,7 @@ import { formatAggregatorNames, formatIconUrlWithProxy, } from './assetsUtil'; -import { fetchTokenList } from './token-service'; +import { fetchTokenListByChainId } from './token-service'; const DEFAULT_INTERVAL = 24 * 60 * 60 * 1000; const DEFAULT_THRESHOLD = 24 * 60 * 60 * 1000; @@ -271,7 +271,7 @@ export class TokenListController extends PollingController< } else { // Fetch fresh token list const tokensFromAPI: TokenListToken[] = await safelyExecute(() => { - return fetchTokenList(chainId, this.abortController.signal); + return fetchTokenListByChainId(chainId, this.abortController.signal); }); if (!tokensFromAPI) { // Fallback to expired cached tokens diff --git a/packages/assets-controllers/src/token-service.test.ts b/packages/assets-controllers/src/token-service.test.ts index 7e168dd6cc6..1420d107874 100644 --- a/packages/assets-controllers/src/token-service.test.ts +++ b/packages/assets-controllers/src/token-service.test.ts @@ -2,7 +2,7 @@ import { toHex } from '@metamask/controller-utils'; import nock from 'nock'; import { - fetchTokenList, + fetchTokenListByChainId, fetchTokenMetadata, TOKEN_END_POINT_API, TOKEN_METADATA_NO_SUPPORT_ERROR, @@ -137,7 +137,7 @@ const sampleDecimalChainId = 1; const sampleChainId = toHex(sampleDecimalChainId); describe('Token service', () => { - describe('fetchTokenList', () => { + describe('fetchTokenListByChainId', () => { it('should call the tokens api and return the list of tokens', async () => { const { signal } = new AbortController(); nock(TOKEN_END_POINT_API) @@ -145,7 +145,7 @@ describe('Token service', () => { .reply(200, sampleTokenList) .persist(); - const tokens = await fetchTokenList(sampleChainId, signal); + const tokens = await fetchTokenListByChainId(sampleChainId, signal); expect(tokens).toStrictEqual(sampleTokenList); }); @@ -159,7 +159,7 @@ describe('Token service', () => { .reply(200, sampleTokenList) .persist(); - const fetchPromise = fetchTokenList( + const fetchPromise = fetchTokenListByChainId( sampleChainId, abortController.signal, ); @@ -175,7 +175,7 @@ describe('Token service', () => { .replyWithError('Example network error') .persist(); - const result = await fetchTokenList(sampleChainId, signal); + const result = await fetchTokenListByChainId(sampleChainId, signal); expect(result).toBeUndefined(); }); @@ -187,7 +187,7 @@ describe('Token service', () => { .reply(500) .persist(); - const result = await fetchTokenList(sampleChainId, signal); + const result = await fetchTokenListByChainId(sampleChainId, signal); expect(result).toBeUndefined(); }); @@ -201,7 +201,7 @@ describe('Token service', () => { .reply(200, sampleTokenList) .persist(); - const result = await fetchTokenList(sampleChainId, signal, { + const result = await fetchTokenListByChainId(sampleChainId, signal, { timeout: ONE_MILLISECOND, }); @@ -317,7 +317,7 @@ describe('Token service', () => { .reply(404, undefined) .persist(); - const tokens = await fetchTokenList(sampleChainId, signal); + const tokens = await fetchTokenListByChainId(sampleChainId, signal); expect(tokens).toBeUndefined(); }); diff --git a/packages/assets-controllers/src/token-service.ts b/packages/assets-controllers/src/token-service.ts index 614753acfa6..e0654597416 100644 --- a/packages/assets-controllers/src/token-service.ts +++ b/packages/assets-controllers/src/token-service.ts @@ -46,7 +46,7 @@ const defaultTimeout = tenSecondsInMilliseconds; * @param options.timeout - The fetch timeout. * @returns The token list, or `undefined` if the request was cancelled. */ -export async function fetchTokenList( +export async function fetchTokenListByChainId( chainId: Hex, abortSignal: AbortSignal, { timeout = defaultTimeout } = {},