Fix portfolio change to 0 if balance is zero

If you don't have money in your balance, your "portfolio" change is nothing.

- Positive portfolio change includes if it is zero
This commit is contained in:
Oskar Thorén 2017-09-21 20:01:20 +02:00 committed by Roman Volosovskyi
parent e8c2fa1f80
commit c846574155
2 changed files with 8 additions and 5 deletions

View File

@ -45,7 +45,7 @@
transaction-history-action]]]) transaction-history-action]]])
(defn- change-display [change] (defn- change-display [change]
(let [pos-change? (pos? change)] (let [pos-change? (or (pos? change) (zero? change))]
[react/view {:style (if pos-change? [react/view {:style (if pos-change?
wallet.styles/today-variation-container-positive wallet.styles/today-variation-container-positive
wallet.styles/today-variation-container-negative)} wallet.styles/today-variation-container-negative)}

View File

@ -46,11 +46,14 @@
(reg-sub :portfolio-change (reg-sub :portfolio-change
:<- [:price] :<- [:price]
:<- [:last-day] :<- [:last-day]
(fn [[price last-day]] :<- [:balance]
(fn [[price last-day balance]]
(when (and price last-day) (when (and price last-day)
(-> (money/percent-change price last-day) (if (> balance 0)
(money/with-precision 2) (-> (money/percent-change price last-day)
.toNumber)))) (money/with-precision 2)
.toNumber)
0))))
(reg-sub :prices-loading? (reg-sub :prices-loading?
(fn [db] (fn [db]