MyCrypto/common/utils/tokens.ts

19 lines
545 B
TypeScript
Raw Normal View History

import { Token } from 'types/network';
export function dedupeCustomTokens(networkTokens: Token[], customTokens: Token[]): Token[] {
if (!customTokens.length) {
return [];
}
// If any tokens have the same symbol or contract address, remove them
const tokenCollisionMap = networkTokens.reduce((prev, token) => {
prev[token.symbol] = true;
prev[token.address] = true;
return prev;
}, {});
return customTokens.filter(token => {
return !tokenCollisionMap[token.address] && !tokenCollisionMap[token.symbol];
});
}