diff --git a/src/helpers/balance.js b/src/helpers/balance.js index a211002e..340c5be2 100644 --- a/src/helpers/balance.js +++ b/src/helpers/balance.js @@ -69,6 +69,7 @@ export function getBalanceHistoryForAccount({ counterValues: Object, interval: DateInterval, }): Array { + const todayDate = moment().format('YYYY-MM-DD') const unit = getDefaultUnitByCoinType(account.coinType) const counterVals = get(counterValues, `${unit.code}.${counterValue}`) let lastBalance = getBalanceAtIntervalStart(account, interval) @@ -79,14 +80,19 @@ export function getBalanceHistoryForAccount({ return { balance, date } } + const isToday = date === todayDate + const counterVal = isToday + ? counterVals.latest || counterVals[date] || 0 + : counterVals[date] || 0 + // if we don't have data on account balance for that day, // we take the prev day if (isUndefined(account.balanceByDay[date])) { - balance = lastBalance === null ? 0 : lastBalance * counterVals[date] + balance = lastBalance === null ? 0 : lastBalance * counterVal } else { const b = account.balanceByDay[date] lastBalance = b - balance = b * counterVals[date] + balance = b * counterVal } if (isNaN(balance)) { diff --git a/src/reducers/counterValues.js b/src/reducers/counterValues.js index c662c04f..612a3f9e 100644 --- a/src/reducers/counterValues.js +++ b/src/reducers/counterValues.js @@ -16,7 +16,7 @@ export type CounterValuesState = {} const state: CounterValuesState = {} const handlers = { - UPDATE_COUNTER_VALUES: (state, { payload: counterValues }) => merge(state, counterValues), + UPDATE_COUNTER_VALUES: (state, { payload: counterValues }) => merge({ ...state }, counterValues), } const getPairHistory = state => (coinTicker, fiat) => {