#301: turn stats calculation into subscription, improve dollar amount display
This commit is contained in:
parent
3cdfa549b7
commit
35a8cfd84c
|
@ -135,4 +135,10 @@
|
||||||
[:div.page-nav-text [:span (str "Page " page-number " of " page-count)]]
|
[:div.page-nav-text [:span (str "Page " page-number " of " page-count)]]
|
||||||
[draw-page-numbers page-number page-count container-element]]])))
|
[draw-page-numbers page-number page-count container-element]]])))
|
||||||
|
|
||||||
|
(defn usd-string
|
||||||
|
"Turn a given float into a USD currency string based on the browsers locale setting.
|
||||||
|
|
||||||
|
A more complex and customizable approach can be found in goog.i18n.NumberFormat:
|
||||||
|
https://google.github.io/closure-library/api/goog.i18n.NumberFormat.html"
|
||||||
|
[usd-float]
|
||||||
|
(.toLocaleString usd-float js/navigator.language #js {:style "currency" :currency "USD"}))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(ns commiteth.manage-payouts
|
(ns commiteth.manage-payouts
|
||||||
(:require [re-frame.core :as rf]
|
(:require [re-frame.core :as rf]
|
||||||
[commiteth.common :refer [human-time]]))
|
[commiteth.common :as common :refer [human-time]]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,21 +58,20 @@
|
||||||
[claim-card bounty claim]))))
|
[claim-card bounty claim]))))
|
||||||
|
|
||||||
(defn bounty-stats [{:keys [paid unpaid]}]
|
(defn bounty-stats [{:keys [paid unpaid]}]
|
||||||
(let [sum-dollars (fn [bounties]
|
[:div.cf.pv4
|
||||||
(reduce + (map #(js/parseFloat (:value_usd %)) bounties)))]
|
[:div.fl.w-50.tc
|
||||||
[:div.cf.pv4
|
[:div.ttu.tracked "Open"]
|
||||||
[:div.fl.w-50.tc
|
[:div.f2.pa2 (common/usd-string (:combined-usd-value unpaid))]
|
||||||
[:div.ttu.tracked "Open"]
|
[:div (:count unpaid) " bounties"]]
|
||||||
[:div.f2.pa2 "$" (sum-dollars unpaid)]
|
|
||||||
[:div (count unpaid) " bounties"]]
|
|
||||||
|
|
||||||
[:div.fl.w-50.tc
|
[:div.fl.w-50.tc
|
||||||
[:div.ttu.tracked "Paid"]
|
[:div.ttu.tracked "Paid"]
|
||||||
[:div.f2.pa2 "$" (sum-dollars paid)]
|
[:div.f2.pa2 (common/usd-string (:combined-usd-value paid))]
|
||||||
[:div (count paid) " bounties"]]]))
|
[:div (:count paid) " bounties"]]])
|
||||||
|
|
||||||
(defn manage-payouts-page []
|
(defn manage-payouts-page []
|
||||||
(let [owner-bounties (rf/subscribe [:owner-bounties])
|
(let [owner-bounties (rf/subscribe [:owner-bounties])
|
||||||
|
bounty-stats-data (rf/subscribe [:owner-bounties-stats])
|
||||||
owner-bounties-loading? (rf/subscribe [:get-in [:owner-bounties-loading?]])]
|
owner-bounties-loading? (rf/subscribe [:get-in [:owner-bounties-loading?]])]
|
||||||
(fn []
|
(fn []
|
||||||
(if @owner-bounties-loading?
|
(if @owner-bounties-loading?
|
||||||
|
@ -80,18 +79,14 @@
|
||||||
[:div.ui.active.inverted.dimmer
|
[:div.ui.active.inverted.dimmer
|
||||||
[:div.ui.text.loader "Loading"]]]
|
[:div.ui.text.loader "Loading"]]]
|
||||||
(let [web3 (.-web3 js/window)
|
(let [web3 (.-web3 js/window)
|
||||||
bounties (vals @owner-bounties)
|
bounties (vals @owner-bounties)]
|
||||||
paid? :payout_hash
|
|
||||||
unpaid-bounties (filter (complement paid?) bounties)
|
|
||||||
paid-bounties (filter paid? bounties)]
|
|
||||||
[:div.ui.container
|
[:div.ui.container
|
||||||
(when (nil? web3)
|
(when (nil? web3)
|
||||||
[:div.ui.warning.message
|
[:div.ui.warning.message
|
||||||
[:i.warning.icon]
|
[:i.warning.icon]
|
||||||
"To sign off claims, please view Status Open Bounty in Status, Mist or Metamask"])
|
"To sign off claims, please view Status Open Bounty in Status, Mist or Metamask"])
|
||||||
[bounty-stats {:paid paid-bounties
|
[bounty-stats @bounty-stats-data]
|
||||||
:unpaid unpaid-bounties}]
|
|
||||||
[:h3 "New claims"]
|
[:h3 "New claims"]
|
||||||
[claim-list unpaid-bounties]
|
[claim-list (filter (complement :paid?) bounties)]
|
||||||
[:h3 "Old claims"]
|
[:h3 "Old claims"]
|
||||||
[claim-list paid-bounties]])))))
|
[claim-list (filter :paid? bounties)]])))))
|
||||||
|
|
|
@ -68,7 +68,26 @@
|
||||||
(reg-sub
|
(reg-sub
|
||||||
:owner-bounties
|
:owner-bounties
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(:owner-bounties db)))
|
(->> (for [[id bounty] (:owner-bounties db)]
|
||||||
|
;; TODO(martinklepsch) we might want to consider using a
|
||||||
|
;; special prefix or namespace for derived properties that
|
||||||
|
;; are added to domain records like this
|
||||||
|
;; e.g. `derived/paid?`
|
||||||
|
[id (assoc bounty :paid? (boolean (:payout_hash bounty)))])
|
||||||
|
(into {}))))
|
||||||
|
|
||||||
|
(reg-sub
|
||||||
|
:owner-bounties-stats
|
||||||
|
:<- [:owner-bounties]
|
||||||
|
(fn [owner-bounties _]
|
||||||
|
(let [sum-dollars (fn sum-dollars [bounties]
|
||||||
|
(reduce + (map #(js/parseFloat (:value_usd %)) bounties)))
|
||||||
|
{:keys [paid unpaid]} (group-by #(if (:paid? %) :paid :unpaid)
|
||||||
|
(vals owner-bounties))]
|
||||||
|
{:paid {:count (count paid)
|
||||||
|
:combined-usd-value (sum-dollars paid)}
|
||||||
|
:unpaid {:count (count unpaid)
|
||||||
|
:combined-usd-value (sum-dollars unpaid)}})))
|
||||||
|
|
||||||
(reg-sub
|
(reg-sub
|
||||||
:pagination
|
:pagination
|
||||||
|
|
Loading…
Reference in New Issue