diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 88cbca7..c91e036 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -207,6 +207,7 @@ SELECT i.title AS issue_title, i.repo_id AS repo_id, i.balance AS balance, + i.confirm_hash AS confirm_hash, p.pr_id AS pr_id, p.user_id AS user_id, p.pr_number AS pr_number, @@ -214,7 +215,8 @@ SELECT u.login AS user_login, u.name AS user_name, r.login AS owner_name, - r.repo AS repo_name + r.repo AS repo_name, + o.address AS owner_address FROM issues i INNER JOIN pull_requests p ON (p.commit_id = i.commit_id OR coalesce(p.issue_number, -1) = i.issue_number) @@ -223,6 +225,8 @@ FROM issues i ON u.id = p.user_id INNER JOIN repositories r ON r.repo_id = i.repo_id + INNER JOIN users o + ON r.user_id = o.id WHERE r.user_id = :owner_id; -- :name owner-issues-list :? :* diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index f8542f7..4325659 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -57,10 +57,12 @@ (ok (repositories/get-enabled (:id user)))) (GET "/bounties" [] (ok (bounties/list-all-bounties))) - (GET "/issues" [] + (GET "/user/bounties" [] :auth-rules authenticated? :current-user user - (ok (map #(conj % {:balance-eth (eth/hex->eth (:balance %) 6)}) + (ok (map #(conj % (let [balance (:balance %)] + {:balance-eth (eth/hex->eth balance 6) + :balance-wei (eth/hex->big-integer balance)})) (bounties/list-owner-bounties (:id user))))) (POST "/repository/toggle" {:keys [params]} :auth-rules authenticated? diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 19570cb..7319ffb 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -33,7 +33,7 @@ :dispatch-n [[:load-user-profile] [:load-user-repos] [:load-enabled-repos] - [:load-issues]]})) + [:load-owner-bounties]]})) (reg-event-fx :load-bounties @@ -49,11 +49,11 @@ (assoc db :all-bounties bounties))) (reg-event-fx - :load-issues + :load-owner-bounties (fn [{:keys [db]} [_]] {:db db :http {:method GET - :url "/api/issues" + :url "/api/user/bounties" :on-success #(dispatch [:set-owner-bounties %])}})) (reg-event-db diff --git a/src/cljs/commiteth/manage.cljs b/src/cljs/commiteth/manage.cljs index a624f60..36157fa 100644 --- a/src/cljs/commiteth/manage.cljs +++ b/src/cljs/commiteth/manage.cljs @@ -27,12 +27,28 @@ [:div (map repository-row @repos)]))) +(defn send-transaction + [issue] + (fn [] + (let [{owner-address :owner_address + contract-address :contract_address + confirm-hash :confirm_hash} issue + eth (.-eth js/web3) + payload {:from owner-address + :to contract-address + :value 1 + :data (str "0x797af627" confirm-hash)}] + (println "sending transaction" payload) + (.sendTransaction eth (clj->js payload) + #(println "send-transaction callback" %))))) + (defn issue-row [{title :issue_title issue-id :issue_id issue-number :issue_number owner :owner_name repo :repo_name - balance :balance-eth}] + balance :balance-eth + :as issue}] ^{:key issue-id} [:li.issue [:div.d-table.table-fixed.width-full @@ -52,7 +68,8 @@ {:type "submit" :style {:margin-top "7px" :margin-right "7px"} - :on-click #(println %)} + :disabled (not (exists? js/web3)) + :on-click (send-transaction issue)} (str "Sign and send " balance " ETH")] [:div.float-left.col-9.p-3.lh-condensed [:span.mr-2.float-right.text-gray.text-small