Require Ethereum address for toggling repos

* do not allow toggling of repositories without a saved Ethereum
  address (Fixes: #20)
* fix react warning on activity view
* fix bugs in payout related re-frame handlers
* project file tweaks
This commit is contained in:
Teemu Patja 2017-03-03 10:19:28 +02:00
parent 9f010648aa
commit 442f5c7821
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
5 changed files with 37 additions and 26 deletions

View File

@ -44,7 +44,8 @@
[pandect "0.6.1"] [pandect "0.6.1"]
[prismatic/plumbing "0.5.3"] [prismatic/plumbing "0.5.3"]
[cljsjs/moment "2.17.1-0"] [cljsjs/moment "2.17.1-0"]
[org.clojure/tools.nrepl "0.2.12"]] [org.clojure/tools.nrepl "0.2.12"]
[com.cemerick/piggieback "0.2.2-SNAPSHOT"]]
:min-lein-version "2.0.0" :min-lein-version "2.0.0"
:source-paths ["src/clj" "src/cljc"] :source-paths ["src/clj" "src/cljc"]
@ -131,7 +132,8 @@
:doo {:build "test"} :doo {:build "test"}
:source-paths ["env/dev/clj" "test/clj"] :source-paths ["env/dev/clj" "test/clj"]
:resource-paths ["env/dev/resources"] :resource-paths ["env/dev/resources"]
:repl-options {:init-ns user} :repl-options {:init-ns user
:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:injections [(require 'pjstadig.humane-test-output) :injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]} (pjstadig.humane-test-output/activate!)]}
:test {:resource-paths ["env/dev/resources" "env/test/resources"] :test {:resource-paths ["env/dev/resources" "env/test/resources"]

View File

@ -64,7 +64,11 @@
{repo-id :id {repo-id :id
full-repo :full_name full-repo :full_name
repo :name} params repo :name} params
[owner _] (str/split full-repo #"/")] [owner _] (str/split full-repo #"/")
db-user (users/get-user (:id user))]
(if (empty? (:address db-user))
{:status 400
:body "Please add your ethereum address to your profile first"}
(try (try
(let [db-item (repositories/create (merge params {:user_id user-id (let [db-item (repositories/create (merge params {:user_id user-id
:owner owner})) :owner owner}))
@ -79,7 +83,7 @@
(log/info "exception when enabling repo " (log/info "exception when enabling repo "
(.getMessage e)) (.getMessage e))
(repositories/update-repo repo-id {:state -1}) (repositories/update-repo repo-id {:state -1})
(internal-server-error))))) (internal-server-error))))))
(defn in? [coll elem] (defn in? [coll elem]
(some #(= elem %) coll)) (some #(= elem %) coll))

View File

@ -16,11 +16,11 @@
{:href (issue-url repo-owner repo-name issue-number)} {:href (issue-url repo-owner repo-name issue-number)}
issue-title]] issue-title]]
(case item-type (case item-type
"new-bounty" [:p "Opened a bounty for " issue-link] "new-bounty" [:div "Opened a bounty for " issue-link]
"claim-payout" [:p "Received " [:span.balance "ETH " balance] "claim-payout" [:div "Received " [:span.balance "ETH " balance]
" for " issue-link] " for " issue-link]
"open-claim" [:p "Submitted a claim for " issue-link] "open-claim" [:div "Submitted a claim for " issue-link]
"balance-update" [:p issue-link " bounty increased to " "balance-update" [:div issue-link " bounty increased to "
[:div.balance balance]] [:div.balance balance]]
""))) "")))

View File

@ -46,6 +46,7 @@
(defn claim-list [bounties] (defn claim-list [bounties]
;; TODO: exclude bounties with no claims
(if (empty? bounties) (if (empty? bounties)
[:div.ui.text "No items"] [:div.ui.text "No items"]
(into [:div.activity-item-container] (into [:div.activity-item-container]

View File

@ -187,6 +187,7 @@
:url "/api/user/repository/toggle" :url "/api/user/repository/toggle"
:on-success #(dispatch [:repo-toggle-success %]) :on-success #(dispatch [:repo-toggle-success %])
:on-error #(dispatch [:repo-toggle-error repo %]) :on-error #(dispatch [:repo-toggle-error repo %])
:finally #(println "finally" %)
:params (select-keys repo [:id :owner :full_name :name])}})) :params (select-keys repo [:id :owner :full_name :name])}}))
@ -207,7 +208,10 @@
(:full_name repo) (:full_name repo)
{:busy? false})) {:busy? false}))
:dispatch [:set-flash-message :dispatch [:set-flash-message
:error (str "Failed to toggle repo: " (:status-text response))]})) :error (if (= 400 (:status response))
(:response response)
(str "Failed to toggle repo: "
(:status-text response)))]}))
(reg-event-fx (reg-event-fx
@ -281,12 +285,12 @@
:payout-confirmed :payout-confirmed
(fn [db [_ issue-id]] (fn [db [_ issue-id]]
(-> db (-> db
(dissoc-in [:owner-bounties (:issue_id issue) :confirming?] false) (dissoc-in [:owner-bounties (:issue_id issue-id) :confirming?])
(assoc-in [:owner-bounties (:issue_id issue) :confirmed?] true)))) (assoc-in [:owner-bounties (:issue_id issue-id) :confirmed?] true))))
(reg-event-db (reg-event-db
:payout-confirm-failed :payout-confirm-failed
(fn [db [_ issue-id]] (fn [db [_ issue-id]]
(-> db (-> db
(dissoc-in [:owner-bounties (:issue_id issue) :confirming?] false) (dissoc-in [:owner-bounties (:issue_id issue-id) :confirming?])
(assoc-in [:owner-bounties (:issue_id issue) :confirm-failed?] true)))) (assoc-in [:owner-bounties (:issue_id issue-id) :confirm-failed?] true))))