diff --git a/src/components/BalanceSummary/index.js b/src/components/BalanceSummary/index.js index 282e8b46..71cf4d03 100644 --- a/src/components/BalanceSummary/index.js +++ b/src/components/BalanceSummary/index.js @@ -50,7 +50,7 @@ const BalanceSummary = ({ accounts, selectedTime, daysCount }: Props) => ( }} strokeWidth={2} renderLabels={d => - formatCurrencyUnit(getFiatUnit('USD'), d.y * 10, { + formatCurrencyUnit(getFiatUnit('USD'), d.y * 100, { showCode: true, }) } diff --git a/src/components/CalculateBalance.js b/src/components/CalculateBalance.js index bbf5c3e1..393c435f 100644 --- a/src/components/CalculateBalance.js +++ b/src/components/CalculateBalance.js @@ -90,11 +90,7 @@ function calculateBalance(props) { }) return { - allBalances: getAllBalances({ - accounts: props.accounts, - counterValues: props.counterValues, - daysCount: props.daysCount, - }), + allBalances, totalBalance: last(allBalances).value, sinceBalance: first(allBalances).value, } diff --git a/src/datas.json b/src/datas.json index 61ed5258..b8136eef 100644 --- a/src/datas.json +++ b/src/datas.json @@ -2784,7 +2784,8 @@ "2018-02-26": 10326.5, "2018-02-27": 10594.76, "2018-02-28": 10334.44, - "2018-03-01": 10711.91 + "2018-03-01": 10929.37, + "2018-03-02": 11130.09 }, "XRP-USD": { "2015-01-21": 0.01523, @@ -3922,7 +3923,8 @@ "2018-02-26": 0.9296, "2018-02-27": 0.9276, "2018-02-28": 0.8853, - "2018-03-01": 0.907 + "2018-03-01": 0.9155, + "2018-03-02": 0.9072 }, "LTC-USD": { "2013-10-24": 3, @@ -5514,6 +5516,7 @@ "2018-02-26": 218.62, "2018-02-27": 215.15, "2018-02-28": 202.14, - "2018-03-01": 208.91 + "2018-03-01": 209.32, + "2018-03-02": 208.01 } } \ No newline at end of file diff --git a/src/helpers/btc.js b/src/helpers/btc.js index 5a6f259a..b1b848dc 100644 --- a/src/helpers/btc.js +++ b/src/helpers/btc.js @@ -68,6 +68,7 @@ export function getBalanceByDay(transactions: Transactions) { export async function getAccount({ rootPath, allAddresses = [], + allTxsHash = [], currentIndex = 0, hdnode, segwit, @@ -78,6 +79,7 @@ export async function getAccount({ }: { rootPath: string, allAddresses?: Array, + allTxsHash?: Array, currentIndex?: number, hdnode: Object, segwit: boolean, @@ -122,7 +124,7 @@ export async function getAccount({ new Promise(resolve => setTimeout(() => resolve(getAddress(params)), asyncDelay)) const getLastAddress = (addresses, txs) => { - const txsAddresses = [...txs.inputs.map(tx => tx.address), ...txs.outputs.map(tx => tx.address)] + const txsAddresses = [...txs.inputs.map(t => t.address), ...txs.outputs.map(t => t.address)] return addresses.find(a => txsAddresses.includes(a.address)) || null } @@ -146,9 +148,8 @@ export async function getAccount({ allAddresses = [...new Set([...allAddresses, ...listAddresses])] const transactionsOpts = { coin_type: coinType } - const txs = await ledger.getTransactions(listAddresses, transactionsOpts) - - txs.reverse() + let txs = await ledger.getTransactions(listAddresses, transactionsOpts) + txs.reverse().filter(t => !allTxsHash.includes(t.hash)) const hasTransactions = txs.length > 0 diff --git a/src/internals/accounts/sync.js b/src/internals/accounts/sync.js index f660f96b..68064960 100644 --- a/src/internals/accounts/sync.js +++ b/src/internals/accounts/sync.js @@ -4,12 +4,15 @@ import { getAccount, getHDNode, networks } from 'helpers/btc' const network = networks[1] -function syncAccount({ id, ...currentAccount }) { +function syncAccount({ id, transactions, ...currentAccount }) { const hdnode = getHDNode({ xpub58: id, network }) - return getAccount({ hdnode, network, segwit: true, ...currentAccount }).then(account => ({ - id, - ...account, - })) + const allTxsHash = transactions.map(t => t.hash) + return getAccount({ hdnode, network, allTxsHash, segwit: true, ...currentAccount }).then( + account => ({ + id, + ...account, + }), + ) } export default (send: Function) => ({ diff --git a/src/reducers/accounts.js b/src/reducers/accounts.js index 6115c324..19c103cd 100644 --- a/src/reducers/accounts.js +++ b/src/reducers/accounts.js @@ -53,17 +53,18 @@ const handlers: Object = { return existingAccount } - const { transactions, index } = account + const { balance, balanceByDay, transactions } = existingAccount const updatedAccount = { ...existingAccount, ...account, - balance: transactions.reduce((result, v) => { - result += v.balance + balance: balance + account.balance, + balanceByDay: Object.keys(balanceByDay).reduce((result, k) => { + result[k] = balanceByDay[k] + (account.balanceByDay[k] || 0) return result - }, 0), - index: index || get(existingAccount, 'index', 0), - transactions, + }, {}), + index: account.index || get(existingAccount, 'index', 0), + transactions: [...transactions, ...account.transactions], } return orderAccountsTransactions(updatedAccount) diff --git a/src/renderer/events.js b/src/renderer/events.js index 4abe2860..3123b62c 100644 --- a/src/renderer/events.js +++ b/src/renderer/events.js @@ -2,7 +2,6 @@ import { ipcRenderer } from 'electron' import objectPath from 'object-path' -import get from 'lodash/get' import debug from 'debug' import type { Accounts } from 'types/common' @@ -52,13 +51,13 @@ export function startSyncAccounts(accounts: Accounts) { syncAccounts = true sendEvent('accounts', 'sync.all', { accounts: accounts.map(account => { - const index = get(account, 'index', 0) - const addresses = get(account, 'addresses', []) + const { id, rootPath, addresses, index, transactions } = account return { - id: account.id, - rootPath: account.rootPath, + id, allAddresses: addresses, currentIndex: index, + rootPath, + transactions, } }), }) @@ -92,20 +91,11 @@ export default ({ store, locked }: { store: Object, locked: boolean }) => { return } - const { name, balanceByDay } = currentAccount + const { name } = currentAccount if (account.transactions.length > 0) { d.sync(`Update account - ${name}`) - store.dispatch( - updateAccount({ - ...account, - balance: currentAccount.balance + account.balance, - balanceByDay: Object.keys(balanceByDay).reduce((result, k) => { - result[k] = balanceByDay[k] + (account.balanceByDay[k] || 0) - return result - }, {}), - }), - ) + store.dispatch(updateAccount(account)) } } },