From b25e01f14decbb21e66c285cd4552e506a2948a4 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Fri, 17 Mar 2017 22:59:03 +0200 Subject: [PATCH] Simple "open bounties" view * add simple tab for showing all open bounties (#37). Probably needs some UX improvements * rename old "bounties" tab to "manage payouts" * fix issues in db migration --- .../20170317210604-user-stats.up.sql | 4 +- resources/sql/queries.sql | 47 ++++++++++--------- src/clj/commiteth/db/bounties.clj | 19 ++++---- src/clj/commiteth/routes/services.clj | 5 +- src/cljs/commiteth/core.cljs | 11 +++-- src/cljs/commiteth/db.cljs | 33 ++++++------- .../{bounties.cljs => manage_payouts.cljs} | 5 +- src/cljs/commiteth/subscriptions.cljs | 4 +- 8 files changed, 65 insertions(+), 63 deletions(-) rename src/cljs/commiteth/{bounties.cljs => manage_payouts.cljs} (95%) diff --git a/resources/migrations/20170317210604-user-stats.up.sql b/resources/migrations/20170317210604-user-stats.up.sql index 8c03bc7..60b57f6 100644 --- a/resources/migrations/20170317210604-user-stats.up.sql +++ b/resources/migrations/20170317210604-user-stats.up.sql @@ -1,12 +1,12 @@ -drop table usage_metrics; +drop table if exists usage_metrics; CREATE TABLE usage_metrics ( registered_users int, users_with_address int, change_timestamp timestamp without time zone DEFAULT timezone('utc'::text, now())); - +drop function if exists store_usage_metrics() cascade; CREATE OR REPLACE FUNCTION store_usage_metrics() RETURNS TRIGGER AS $usage_metrics$ BEGIN insert into usage_metrics (registered_users, users_with_address) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index baeb126..56feaa4 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -293,7 +293,31 @@ updated = timezone('utc'::text, now()) WHERE issue_id = :issue_id; --- :name owner-bounties-list :? :* +-- :name open-bounties :? :* +-- :doc all bounty issues for given owner +SELECT + i.contract_address AS contract_address, + i.issue_id AS issue_id, + i.issue_number AS issue_number, + i.title AS issue_title, + i.repo_id AS repo_id, + i.balance AS balance, + i.confirm_hash AS confirm_hash, + i.payout_hash AS payout_hash, + i.payout_receipt AS payout_receipt, + i.updated AS updated, + r.owner AS repo_owner, + r.owner_avatar_url AS repo_owner_avatar_url, + r.repo AS repo_name +FROM issues i, repositories r +WHERE +r.repo_id = i.repo_id +AND i.confirm_hash is null +ORDER BY balance desc, updated desc; + + + +-- :name owner-bounties :? :* -- :doc all bounty issues for given owner SELECT i.contract_address AS contract_address, @@ -348,27 +372,6 @@ AND r.user_id = o.id AND i.issue_id = :issue_id; - --- :name owner-issues-list :? :* --- :doc owner's bounty issues with no merged PR -SELECT - i.contract_address AS contract_address, - i.issue_id AS issue_id, - i.issue_number AS issue_number, - i.title AS issue_title, - i.repo_id AS repo_id, - r.owner AS repo_owner, - r.repo AS repo_name -FROM issues i, repositories r -WHERE r.repo_id = i.repo_id -AND r.user_id = :owner_id -AND i.commit_sha IS NULL -AND NOT exists(SELECT 1 - FROM pull_requests - WHERE issue_number = i.issue_number - AND state = 1); - - -- :name open-bounty-contracts :? :* -- :doc bounty issues with mined bounty contracts SELECT diff --git a/src/clj/commiteth/db/bounties.clj b/src/clj/commiteth/db/bounties.clj index 91c1c2c..9a072b4 100644 --- a/src/clj/commiteth/db/bounties.clj +++ b/src/clj/commiteth/db/bounties.clj @@ -10,21 +10,20 @@ (jdbc/with-db-connection [con-db *db*] (db/pending-contracts con-db))) -(defn list-owner-bounties - [owner] +(defn owner-bounties + [owner-id] (jdbc/with-db-connection [con-db *db*] - (db/owner-bounties-list con-db {:owner_id owner}))) + (db/owner-bounties con-db {:owner_id owner-id}))) + +(defn open-bounties + [] + (jdbc/with-db-connection [con-db *db*] + (db/open-bounties con-db))) (defn bounty-claims [issue-id] (jdbc/with-db-connection [con-db *db*] - (db/bounty-claims con-db { - :issue_id issue-id}))) - -(defn list-not-fixed-issues - [owner-id] - (jdbc/with-db-connection [con-db *db*] - (db/owner-issues-list con-db {:owner_id owner-id}))) + (db/bounty-claims con-db {:issue_id issue-id}))) (defn pending-bounties-list [] diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 91f254d..d9e01e9 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -105,7 +105,7 @@ (format "%.4f" n)) (defn user-bounties [user] - (let [owner-bounties (bounties-db/list-owner-bounties (:id user))] + (let [owner-bounties (bounties-db/owner-bounties (:id user))] (into {} (for [ob owner-bounties :let [b (update ob :balance decimal->str)]] @@ -156,6 +156,9 @@ (GET "/activity-feed" [] (log/debug "/activity-feed") (ok (activity-feed))) + (GET "/open-bounties" [] + (log/debug "/open-bounties") + (ok (bounties-db/open-bounties))) (context "/user" [] (GET "/" [] :auth-rules authenticated? diff --git a/src/cljs/commiteth/core.cljs b/src/cljs/commiteth/core.cljs index 147c302..f9cdafa 100644 --- a/src/cljs/commiteth/core.cljs +++ b/src/cljs/commiteth/core.cljs @@ -10,8 +10,9 @@ [commiteth.handlers] [commiteth.subscriptions] [commiteth.activity :refer [activity-page]] - [commiteth.repos :refer [repos-page]] [commiteth.bounties :refer [bounties-page]] + [commiteth.repos :refer [repos-page]] + [commiteth.manage-payouts :refer [manage-payouts-page]] [commiteth.update-address :refer [update-address-page]] [commiteth.common :refer [input]] [commiteth.config :as config] @@ -72,8 +73,9 @@ (fn [] (let [tabs (apply conj [[:activity "Activity"]] (when @user - [[:repos "Repositories"] - [:bounties "Bounties"]]))] + [[:bounties "Open bounties"] + [:repos "Repositories"] + [:manage-payouts "Manage Payouts"]]))] (into [:div.ui.attached.tabular.menu.tiny.commiteth-tabs] (for [[page caption] tabs] (let [props {:class (str "ui item" @@ -105,8 +107,9 @@ (def pages {:activity #'activity-page - :repos #'repos-page :bounties #'bounties-page + :repos #'repos-page + :manage-payouts #'manage-payouts-page :update-address #'update-address-page}) diff --git a/src/cljs/commiteth/db.cljs b/src/cljs/commiteth/db.cljs index 50eab52..efc1824 100644 --- a/src/cljs/commiteth/db.cljs +++ b/src/cljs/commiteth/db.cljs @@ -5,24 +5,19 @@ :user nil :repos-loading? false :repos {} + :open-bounties [{:confirm_hash nil, + :issue_id 207799767, + :issue_number 19, + :repo_name "commiteth", + :updated #inst "2017-03-16T18:32:43.113-00:00", + :issue_title "Estimate gas instead of hard-coding", + :repo_owner "status-im", + :repo_owner_avatar_url "https://avatars2.githubusercontent.com/u/11767950?v=3" + :balance 0.0M, + :payout_receipt nil, + :repo_id 65593470, + :contract_address "0xaf77604e06169b210158f00ad4d3ef028aecded9", + :payout_hash nil}] :owner-bounties {} :top-hunters [] - :activity-feed [] #_[{:type :create-bounty - :user {:display-name "Dummy User" - :avatar-url "https://randomuser.me/api/portraits/men/6.jpg"} - :issue-title "Feature X" - :issue-url "https://github.com/foo/bar/issues/2" - :timestamp "1 day ago"} - {:type :submit-claim - :user {:display-name "Place Holder" - :avatar-url "https://randomuser.me/api/portraits/men/4.jpg"} - :balance-eth "15" - :timestamp "2 days ago"} - {:type :balance-update - :user {:display-name "Place Holder" - :avatar-url "https://randomuser.me/api/portraits/men/4.jpg"} - - :issue-title "Feature Y" - :issue-url "https://github.com/foo/bar/issues/1" - :balance-eth "15" - :timestamp "2 days ago"}]}) + :activity-feed []}) diff --git a/src/cljs/commiteth/bounties.cljs b/src/cljs/commiteth/manage_payouts.cljs similarity index 95% rename from src/cljs/commiteth/bounties.cljs rename to src/cljs/commiteth/manage_payouts.cljs index 0cef000..910ac8c 100644 --- a/src/cljs/commiteth/bounties.cljs +++ b/src/cljs/commiteth/manage_payouts.cljs @@ -1,4 +1,4 @@ -(ns commiteth.bounties +(ns commiteth.manage-payouts (:require [re-frame.core :as rf] [commiteth.common :refer [moment-timestamp]])) @@ -19,7 +19,6 @@ paid? (not-empty (:payout_hash claim)) confirming? (:confirming? bounty) updated (:updated bounty)] - (println "paid?" paid? "merged?" merged? (and merged? ((comp not) paid?))) [:div.activity-item [:div.ui.grid.container [:div.left-column @@ -56,7 +55,7 @@ [claim-card bounty claim])))) -(defn bounties-page [] +(defn manage-payouts-page [] (let [owner-bounties (rf/subscribe [:owner-bounties])] (fn [] (let [web3 (.-web3 js/window) diff --git a/src/cljs/commiteth/subscriptions.cljs b/src/cljs/commiteth/subscriptions.cljs index eb10d9b..08e4b67 100644 --- a/src/cljs/commiteth/subscriptions.cljs +++ b/src/cljs/commiteth/subscriptions.cljs @@ -27,9 +27,9 @@ (:flash-message db))) (reg-sub - :all-bounties + :open-bounties (fn [db _] - (:all-bounties db))) + (:open-bounties db))) (reg-sub :owner-bounties