cleaning up interface for account.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user