From 6320efbbdffc99fa35869df26def2da8ca1ecbea Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Fri, 20 Jan 2017 17:27:46 +0000 Subject: [PATCH 1/4] Fixing wrong token displayed --- js/src/modals/Transfer/Details/details.js | 2 +- js/src/redux/providers/balancesActions.js | 93 +++++++++++++---------- js/src/ui/Balance/balance.js | 4 +- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/js/src/modals/Transfer/Details/details.js b/js/src/modals/Transfer/Details/details.js index c2e062a2200..0ff55b9dd91 100644 --- a/js/src/modals/Transfer/Details/details.js +++ b/js/src/modals/Transfer/Details/details.js @@ -96,7 +96,7 @@ class TokenSelect extends Component { return ( diff --git a/js/src/redux/providers/balancesActions.js b/js/src/redux/providers/balancesActions.js index 2f7acf82e53..54240fa0bac 100644 --- a/js/src/redux/providers/balancesActions.js +++ b/js/src/redux/providers/balancesActions.js @@ -31,7 +31,8 @@ const log = getLogger(LOG_KEYS.Balances); const ETH = { name: 'Ethereum', tag: 'ETH', - image: imagesEthereum + image: imagesEthereum, + native: true }; function setBalances (_balances, skipNotifications = false) { @@ -39,10 +40,9 @@ function setBalances (_balances, skipNotifications = false) { const state = getState(); const currentTokens = Object.values(state.balances.tokens || {}); - const currentTags = [ 'eth' ] - .concat(currentTokens.map((token) => token.tag)) - .filter((tag) => tag) - .map((tag) => tag.toLowerCase()); + const tokensAddresses = currentTokens + .map((token) => token.address) + .filter((address) => address); const accounts = state.personal.accounts; const nextBalances = _balances; @@ -61,53 +61,59 @@ function setBalances (_balances, skipNotifications = false) { const prevTokens = balance.tokens.slice(); const nextTokens = []; - currentTags - .forEach((tag) => { - const prevToken = prevTokens.find((tok) => tok.token.tag.toLowerCase() === tag); - const nextToken = tokens.find((tok) => tok.token.tag.toLowerCase() === tag); + const handleToken = (prevToken, nextToken) => { + // If the given token is not in the current tokens, skip + if (!nextToken && !prevToken) { + return false; + } + + // No updates + if (!nextToken) { + return nextTokens.push(prevToken); + } + + const { token, value } = nextToken; - // If the given token is not in the current tokens, skip - if (!nextToken && !prevToken) { - return false; - } + // If it's a new token, push it + if (!prevToken) { + return nextTokens.push({ + token, value + }); + } - // No updates - if (!nextToken) { - return nextTokens.push(prevToken); - } + // Otherwise, update the value + const prevValue = prevToken.value; - const { token, value } = nextToken; + // 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); - // If it's a new token, push it - if (!prevToken) { - return nextTokens.push({ - token, value - }); - } + const redirectToAccount = () => { + const route = `/accounts/${account.address}`; + dispatch(push(route)); + }; - // Otherwise, update the value - const prevValue = prevToken.value; + notifyTransaction(account, token, txValue, redirectToAccount); + } - // FIXME: Temporary hack to not continuously pop-up notifications until fixed - const FIXME_SKIP = false; + return nextTokens.push({ + ...prevToken, + value + }); + }; - // 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 prevEthToken = prevTokens.find((tok) => tok.token.native); + const nextEthToken = tokens.find((tok) => tok.token.native); - const redirectToAccount = () => { - const route = `/accounts/${account.address}`; - dispatch(push(route)); - }; + handleToken(prevEthToken, nextEthToken); - notifyTransaction(account, token, txValue, redirectToAccount); - } + tokensAddresses + .forEach((address) => { + const prevToken = prevTokens.find((tok) => tok.token.address === address); + const nextToken = tokens.find((tok) => tok.token.address === address); - return nextTokens.push({ - ...prevToken, - value - }); + handleToken(prevToken, nextToken); }); balances[address] = { txCount: txCount || new BigNumber(0), tokens: nextTokens }; @@ -179,6 +185,9 @@ export function fetchTokens (_tokenIds, options = {}) { return Promise .all(tokenIds.map((id) => fetchTokenInfo(tokenreg, id, api))) + .then((tokens) => { + return token.filter((token) => token.tag && token.tag.toLowerCase() !== 'eth'); + }) .then((tokens) => { // dispatch only the changed images tokens diff --git a/js/src/ui/Balance/balance.js b/js/src/ui/Balance/balance.js index 00c03b46c6d..c1a1fad7cac 100644 --- a/js/src/ui/Balance/balance.js +++ b/js/src/ui/Balance/balance.js @@ -41,7 +41,7 @@ class Balance extends Component { let body = (balance.tokens || []) .filter((balance) => new BigNumber(balance.value).gt(0)) - .map((balance) => { + .map((balance, index) => { const token = balance.token; let value; @@ -76,7 +76,7 @@ class Balance extends Component { return (
Date: Fri, 20 Jan 2017 17:28:11 +0000 Subject: [PATCH 2/4] Linting --- js/src/redux/providers/balancesActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/redux/providers/balancesActions.js b/js/src/redux/providers/balancesActions.js index 54240fa0bac..2d79e54abca 100644 --- a/js/src/redux/providers/balancesActions.js +++ b/js/src/redux/providers/balancesActions.js @@ -186,7 +186,7 @@ export function fetchTokens (_tokenIds, options = {}) { return Promise .all(tokenIds.map((id) => fetchTokenInfo(tokenreg, id, api))) .then((tokens) => { - return token.filter((token) => token.tag && token.tag.toLowerCase() !== 'eth'); + return tokens.filter((token) => token.tag && token.tag.toLowerCase() !== 'eth'); }) .then((tokens) => { // dispatch only the changed images From c645d8c9217d38bb529aaa15fee949ef970de641 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Fri, 20 Jan 2017 17:45:05 +0000 Subject: [PATCH 3/4] Revert filtering out --- js/src/redux/providers/balancesActions.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/src/redux/providers/balancesActions.js b/js/src/redux/providers/balancesActions.js index 2d79e54abca..011137d7e90 100644 --- a/js/src/redux/providers/balancesActions.js +++ b/js/src/redux/providers/balancesActions.js @@ -185,9 +185,6 @@ export function fetchTokens (_tokenIds, options = {}) { return Promise .all(tokenIds.map((id) => fetchTokenInfo(tokenreg, id, api))) - .then((tokens) => { - return tokens.filter((token) => token.tag && token.tag.toLowerCase() !== 'eth'); - }) .then((tokens) => { // dispatch only the changed images tokens From 6346b7491faf6bbd255bfc4b407bb14c2630a1de Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Fri, 20 Jan 2017 18:17:35 +0000 Subject: [PATCH 4/4] Revert the revert --- js/src/redux/providers/balancesActions.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/src/redux/providers/balancesActions.js b/js/src/redux/providers/balancesActions.js index 011137d7e90..4a88bb1bea8 100644 --- a/js/src/redux/providers/balancesActions.js +++ b/js/src/redux/providers/balancesActions.js @@ -185,6 +185,8 @@ export function fetchTokens (_tokenIds, options = {}) { return Promise .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) => { // dispatch only the changed images tokens