2018-01-30 01:41:59 +00:00
|
|
|
import { Token } from 'types/network';
|
2018-01-11 06:50:31 +00:00
|
|
|
|
|
|
|
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];
|
|
|
|
});
|
|
|
|
}
|