Store tokens with repeatable id (#7435)

This commit is contained in:
Jaco Greeff 2018-01-03 15:25:45 +01:00 committed by GitHub
parent 51319ebe3f
commit 7c1cbd33ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 11 deletions

View File

@ -23,7 +23,7 @@ import { fetchTokenIds, fetchTokensBasics, fetchTokensInfo, fetchTokensImages }
import { setAddressImage } from './imagesActions'; 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); const log = getLogger(LOG_KEYS.Balances);
function _setTokens (tokens) { function _setTokens (tokens) {

View File

@ -59,22 +59,18 @@ export function fetchTokensBasics (api, tokenReg, start = 0, limit = 100) {
}) })
.then((tokenAddresses) => { .then((tokenAddresses) => {
return tokenAddresses.map((tokenAddress, index) => { return tokenAddresses.map((tokenAddress, index) => {
if (/^0x0*$/.test(tokenAddress)) {
return null;
}
const tokenIndex = start + index; const tokenIndex = start + index;
return { return {
address: tokenAddress, address: /^0x0*$/.test(tokenAddress)
id: getTokenId(tokenAddress, tokenIndex), ? ''
: tokenAddress,
id: getTokenId(tokenIndex),
index: tokenIndex, index: tokenIndex,
fetched: false fetched: false
}; };
}); });
}) })
.then((tokens) => tokens.filter((token) => token))
.then((tokens) => { .then((tokens) => {
const randomAddress = sha3(`${Date.now()}`).substr(0, 42); const randomAddress = sha3(`${Date.now()}`).substr(0, 42);
@ -82,7 +78,13 @@ export function fetchTokensBasics (api, tokenReg, start = 0, limit = 100) {
.then((_balances) => { .then((_balances) => {
const balances = _balances[randomAddress]; 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;
});
}); });
}); });
} }
@ -113,7 +115,7 @@ export function fetchTokensInfo (api, tokenReg, tokenIndexes) {
const token = { const token = {
address, address,
id: getTokenId(address, tokenIndex), id: getTokenId(tokenIndex),
index: tokenIndex, index: tokenIndex,
format: format.toString(), format: format.toString(),