Fix wrong token handling (#4254)
* Fixing wrong token displayed * Linting * Revert filtering out * Revert the revert
This commit is contained in:
parent
6c5167ebb3
commit
8edaab806e
@ -96,7 +96,7 @@ class TokenSelect extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
key={ token.tag }
|
key={ `${index}_${token.tag}` }
|
||||||
value={ token.tag }
|
value={ token.tag }
|
||||||
label={ label }
|
label={ label }
|
||||||
>
|
>
|
||||||
|
@ -31,7 +31,8 @@ const log = getLogger(LOG_KEYS.Balances);
|
|||||||
const ETH = {
|
const ETH = {
|
||||||
name: 'Ethereum',
|
name: 'Ethereum',
|
||||||
tag: 'ETH',
|
tag: 'ETH',
|
||||||
image: imagesEthereum
|
image: imagesEthereum,
|
||||||
|
native: true
|
||||||
};
|
};
|
||||||
|
|
||||||
function setBalances (_balances, skipNotifications = false) {
|
function setBalances (_balances, skipNotifications = false) {
|
||||||
@ -39,10 +40,9 @@ function setBalances (_balances, skipNotifications = false) {
|
|||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
const currentTokens = Object.values(state.balances.tokens || {});
|
const currentTokens = Object.values(state.balances.tokens || {});
|
||||||
const currentTags = [ 'eth' ]
|
const tokensAddresses = currentTokens
|
||||||
.concat(currentTokens.map((token) => token.tag))
|
.map((token) => token.address)
|
||||||
.filter((tag) => tag)
|
.filter((address) => address);
|
||||||
.map((tag) => tag.toLowerCase());
|
|
||||||
|
|
||||||
const accounts = state.personal.accounts;
|
const accounts = state.personal.accounts;
|
||||||
const nextBalances = _balances;
|
const nextBalances = _balances;
|
||||||
@ -61,53 +61,59 @@ function setBalances (_balances, skipNotifications = false) {
|
|||||||
const prevTokens = balance.tokens.slice();
|
const prevTokens = balance.tokens.slice();
|
||||||
const nextTokens = [];
|
const nextTokens = [];
|
||||||
|
|
||||||
currentTags
|
const handleToken = (prevToken, nextToken) => {
|
||||||
.forEach((tag) => {
|
// If the given token is not in the current tokens, skip
|
||||||
const prevToken = prevTokens.find((tok) => tok.token.tag.toLowerCase() === tag);
|
if (!nextToken && !prevToken) {
|
||||||
const nextToken = tokens.find((tok) => tok.token.tag.toLowerCase() === tag);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// If the given token is not in the current tokens, skip
|
// No updates
|
||||||
if (!nextToken && !prevToken) {
|
if (!nextToken) {
|
||||||
return false;
|
return nextTokens.push(prevToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No updates
|
const { token, value } = nextToken;
|
||||||
if (!nextToken) {
|
|
||||||
return nextTokens.push(prevToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { token, value } = nextToken;
|
|
||||||
|
|
||||||
// If it's a new token, push it
|
|
||||||
if (!prevToken) {
|
|
||||||
return nextTokens.push({
|
|
||||||
token, value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, update the value
|
|
||||||
const prevValue = prevToken.value;
|
|
||||||
|
|
||||||
// FIXME: Temporary hack to not continuously pop-up notifications until fixed
|
|
||||||
const FIXME_SKIP = false;
|
|
||||||
|
|
||||||
// If received a token/eth (old value < new value), notify
|
|
||||||
if (FIXME_SKIP && prevValue.lt(value) && accounts[address] && !skipNotifications) {
|
|
||||||
const account = accounts[address];
|
|
||||||
const txValue = value.minus(prevValue);
|
|
||||||
|
|
||||||
const redirectToAccount = () => {
|
|
||||||
const route = `/accounts/${account.address}`;
|
|
||||||
dispatch(push(route));
|
|
||||||
};
|
|
||||||
|
|
||||||
notifyTransaction(account, token, txValue, redirectToAccount);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// If it's a new token, push it
|
||||||
|
if (!prevToken) {
|
||||||
return nextTokens.push({
|
return nextTokens.push({
|
||||||
...prevToken,
|
token, value
|
||||||
value
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, update the value
|
||||||
|
const prevValue = prevToken.value;
|
||||||
|
|
||||||
|
// If received a token/eth (old value < new value), notify
|
||||||
|
if (prevValue.lt(value) && accounts[address] && !skipNotifications) {
|
||||||
|
const account = accounts[address];
|
||||||
|
const txValue = value.minus(prevValue);
|
||||||
|
|
||||||
|
const redirectToAccount = () => {
|
||||||
|
const route = `/accounts/${account.address}`;
|
||||||
|
dispatch(push(route));
|
||||||
|
};
|
||||||
|
|
||||||
|
notifyTransaction(account, token, txValue, redirectToAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nextTokens.push({
|
||||||
|
...prevToken,
|
||||||
|
value
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const prevEthToken = prevTokens.find((tok) => tok.token.native);
|
||||||
|
const nextEthToken = tokens.find((tok) => tok.token.native);
|
||||||
|
|
||||||
|
handleToken(prevEthToken, nextEthToken);
|
||||||
|
|
||||||
|
tokensAddresses
|
||||||
|
.forEach((address) => {
|
||||||
|
const prevToken = prevTokens.find((tok) => tok.token.address === address);
|
||||||
|
const nextToken = tokens.find((tok) => tok.token.address === address);
|
||||||
|
|
||||||
|
handleToken(prevToken, nextToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
balances[address] = { txCount: txCount || new BigNumber(0), tokens: nextTokens };
|
balances[address] = { txCount: txCount || new BigNumber(0), tokens: nextTokens };
|
||||||
@ -179,6 +185,8 @@ export function fetchTokens (_tokenIds, options = {}) {
|
|||||||
|
|
||||||
return Promise
|
return Promise
|
||||||
.all(tokenIds.map((id) => fetchTokenInfo(tokenreg, id, api)))
|
.all(tokenIds.map((id) => fetchTokenInfo(tokenreg, id, api)))
|
||||||
|
// FIXME ; shouldn't have to filter out tokens...
|
||||||
|
.then((tokens) => tokens.filter((token) => token.tag && token.tag.toLowerCase() !== 'eth'))
|
||||||
.then((tokens) => {
|
.then((tokens) => {
|
||||||
// dispatch only the changed images
|
// dispatch only the changed images
|
||||||
tokens
|
tokens
|
||||||
|
@ -41,7 +41,7 @@ class Balance extends Component {
|
|||||||
|
|
||||||
let body = (balance.tokens || [])
|
let body = (balance.tokens || [])
|
||||||
.filter((balance) => new BigNumber(balance.value).gt(0))
|
.filter((balance) => new BigNumber(balance.value).gt(0))
|
||||||
.map((balance) => {
|
.map((balance, index) => {
|
||||||
const token = balance.token;
|
const token = balance.token;
|
||||||
|
|
||||||
let value;
|
let value;
|
||||||
@ -76,7 +76,7 @@ class Balance extends Component {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={ styles.balance }
|
className={ styles.balance }
|
||||||
key={ token.tag }
|
key={ `${index}_${token.tag}` }
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={ imagesrc }
|
src={ imagesrc }
|
||||||
|
Loading…
Reference in New Issue
Block a user