MyCrypto/common/utils/tokens.ts

19 lines
545 B
TypeScript
Raw Normal View History

2018-01-30 01:41:59 +00:00
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];
});
}