From 584f742de95ded3d8449a59f6fea070d25311dd2 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Wed, 23 Aug 2017 23:47:50 +0300 Subject: [PATCH] Show tokens, ETH and USD value on UI * make activity feed items and open bounties view show badges for ETH and tokems and total USD in item description * make top hunters work based on total USD value paid out in bounties * upgrade lein-cljsbuild --- project.clj | 2 +- resources/sql/queries.sql | 33 ++++++++++++------- src/clj/commiteth/db/issues.clj | 4 +-- src/clj/commiteth/routes/qrcodes.clj | 6 ++-- src/clj/commiteth/routes/services.clj | 40 ++++++++++++++++-------- src/clj/commiteth/scheduler.clj | 24 +++++++------- src/clj/commiteth/util/png_rendering.clj | 4 +-- src/clj/commiteth/util/util.clj | 5 ++- src/cljs/commiteth/activity.cljs | 17 ++++++---- src/cljs/commiteth/bounties.cljs | 9 ++++-- src/cljs/commiteth/core.cljs | 2 +- 11 files changed, 90 insertions(+), 56 deletions(-) diff --git a/project.clj b/project.clj index d4027cd..ca50c4c 100644 --- a/project.clj +++ b/project.clj @@ -64,7 +64,7 @@ :plugins [[lein-cprop "1.0.1"] [migratus-lein "0.4.1"] - [lein-cljsbuild "1.1.3"] + [lein-cljsbuild "1.1.7"] [lein-auto "0.1.2"] [lein-less "1.7.5"] [lein-shell "0.5.0"] diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index e25dc94..38c2bf2 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -251,8 +251,9 @@ SELECT i.comment_id AS comment_id, i.issue_number AS issue_number, i.issue_id AS issue_id, - i.balance_eth AS balance, + i.balance_eth AS balance_eth, i.tokens AS tokens, + i.value_usd AS value_usd, u.login AS winner_login, u.address AS payout_address FROM issues i, pull_requests p, users u, repositories r @@ -288,8 +289,9 @@ SELECT i.comment_id AS comment_id, i.issue_number AS issue_number, i.issue_id AS issue_id, - i.balance_eth AS balance, + i.balance_eth AS balance_eth, i.tokens AS tokens, + i.value_usd AS value_usd, u.address AS payout_address, u.login AS payee_login, i.payout_hash AS payout_hash @@ -355,8 +357,9 @@ SELECT i.issue_number AS issue_number, i.title AS issue_title, i.repo_id AS repo_id, - i.balance_eth AS balance, + i.balance_eth AS balance_eth, i.tokens AS tokens, + i.value_usd AS value_usd, i.confirm_hash AS confirm_hash, i.payout_hash AS payout_hash, i.payout_receipt AS payout_receipt, @@ -368,7 +371,7 @@ FROM issues i, repositories r WHERE r.repo_id = i.repo_id AND i.confirm_hash is null -ORDER BY balance desc, updated desc; -- TODO: order by USD value first +ORDER BY value_usd desc, updated desc; @@ -382,6 +385,7 @@ SELECT i.repo_id AS repo_id, i.balance_eth AS balance_eth, i.tokens AS tokens, + i.value_usd AS value_usd, i.confirm_hash AS confirm_hash, i.payout_hash AS payout_hash, i.payout_receipt AS payout_receipt, @@ -403,8 +407,9 @@ SELECT i.issue_number AS issue_number, i.title AS issue_title, i.repo_id AS repo_id, - i.balance_eth AS balance, + i.balance_eth AS balance_eth, i.tokens AS tokens, + i.value_usd AS value_usd, i.confirm_hash AS confirm_hash, i.payout_hash AS payout_hash, i.payout_receipt AS payout_receipt, @@ -438,8 +443,9 @@ SELECT i.comment_id AS comment_id, i.issue_number AS issue_number, i.issue_id AS issue_id, - i.balance_eth AS balance, - i.tokens AS tokens + i.balance_eth AS balance_eth, + i.tokens AS tokens, + i.value_usd AS value_usd FROM issues i, repositories r WHERE r.repo_id = i.repo_id AND contract_address IS NOT NULL @@ -451,8 +457,9 @@ SELECT i.contract_address AS contract_address, i.issue_id AS issue_id, i.issue_number AS issue_number, - i.balance_eth AS balance, + i.balance_eth AS balance_eth, i.tokens AS tokens, + i.value_usd AS value_usd, r.owner AS owner, r.repo AS repo FROM issues i, repositories r @@ -464,7 +471,7 @@ AND r.repo = :repo; -- :name update-eth-balance :! :n -- :doc updates balance of a wallet attached to a given issue UPDATE issues -SET balance_eth = :balance, +SET balance_eth = :balance_eth, updated = timezone('utc'::text, now()) WHERE contract_address = :contract_address; @@ -494,14 +501,14 @@ u.id AS user_id, u.login AS login, u.name AS user_name, u.avatar_url AS avatar_url, -SUM(i.balance_eth) AS total_eth +SUM(i.value_usd) AS total_usd FROM issues i, users u, pull_requests pr WHERE pr.commit_sha = i.commit_sha AND u.id = pr.user_id AND i.payout_receipt IS NOT NULL GROUP BY u.id -ORDER BY total_eth DESC; -- TODO: this should work with value_usd +ORDER BY total_usd DESC; -- :name bounties-activity :? :* @@ -514,7 +521,9 @@ SELECT issue_number, user_name, user_avatar_url, - balance, + balance_eth, + tokens, + value_usd, updated FROM activity_feed_view ORDER BY updated DESC diff --git a/src/clj/commiteth/db/issues.clj b/src/clj/commiteth/db/issues.clj index 912c5c7..65cde9d 100644 --- a/src/clj/commiteth/db/issues.clj +++ b/src/clj/commiteth/db/issues.clj @@ -65,10 +65,10 @@ (db/list-failed-deployments con-db))) (defn update-eth-balance - [contract-address balance] + [contract-address balance-eth] (jdbc/with-db-connection [con-db *db*] (db/update-eth-balance con-db {:contract_address contract-address - :balance balance}))) + :balance_eth balance-eth}))) (defn update-token-balances [contract-address balances] diff --git a/src/clj/commiteth/routes/qrcodes.clj b/src/clj/commiteth/routes/qrcodes.clj index cb45039..1519077 100644 --- a/src/clj/commiteth/routes/qrcodes.clj +++ b/src/clj/commiteth/routes/qrcodes.clj @@ -15,14 +15,14 @@ (if-let [{address :contract_address repo :repo issue-id :issue_id - balance :balance} + balance-eth :balance_eth} (bounties/get-bounty owner repo (Integer/parseInt issue))] (do (log/debug "address:" address) - (log/debug owner repo issue balance) - (log/debug hash (github/github-comment-hash owner repo issue balance)) + (log/debug owner repo issue balance-eth) + (log/debug hash (github/github-comment-hash owner repo issue balance-eth)) (if address (if-let [{png-data :png_data} (comment-images/get-image-data diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 9a30275..4aff076 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -15,7 +15,8 @@ [clojure.tools.logging :as log] [commiteth.eth.core :as eth] [commiteth.config :refer [env]] - [commiteth.util.util :refer [decimal->str]] + [commiteth.util.util :refer [usd-decimal->str + eth-decimal->str]] [crypto.random :as random] [clojure.set :refer [rename-keys]] [clojure.string :as str])) @@ -112,11 +113,11 @@ (let [owner-bounties (bounties-db/owner-bounties (:id user))] (into {} (for [ob owner-bounties - :let [b (update ob :balance decimal->str)]] + :let [b (update ob :value_usd usd-decimal->str)]] [(:issue_id b) (conj b (let [claims (map - #(update % :balance decimal->str) + #(update % :value_usd usd-decimal->str) (bounties-db/bounty-claims (:issue_id b)))] {:claims claims}))])))) @@ -124,26 +125,40 @@ (defn top-hunters [] (let [renames {:user_name :display-name :avatar_url :avatar-url - :total_eth :total-eth}] + :total_usd :total-usd}] (map #(-> % (rename-keys renames) - (update :total-eth decimal->str)) + (update :total-usd usd-decimal->str)) (bounties-db/top-hunters)))) -(defn activity-feed [] - (let [renames {:user_name :display-name +(defn prettify-bounty-items [bounty-items] + (let [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} - activity-items (bounties-db/bounty-activity)] + :issue_number :issue-number + :value_usd :value-usd + :balance_eth :balance-eth}] (map #(-> % (rename-keys renames) - (update :balance decimal->str)) - activity-items))) + (update :value-usd usd-decimal->str) + (update :balance-eth eth-decimal->str) + (update :tokens (fn [tokens] + (into {} + (map (fn [[tla balance]] + [tla (format "%.2f" balance)]) + tokens))))) + bounty-items))) + +(defn activity-feed [] + (prettify-bounty-items (bounties-db/bounty-activity))) + +(defn open-bounties [] + (prettify-bounty-items (bounties-db/open-bounties))) + (defn current-user-token [user] @@ -173,8 +188,7 @@ (ok (activity-feed))) (GET "/open-bounties" [] (log/debug "/open-bounties") - (ok (map #(update % :balance decimal->str) - (bounties-db/open-bounties)))) + (ok (open-bounties))) (GET "/usage-metrics" [] :query-params [token :- String] :auth-rules status-team-member? diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index d2d67c3..ed4fb9d 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -7,7 +7,7 @@ [commiteth.db.bounties :as db-bounties] [commiteth.bounties :as bounties] [commiteth.util.crypto-fiat-value :as fiat-util] - [commiteth.util.util :refer [decimal->str]] + [commiteth.util.util :refer [eth-decimal->str]] [clojure.tools.logging :as log] [mount.core :as mount] [clj-time.core :as t] @@ -29,23 +29,23 @@ repo :repo comment-id :comment_id issue-number :issue_number} issue - balance-str (eth/get-balance-eth contract-address 6) - balance (read-string balance-str)] + balance-eth-str (eth/get-balance-eth contract-address 6) + balance-eth (read-string balance-eth-str)] (bounties/update-bounty-comment-image issue-id owner repo issue-number contract-address - balance - balance-str + balance-eth + balance-eth-str {}) (github/update-comment owner repo comment-id issue-number contract-address - balance - balance-str + balance-eth + balance-eth-str {})))))) @@ -87,7 +87,7 @@ owner :owner comment-id :comment_id issue-number :issue_number - balance :balance + balance-eth :balance_eth tokens :tokens winner-login :winner_login} (db-bounties/pending-bounties) :let [value (eth/get-balance-hex contract-address)]] @@ -99,7 +99,7 @@ repo comment-id contract-address - (decimal->str balance) + (eth-decimal->str balance-eth) tokens winner-login))))) @@ -124,7 +124,7 @@ owner :owner comment-id :comment_id issue-number :issue_number - balance :balance + balance-eth :balance_eth tokens :tokens payee-login :payee_login} (db-bounties/confirmed-payouts)] (log/debug "confirmed payout:" payout-hash) @@ -135,7 +135,7 @@ repo comment-id contract-address - (decimal->str balance) + (eth-decimal->str balance-eth) tokens payee-login)))) @@ -205,7 +205,7 @@ repo :repo comment-id :comment_id issue-id :issue_id - db-balance-eth :balance + db-balance-eth :balance_eth db-tokens :tokens issue-number :issue_number} (db-bounties/open-bounty-contracts)] (when comment-id diff --git a/src/clj/commiteth/util/png_rendering.clj b/src/clj/commiteth/util/png_rendering.clj index f739eec..12f2a17 100644 --- a/src/clj/commiteth/util/png_rendering.clj +++ b/src/clj/commiteth/util/png_rendering.clj @@ -61,12 +61,12 @@ (let [{owner :owner repo :repo issue-id :issue_id - balance :balance} (db-bounties/get-bounty owner repo issue-number) + balance-eth :balance_eth} (db-bounties/get-bounty owner repo issue-number) hash (github/github-comment-hash owner repo issue-number - balance)] + balance-eth)] (with-open [w (io/output-stream filename)] (.write w (:png_data (db/get-image-data issue-id hash)))))) diff --git a/src/clj/commiteth/util/util.clj b/src/clj/commiteth/util/util.clj index ca5804b..b110ea6 100644 --- a/src/clj/commiteth/util/util.clj +++ b/src/clj/commiteth/util/util.clj @@ -1,5 +1,8 @@ (ns commiteth.util.util) -(defn decimal->str [n] +(defn eth-decimal->str [n] (format "%.4f" n)) + +(defn usd-decimal->str [n] + (format "%.2f" n)) diff --git a/src/cljs/commiteth/activity.cljs b/src/cljs/commiteth/activity.cljs index e4d57b7..df32e62 100644 --- a/src/cljs/commiteth/activity.cljs +++ b/src/cljs/commiteth/activity.cljs @@ -6,7 +6,7 @@ (defn item-description [{:keys [display-name - balance + value-usd issue-title item-type repo-owner @@ -17,19 +17,22 @@ issue-title]] (case item-type "new-bounty" [:div "New bounty opened for issue " issue-link] - "claim-payout" [:div "Received ETH " balance + "claim-payout" [:div "Received USD " value-usd " for " issue-link] "open-claim" [:div "Submitted a claim for " issue-link] - "balance-update" [:div issue-link " bounty increased to ETH " balance] + "balance-update" [:div issue-link " bounty increased to USD " value-usd] ""))) (defn activity-item [{:keys [avatar-url display-name updated - balance + value-usd + balance-eth issue-title - item-type] :as item}] + item-type + tokens] :as item}] + (println item) [:div.item.activity-item [:div.ui.mini.circular.image [:img {:src avatar-url}]] @@ -39,7 +42,9 @@ [item-description item]] [:div.footer-row (when-not (= item-type "new-bounty") - [:div.balance-badge (str "ETH " balance )]) + (for [[tla balance] (merge tokens {:ETH balance-eth})] + [:div.balance-badge + (str (subs (str tla) 1) " " balance)])) [:div.time (moment-timestamp updated)]]]]) diff --git a/src/cljs/commiteth/bounties.cljs b/src/cljs/commiteth/bounties.cljs index 604f31c..35fb69f 100644 --- a/src/cljs/commiteth/bounties.cljs +++ b/src/cljs/commiteth/bounties.cljs @@ -5,14 +5,15 @@ (defn bounty-item [bounty] - (println bounty) (let [{avatar-url :repo_owner_avatar_url owner :repo_owner repo-name :repo_name issue-title :issue_title issue-number :issue_number updated :updated - balance :balance} bounty + tokens :tokens + balance-eth :balance-eth + value-usd :value_usd} bounty full-repo (str owner "/" repo-name) issue-link [:a {:href (issue-url owner repo-name issue-number)} @@ -25,7 +26,9 @@ [:div.description issue-link] [:div.footer-row - [:div.balance-badge (str "ETH " balance )] + (for [[tla balance] (merge tokens {:ETH balance-eth})] + [:div.balance-badge + (str (subs (str tla) 1) " " balance)]) [:div.time (moment-timestamp updated)]]]])) (defn bounties-list [open-bounties] diff --git a/src/cljs/commiteth/core.cljs b/src/cljs/commiteth/core.cljs index ffb4fab..41baa3c 100644 --- a/src/cljs/commiteth/core.cljs +++ b/src/cljs/commiteth/core.cljs @@ -130,7 +130,7 @@ [:img {:src (:avatar-url hunter)}]] [:div.content [:div.header (:display-name hunter)] - [:div.description (str "ETH " (:total-eth hunter))]]]) + [:div.description (str "USD " (:total-usd hunter))]]]) @top-hunters)))))) (defn page []