aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/blockchain.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-30 18:16:13 +0800
committerFabio Berger <me@fabioberger.com>2018-01-30 18:16:13 +0800
commit86cc011212088801a778d947ae925cc0b1ddadf8 (patch)
tree9c12a4dc945d3dd23416d4ea1ccde438c9ed687e /packages/website/ts/blockchain.ts
parentc0facfc28f65495a52f9405613fe4a08aff5d164 (diff)
downloaddexon-sol-tools-86cc011212088801a778d947ae925cc0b1ddadf8.tar
dexon-sol-tools-86cc011212088801a778d947ae925cc0b1ddadf8.tar.gz
dexon-sol-tools-86cc011212088801a778d947ae925cc0b1ddadf8.tar.bz2
dexon-sol-tools-86cc011212088801a778d947ae925cc0b1ddadf8.tar.lz
dexon-sol-tools-86cc011212088801a778d947ae925cc0b1ddadf8.tar.xz
dexon-sol-tools-86cc011212088801a778d947ae925cc0b1ddadf8.tar.zst
dexon-sol-tools-86cc011212088801a778d947ae925cc0b1ddadf8.zip
Wholesale replace the tokenByAddress and de-dup properly
Diffstat (limited to 'packages/website/ts/blockchain.ts')
-rw-r--r--packages/website/ts/blockchain.ts24
1 files changed, 14 insertions, 10 deletions
diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts
index aba438e8d..d310464ed 100644
--- a/packages/website/ts/blockchain.ts
+++ b/packages/website/ts/blockchain.ts
@@ -512,26 +512,30 @@ export class Blockchain {
const tokenRegistryTokensByAddress = await this._getTokenRegistryTokensByAddressAsync();
- let trackedTokensIfExists = trackedTokenStorage.getTrackedTokensIfExists(this._userAddress, this.networkId);
+ const trackedTokensByAddress = trackedTokenStorage.getTrackedTokensByAddress(this._userAddress, this.networkId);
const tokenRegistryTokens = _.values(tokenRegistryTokensByAddress);
- if (_.isUndefined(trackedTokensIfExists)) {
- trackedTokensIfExists = _.map(configs.DEFAULT_TRACKED_TOKEN_SYMBOLS, symbol => {
+ if (_.isEmpty(trackedTokensByAddress)) {
+ _.each(configs.DEFAULT_TRACKED_TOKEN_SYMBOLS, symbol => {
const token = _.find(tokenRegistryTokens, t => t.symbol === symbol);
token.isTracked = true;
- return token;
+ trackedTokensByAddress[token.address] = token;
});
- _.each(trackedTokensIfExists, token => {
+ _.each(trackedTokensByAddress, (token: Token, address: string) => {
trackedTokenStorage.addTrackedTokenToUser(this._userAddress, this.networkId, token);
});
} else {
// Properly set all tokenRegistry tokens `isTracked` to true if they are in the existing trackedTokens array
- _.each(trackedTokensIfExists, trackedToken => {
- if (!_.isUndefined(tokenRegistryTokensByAddress[trackedToken.address])) {
- tokenRegistryTokensByAddress[trackedToken.address].isTracked = true;
+ _.each(trackedTokensByAddress, (trackedToken: Token, address: string) => {
+ if (!_.isUndefined(tokenRegistryTokensByAddress[address])) {
+ tokenRegistryTokensByAddress[address].isTracked = true;
}
});
}
- const allTokens = _.uniq([...tokenRegistryTokens, ...trackedTokensIfExists]);
+ const allTokensByAddress = {
+ ...tokenRegistryTokensByAddress,
+ ...trackedTokensByAddress,
+ };
+ const allTokens = _.values(allTokensByAddress);
const mostPopularTradingPairTokens: Token[] = [
_.find(allTokens, { symbol: configs.DEFAULT_TRACKED_TOKEN_SYMBOLS[0] }),
_.find(allTokens, { symbol: configs.DEFAULT_TRACKED_TOKEN_SYMBOLS[1] }),
@@ -544,7 +548,7 @@ export class Blockchain {
address: mostPopularTradingPairTokens[1].address,
},
};
- this._dispatcher.batchDispatch(allTokens, this.networkId, this._userAddress, sideToAssetToken);
+ this._dispatcher.batchDispatch(allTokensByAddress, this.networkId, this._userAddress, sideToAssetToken);
this._dispatcher.updateBlockchainIsLoaded(true);
}