2018-02-12 20:43:07 +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
|
2018-03-07 23:36:05 +00:00
|
|
|
const tokenCollisionMap = networkTokens.reduce<{ [tokenKey: string]: boolean }>((prev, token) => {
|
2018-01-11 06:50:31 +00:00
|
|
|
prev[token.symbol] = true;
|
|
|
|
prev[token.address] = true;
|
|
|
|
return prev;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
return customTokens.filter(token => {
|
|
|
|
return !tokenCollisionMap[token.address] && !tokenCollisionMap[token.symbol];
|
|
|
|
});
|
|
|
|
}
|