Skip to content

Commit

Permalink
rename fetchTokenList helper function to fetchTokenListByChainId
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Oct 6, 2023
1 parent e10b445 commit 73ff166
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/assets-controllers/src/TokenListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1387,7 +1387,7 @@ describe('TokenListController', () => {
};

const fetchTokenListSpy = jest
.spyOn(tokenService, 'fetchTokenList')
.spyOn(tokenService, 'fetchTokenListByChainId')
.mockImplementation(async (chainId) => {
switch (chainId) {
case ChainId.sepolia:
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/TokenListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions packages/assets-controllers/src/token-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -137,15 +137,15 @@ 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)
.get(`/tokens/${sampleDecimalChainId}`)
.reply(200, sampleTokenList)
.persist();

const tokens = await fetchTokenList(sampleChainId, signal);
const tokens = await fetchTokenListByChainId(sampleChainId, signal);

expect(tokens).toStrictEqual(sampleTokenList);
});
Expand All @@ -159,7 +159,7 @@ describe('Token service', () => {
.reply(200, sampleTokenList)
.persist();

const fetchPromise = fetchTokenList(
const fetchPromise = fetchTokenListByChainId(
sampleChainId,
abortController.signal,
);
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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,
});

Expand Down Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/token-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {},
Expand Down

0 comments on commit 73ff166

Please sign in to comment.