Skip to content

Commit

Permalink
[Token Detection V2] Refining the polling interval and the occurrence…
Browse files Browse the repository at this point in the history
…s limit for the Dynamic token list (#836)
  • Loading branch information
NiranjanaBinoy authored May 19, 2022
1 parent 6dd147a commit db34740
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 59 deletions.
68 changes: 13 additions & 55 deletions src/assets/TokenListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const sampleWithDuplicateSymbolsTokensChainsCache =
return output;
}, {} as TokenListMap);

const sampleWithLessThan2Occurences = [
const sampleWithLessThan3OccurencesResponse = [
{
address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
symbol: 'SNX',
Expand Down Expand Up @@ -170,9 +170,11 @@ const sampleWithLessThan2Occurences = [
},
];

const sampleWithLessThan2OccurencesTokensChainsCache =
sampleWithLessThan2Occurences.reduce((output, current) => {
output[current.address] = current;
const sampleWith3OrMoreOccurrences =
sampleWithLessThan3OccurencesResponse.reduce((output, token) => {
if (token.occurrences >= 3) {
output[token.address] = token;
}
return output;
}, {} as TokenListMap);

Expand Down Expand Up @@ -436,7 +438,7 @@ const expiredCacheExistingState: TokenListState = {
},
tokensChainsCache: {
'1': {
timestamp: timestamp - 1800000,
timestamp: timestamp - 86400000,
data: {
'0x514910771af9ca656af840dff83e8264ecf986ca': {
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
Expand Down Expand Up @@ -821,10 +823,10 @@ describe('TokenListController', () => {
controller.destroy();
});

it('should update token list after removing data less than 2 occurrences', async () => {
it('should update token list after removing data less than 3 occurrences', async () => {
nock(TOKEN_END_POINT_API)
.get(`/tokens/${NetworksChainId.mainnet}`)
.reply(200, sampleWithLessThan2Occurences)
.reply(200, sampleWithLessThan3OccurencesResponse)
.persist();
const messenger = getRestrictedMessenger();
const controller = new TokenListController({
Expand All @@ -833,57 +835,13 @@ describe('TokenListController', () => {
messenger,
});
await controller.start();
expect(controller.state.tokenList).toStrictEqual({
'0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f': {
address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
symbol: 'SNX',
decimals: 18,
occurrences: 2,
name: 'Synthetix',
iconUrl:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/1/0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f.png',
aggregators: [
'Aave',
'Bancor',
'CMC',
'Crypto.com',
'CoinGecko',
'1inch',
'Paraswap',
'PMM',
'Synthetix',
'Zapper',
'Zerion',
'0x',
],
},
'0x514910771af9ca656af840dff83e8264ecf986ca': {
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
symbol: 'LINK',
decimals: 18,
occurrences: 11,
name: 'Chainlink',
iconUrl:
'https://static.metaswap.codefi.network/api/v1/tokenIcons/1/0x514910771af9ca656af840dff83e8264ecf986ca.png',
aggregators: [
'Aave',
'Bancor',
'CMC',
'Crypto.com',
'CoinGecko',
'1inch',
'Paraswap',
'PMM',
'Zapper',
'Zerion',
'0x',
],
},
});
expect(controller.state.tokenList).toStrictEqual(
sampleWith3OrMoreOccurrences,
);

expect(
controller.state.tokensChainsCache[NetworksChainId.mainnet].data,
).toStrictEqual(sampleWithLessThan2OccurencesTokensChainsCache);
).toStrictEqual(sampleWith3OrMoreOccurrences);
controller.destroy();
});

Expand Down
8 changes: 4 additions & 4 deletions src/assets/TokenListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { fetchTokenList } from '../apis/token-service';
import { NetworkState } from '../network/NetworkController';
import { formatAggregatorNames, formatIconUrlWithProxy } from './assetsUtil';

const DEFAULT_INTERVAL = 60 * 60 * 1000;
const DEFAULT_THRESHOLD = 60 * 30 * 1000;
const DEFAULT_INTERVAL = 24 * 60 * 60 * 1000;
const DEFAULT_THRESHOLD = 24 * 60 * 60 * 1000;

const name = 'TokenListController';

Expand Down Expand Up @@ -225,11 +225,11 @@ export class TokenListController extends BaseController<
});
return;
}
// Filtering out tokens with less than 2 occurrences and native tokens
// Filtering out tokens with less than 3 occurrences and native tokens
const filteredTokenList = tokensFromAPI.filter(
(token) =>
token.occurrences &&
token.occurrences >= 2 &&
token.occurrences >= 3 &&
token.address !== '0x0000000000000000000000000000000000000000',
);
// Removing the tokens with symbol conflicts
Expand Down

0 comments on commit db34740

Please sign in to comment.