Merge pull request #348 from status-im/fix/token-formatting

Improve conversion of token values to float
This commit is contained in:
Vitaliy Vlasov 2018-03-12 18:56:49 +02:00 committed by GitHub
commit a37be80b73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -146,26 +146,40 @@
(defn prettify-bounty-items [bounty-items] (defn prettify-bounty-items [bounty-items]
(let [renames {:user_name :display-name (let [format-float (fn [bounty balance]
:user_avatar_url :avatar-url (try
:issue_title :issue-title (format "%.2f" (double balance))
:type :item-type (catch Throwable ex
:repo_name :repo-name (log/error (str (:repo-owner bounty)
:repo_owner :repo-owner "/"
:issue_number :issue-number (:repo-name bounty)
:value_usd :value-usd "/"
:claim_count :claim-count (:issue-number bounty))
:balance_eth :balance-eth "Failed to convert token value:" balance)
:user_has_address :user-has-address}] "0.00")))
update-token-values (fn [bounty]
(->> bounty
:tokens
(map (fn [[tla balance]]
[tla (format-float bounty balance)]))
(into {})
(assoc bounty :tokens)))
renames {:user_name :display-name
:user_avatar_url :avatar-url
:issue_title :issue-title
:type :item-type
:repo_name :repo-name
:repo_owner :repo-owner
:issue_number :issue-number
:value_usd :value-usd
:claim_count :claim-count
:balance_eth :balance-eth
:user_has_address :user-has-address}]
(map #(-> % (map #(-> %
(rename-keys renames) (rename-keys renames)
(update :value-usd usd-decimal->str) (update :value-usd usd-decimal->str)
(update :balance-eth eth-decimal->str) (update :balance-eth eth-decimal->str)
(update :tokens (fn [tokens] update-token-values)
(into {}
(map (fn [[tla balance]]
[tla (format "%.2f" balance)])
tokens)))))
bounty-items))) bounty-items)))
(defn activity-feed [] (defn activity-feed []