Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Store tokens with repeatable id (#7435)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Jan 3, 2018
1 parent 51319eb commit 7c1cbd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion js-old/src/redux/providers/tokensActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { fetchTokenIds, fetchTokensBasics, fetchTokensInfo, fetchTokensImages }

import { setAddressImage } from './imagesActions';

const TOKENS_CACHE_LS_KEY_PREFIX = '_parity::tokens::';
const TOKENS_CACHE_LS_KEY_PREFIX = '_parity::tokenreg::';
const log = getLogger(LOG_KEYS.Balances);

function _setTokens (tokens) {
Expand Down
22 changes: 12 additions & 10 deletions js-old/src/util/tokens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,32 @@ export function fetchTokensBasics (api, tokenReg, start = 0, limit = 100) {
})
.then((tokenAddresses) => {
return tokenAddresses.map((tokenAddress, index) => {
if (/^0x0*$/.test(tokenAddress)) {
return null;
}

const tokenIndex = start + index;

return {
address: tokenAddress,
id: getTokenId(tokenAddress, tokenIndex),
address: /^0x0*$/.test(tokenAddress)
? ''
: tokenAddress,
id: getTokenId(tokenIndex),
index: tokenIndex,

fetched: false
};
});
})
.then((tokens) => tokens.filter((token) => token))
.then((tokens) => {
const randomAddress = sha3(`${Date.now()}`).substr(0, 42);

return fetchTokensBalances(api, tokens, [randomAddress])
.then((_balances) => {
const balances = _balances[randomAddress];

return tokens.filter(({ id }) => balances[id].eq(0));
return tokens.map((token) => {
if (balances[token.id] && balances[token.id].gt(0)) {
token.address = '';
}

return token;
});
});
});
}
Expand Down Expand Up @@ -113,7 +115,7 @@ export function fetchTokensInfo (api, tokenReg, tokenIndexes) {

const token = {
address,
id: getTokenId(address, tokenIndex),
id: getTokenId(tokenIndex),
index: tokenIndex,

format: format.toString(),
Expand Down

0 comments on commit 7c1cbd3

Please sign in to comment.