cleaning up interface for account.

This commit is contained in:
Bryce Covert
2019-04-25 18:46:54 -07:00
parent 459e0b3e52
commit dd86b2be48
4 changed files with 64 additions and 80 deletions

View File

@@ -7,6 +7,41 @@
[re-frame.core :as re-frame]
[clojure.string :as str]))
(defn can-replace-with-default? [accounts]
(and (or (not (seq accounts))
(<= 1 (count accounts)))
(not (get-in accounts [0 :account :id]))))
(defn default-account [accounts default-account amount]
[{:id (str "new-" (random-uuid))
:amount (Math/abs amount)
:amount-percentage 100
:amount-mode "%"
:location (or
(:location default-account)
(get-in accounts [0 :account :location]))
:account default-account}])
(defn from-graphql [accounts total locations]
(println accounts total locations)
(if (seq accounts)
(vec (map
(fn [a]
(-> a
(update :amount js/parseFloat)
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
(Math/abs (js/parseFloat total)))))
(assoc :amount-mode "$")))
accounts))
[{:id (str "new-" (random-uuid))
:amount-mode "$"
:amount (Math/abs total)
:amount-percentage 100
:location (if (= 1 (count locations))
(first locations)
nil)}]))
;; EVENTS