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';
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) {

View File

@ -59,22 +59,18 @@ 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);
@ -82,7 +78,13 @@ export function fetchTokensBasics (api, tokenReg, start = 0, limit = 100) {
.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;
});
});
});
}
@ -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(),