multitude of improvements to stats component
This commit is contained in:
parent
d4cf000166
commit
11d088c63f
|
@ -35,7 +35,4 @@
|
|||
(str "https://github.com/" (:repo-owner bounty) "/" (:repo-name bounty) "/issues/" (:issue-number bounty)))
|
||||
|
||||
(defn crypto-balances [bounty]
|
||||
;; TODO add some assertions
|
||||
(cond-> (seq (:tokens bounty))
|
||||
(< 0 (util/parse-float (:balance-eth bounty)))
|
||||
(conj [:ETH (:balance-eth bounty)])))
|
||||
(assoc (:tokens bounty) :ETH (util/parse-float (:balance-eth bounty))))
|
||||
|
|
|
@ -28,9 +28,16 @@
|
|||
[:span.gray "Value "]
|
||||
[:span.dark-gray (str "$" value-usd)]])
|
||||
|
||||
(defn token-balances [crypto-balances style]
|
||||
(defn token-balances
|
||||
"Render ETH and token balances using the specified `style` (:label or :badge).
|
||||
|
||||
Non-positive balances will not be rendered. ETH will always be rendered first."
|
||||
[crypto-balances style]
|
||||
[:span ; TODO consider non DOM el react wrapping
|
||||
(for [[tla balance] crypto-balances]
|
||||
(for [[tla balance] (-> (dissoc crypto-balances :ETH)
|
||||
(seq)
|
||||
(conj [:ETH (:ETH crypto-balances)]))
|
||||
:when (pos? balance)]
|
||||
^{:key tla}
|
||||
[:div.dib.mr2
|
||||
(case style
|
||||
|
|
|
@ -7,3 +7,13 @@
|
|||
(defn assert-first [xs]
|
||||
(assert (first xs) "assert-first failure")
|
||||
(first xs))
|
||||
|
||||
(defn sum-maps
|
||||
"Take a collection of maps and sum the numeric values for all keys in those maps."
|
||||
[maps]
|
||||
(let [sum-keys (fn sum-keys [r k v]
|
||||
(update r k (fnil + 0) v))]
|
||||
(reduce (fn [r m]
|
||||
(reduce-kv sum-keys r m))
|
||||
{}
|
||||
maps)))
|
||||
|
|
|
@ -182,12 +182,22 @@
|
|||
[:div.ph4 "Open bounties in total"]]])
|
||||
|
||||
(defn bounty-stats-new [{:keys [paid unpaid]}]
|
||||
[:div.br3.bg-white.shadow-6.pa4
|
||||
[:span.db.f3.pg-med.mb2.dark-gray (common/usd-string (:combined-usd-value paid))]
|
||||
[:span.gray "Paid for " [:span.dark-gray (:count paid) " solved bounties"]]
|
||||
[:div.bb.b--near-white.mv3]
|
||||
[:span.db.f3.pg-med.pt1.mb2.dark-gray (common/usd-string (:combined-usd-value unpaid))]
|
||||
[:span.gray "Open for " [:span.dark-gray (:count unpaid) " bounties"]]])
|
||||
(let [usd-stat (fn usd-stat [usd-amount]
|
||||
[:div.dt
|
||||
[:span.dtc.v-mid.pr1 "$"]
|
||||
[:span.dtc.pg-med.fw5.mb2.dark-gray
|
||||
{:class (if (< 100000000 usd-amount) "f3" "f2")}
|
||||
(.toLocaleString usd-amount)]])]
|
||||
[:div.br3.bg-white.shadow-6.pa4.dark-gray
|
||||
[:span.db.mb3.f6 "Paid for " (:count paid) " solved bounties"]
|
||||
(usd-stat (:combined-usd-value paid))
|
||||
[:div.f6.mt3
|
||||
[ui-balances/token-balances (:crypto paid) :label]]
|
||||
[:div.bb.b--near-white.mv3]
|
||||
[:span.db.mb3.f6 "Open for " [:span.dark-gray (:count unpaid) " bounties"]]
|
||||
(usd-stat (:combined-usd-value unpaid))
|
||||
[:div.f6.mt3
|
||||
[ui-balances/token-balances (:crypto unpaid) :label]]]))
|
||||
|
||||
(def state-mapping
|
||||
{:opened :open
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns commiteth.subscriptions
|
||||
(:require [re-frame.core :refer [reg-sub]]
|
||||
[commiteth.db :as db]
|
||||
[commiteth.util :as util]
|
||||
[commiteth.ui-model :as ui-model]
|
||||
[commiteth.common :refer [items-per-page]]
|
||||
[clojure.string :as string]))
|
||||
|
@ -88,14 +89,20 @@
|
|||
:owner-bounties-stats
|
||||
:<- [:owner-bounties]
|
||||
(fn [owner-bounties _]
|
||||
(let [sum-dollars (fn sum-dollars [bounties]
|
||||
(reduce + (map #(js/parseFloat (:value-usd %)) bounties)))
|
||||
(let [sum-field (fn sum-field [field bounties]
|
||||
(reduce + (map #(js/parseFloat (get % field)) bounties)))
|
||||
sum-crypto (fn sum-crypto [bounties]
|
||||
(-> (map :tokens bounties)
|
||||
(util/sum-maps)
|
||||
(assoc :ETH (sum-field :balance-eth bounties))))
|
||||
{:keys [paid unpaid]} (group-by #(if (:paid? %) :paid :unpaid)
|
||||
(vals owner-bounties))]
|
||||
{:paid {:count (count paid)
|
||||
:combined-usd-value (sum-dollars paid)}
|
||||
:combined-usd-value (sum-field :value-usd paid)
|
||||
:crypto (sum-crypto paid)}
|
||||
:unpaid {:count (count unpaid)
|
||||
:combined-usd-value (sum-dollars unpaid)}})))
|
||||
:combined-usd-value (sum-field :value-usd unpaid)
|
||||
:crypto (sum-crypto unpaid)}})))
|
||||
|
||||
(reg-sub
|
||||
:dashboard/seen-banners
|
||||
|
|
Loading…
Reference in New Issue