From 264a83c38497ec1b17fe51272def6a71e81e955e Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 26 Dec 2017 18:14:54 +0300 Subject: [PATCH 01/28] 193 gitignore files added + readme updated --- .gitignore | 3 +++ README.md | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0e3eb683..178a289c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ profiles.clj resources/contracts node_modules .DS_Store +src/java +yarn.lock +/config.edn diff --git a/README.md b/README.md index eedcafd5..f73ecc20 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,13 @@ Web3j [2.3.0](https://github.com/web3j/web3j/releases/tag/v2.3.0) is required an ## Running -Make sure `env/dev/resources/config.edn` is correctly populated. +Prepare your local git-ignored config file: + +``` +cp env/dev/resources/config.edn config.edn +``` + +Make sure `config.edn` is correctly populated. Lauch a local geth node with the bot account unlocked: From 7dbd327a3ca3c31d805070e028f53f8182aaf9b3 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 26 Dec 2017 18:19:20 +0300 Subject: [PATCH 02/28] 193 makefile added --- Makefile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..68a2a23d --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ + +all: uberjar + +.PHONY: contracts +contracts: + ./build_contracts.sh + +less: + lein less once + +less-auto: + lein less auto + +repl: + lein repl + +uberjar: + lein uberjar + +yarn: + yarn install + +cljsbuild: yarn + lein cljsbuild once + +figwheel: yarn + rlwrap lein figwheel + +.PHONY: test +test: + lein test + +migrate: + lein migratus migrate + +create-migration: + @read -p "Enter migration name: " migration \ + && lein migratus create $$migration + +orig: + find . -name '*.orig' -delete From 460eab8f701b844c43276ccb9d5d3f00e5c0d745 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 26 Dec 2017 18:25:29 +0300 Subject: [PATCH 03/28] 193 sql migrations added --- resources/migrations/20171226182259-hide-user.down.sql | 6 ++++++ resources/migrations/20171226182259-hide-user.up.sql | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 resources/migrations/20171226182259-hide-user.down.sql create mode 100644 resources/migrations/20171226182259-hide-user.up.sql diff --git a/resources/migrations/20171226182259-hide-user.down.sql b/resources/migrations/20171226182259-hide-user.down.sql new file mode 100644 index 00000000..e11839ca --- /dev/null +++ b/resources/migrations/20171226182259-hide-user.down.sql @@ -0,0 +1,6 @@ +begin; + +alter table users + drop column is_hidden; + +commit; diff --git a/resources/migrations/20171226182259-hide-user.up.sql b/resources/migrations/20171226182259-hide-user.up.sql new file mode 100644 index 00000000..96b7fc77 --- /dev/null +++ b/resources/migrations/20171226182259-hide-user.up.sql @@ -0,0 +1,6 @@ +begin; + +alter table users + add column is_hidden boolean not null default false; + +commit; From 287922dce878a9b3215f6bec38b4632e70daaf82 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 26 Dec 2017 18:34:24 +0300 Subject: [PATCH 04/28] 193 cider plugin removed --- project.clj | 2 -- 1 file changed, 2 deletions(-) diff --git a/project.clj b/project.clj index 9a0ea358..ae4d2452 100644 --- a/project.clj +++ b/project.clj @@ -69,10 +69,8 @@ [lein-auto "0.1.2"] [lein-less "1.7.5"] [lein-shell "0.5.0"] - [cider/cider-nrepl "0.15.0-SNAPSHOT"] [lein-sha-version "0.1.1"]] - :less {:source-paths ["src/less"] :target-path "resources/public/css"} From 58de6ae3c67e0bb9bef868b3d6b47ba17e42d5cd Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 26 Dec 2017 18:59:38 +0300 Subject: [PATCH 05/28] 193 ignoring dev config --- .gitignore | 2 +- README.md | 3 ++- env/dev/resources/{config.edn => config.example.edn} | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename env/dev/resources/{config.edn => config.example.edn} (100%) diff --git a/.gitignore b/.gitignore index 178a289c..f5f86ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,4 @@ node_modules .DS_Store src/java yarn.lock -/config.edn +env/dev/resources/config.edn diff --git a/README.md b/README.md index f73ecc20..2ebf4b24 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ Web3j [2.3.0](https://github.com/web3j/web3j/releases/tag/v2.3.0) is required an Prepare your local git-ignored config file: ``` -cp env/dev/resources/config.edn config.edn +cd env/dev/resources +cp config.example.edn config.edn ``` Make sure `config.edn` is correctly populated. diff --git a/env/dev/resources/config.edn b/env/dev/resources/config.example.edn similarity index 100% rename from env/dev/resources/config.edn rename to env/dev/resources/config.example.edn From 0eba6fed2e65aee71d5ed2aa65ba200d9af566d5 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 26 Dec 2017 19:21:08 +0300 Subject: [PATCH 06/28] 193 start-end pairs added --- src/clj/commiteth/config.clj | 8 +++++++- src/clj/commiteth/core.clj | 16 +++++++++++----- src/clj/commiteth/db/core.clj | 13 +++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/clj/commiteth/config.clj b/src/clj/commiteth/config.clj index 9a284f26..9e76f7c0 100644 --- a/src/clj/commiteth/config.clj +++ b/src/clj/commiteth/config.clj @@ -1,10 +1,16 @@ (ns commiteth.config (:require [cprop.core :refer [load-config]] [cprop.source :as source] - [mount.core :refer [args defstate]])) + [mount.core :refer [args defstate] :as mount])) (defstate env :start (load-config :merge [(args) (source/from-system-props) (source/from-env)])) + +(defn start! [] + (mount/start #'env)) + +(defn stop! [] + (mount/stop #'env)) diff --git a/src/clj/commiteth/core.clj b/src/clj/commiteth/core.clj index e6177082..352bf1f6 100644 --- a/src/clj/commiteth/core.clj +++ b/src/clj/commiteth/core.clj @@ -16,17 +16,23 @@ :parse-fn #(Integer/parseInt %)]]) (mount/defstate -http-server + http-server :start (http/start - (-> env - (assoc :handler (handler/app)) - (update :port #(or (-> env :options :port) %)))) + (-> env + (assoc :handler (handler/app)) + (update :port #(or (-> env :options :port) %)))) :stop (http/stop http-server)) +(defn start! [] + (mount/start #'http-server)) + +(defn stop! [] + (mount/stop #'http-server)) + (mount/defstate ^{:on-reload :noop} -repl-server + repl-server :start (when-let [nrepl-port (env :nrepl-port)] (log/info "Starting NREPL server on port" nrepl-port) diff --git a/src/clj/commiteth/db/core.clj b/src/clj/commiteth/db/core.clj index a33f2e08..162c418a 100644 --- a/src/clj/commiteth/db/core.clj +++ b/src/clj/commiteth/db/core.clj @@ -4,7 +4,7 @@ [clojure.java.jdbc :as jdbc] [conman.core :as conman] [commiteth.config :refer [env]] - [mount.core :refer [defstate]] + [mount.core :refer [defstate] :as mount] [migratus.core :as migratus] [mpg.core :as mpg] [clojure.string :as str]) @@ -20,21 +20,26 @@ (mpg/patch) -(defn start [] +(defn db-start [] (let [db (env :jdbc-database-url) migratus-config {:store :database :migration-dir "migrations/" :migration-table-name "schema_migrations" :db db}] (migratus/migrate migratus-config) - (conman/bind-connection db "sql/queries.sql") (conman/connect! {:jdbc-url db}) db)) (defstate ^:dynamic *db* - :start (start) + :start (db-start) :stop (conman/disconnect! *db*)) +(defn start! [] + (mount/start #'*db*)) + +(defn stop! [] + (mount/stop #'*db*)) + (conman/bind-connection *db* "sql/queries.sql") (defn to-date [^java.sql.Date sql-date] From e44639ae8516382492ae0e61d83794bcc7c2f61f Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 18:20:24 +0300 Subject: [PATCH 07/28] 193 server handler added --- src/clj/commiteth/db/core.clj | 8 ++++++++ src/clj/commiteth/routes/services.clj | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/clj/commiteth/db/core.clj b/src/clj/commiteth/db/core.clj index 162c418a..0742d6b5 100644 --- a/src/clj/commiteth/db/core.clj +++ b/src/clj/commiteth/db/core.clj @@ -90,3 +90,11 @@ (sql-value [value] (to-pg-json value)) IPersistentVector (sql-value [value] (to-pg-json value))) + +(defmacro with-trx [& body] + "Performs a set of queries in transaction." + `(conman/with-transaction [*db*] + ~@body)) + +(defn update! [& args] + (apply jdbc/update! *db* args)) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 82c56334..fb35a924 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -5,6 +5,7 @@ [compojure.api.meta :refer [restructure-param]] [buddy.auth.accessrules :refer [restrict]] [buddy.auth :refer [authenticated?]] + [commiteth.db.core :as db] [commiteth.db.users :as users] [commiteth.db.usage-metrics :as usage-metrics] [commiteth.db.repositories :as repositories] @@ -234,6 +235,15 @@ (if (= 1 result) (ok) (internal-server-error))))) + + (POST "/hidden" [] + :auth-rules authenticated? + :body-params [user-id :- Long, hidden :- Boolean] + :summary "(Un)mark a user as being hidden (not visible in rating tables)." + (db/with-trx + (db/update! :users {:is_hidden hidden} ["id = ?" user-id])) + (ok)) + (GET "/repositories" {:keys [params]} :auth-rules authenticated? :current-user user From b77a2312ff9c23c4fb29c3e5d3e307788e8a80e0 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 18:27:40 +0300 Subject: [PATCH 08/28] 193 ui widget added --- src/cljs/commiteth/common.cljs | 15 +++++++++++++++ src/cljs/commiteth/handlers.cljs | 20 ++++++++++++++++++-- src/cljs/commiteth/update_address.cljs | 20 +++++++++++++++----- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/cljs/commiteth/common.cljs b/src/cljs/commiteth/common.cljs index 9d302f0f..6802845c 100644 --- a/src/cljs/commiteth/common.cljs +++ b/src/cljs/commiteth/common.cljs @@ -10,6 +10,21 @@ :value @val-ratom :on-change #(reset! val-ratom (-> % .-target .-value))})])) +(defn checkbox + "Common checkbox widget. Takes a boolean value wrapped into an atom + and updates its state when clicking in it. An additional `opt` map + is to override its attributes (class, id, etc)." + [val-atom & [opt]] + [:input + (merge + {:type :checkbox + :checked @val-atom + :on-change + (fn [e] + (let [value (-> e .-target .-checked)] + (reset! val-atom value)))} + opt)]) + (defn dropdown [props title val-ratom items] (fn [] (if (= 1 (count items)) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 528c116b..21717648 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -311,7 +311,6 @@ {:db db :dispatch [:set-active-page :update-address]})) - (reg-event-fx :save-user-address (fn [{:keys [db]} [_ user-id address]] @@ -320,7 +319,7 @@ :http {:method POST :url "/api/user/address" :on-success #(do - (dispatch [:assoc-in [:user [:address] address]]) + (dispatch [:assoc-in [:user :address] address]) (dispatch [:set-flash-message :success "Address saved"])) @@ -332,6 +331,23 @@ :finally #(dispatch [:clear-updating-address]) :params {:user-id user-id :address address}}})) +(reg-event-fx + :mark-user-hidden + (fn [{:keys [db]} [_ user-id hidden]] + {:http {:method POST + :url "/api/user/hidden" + :on-success #(do + (dispatch [:assoc-in [:user :is_hidden] hidden]) + (dispatch [:set-flash-message + :success + "Settings saved"])) + :on-error #(do + (dispatch [:set-flash-message + :error (:response %)])) + :params {:user-id user-id :hidden hidden}}})) + + + (reg-event-db :clear-updating-address (fn [db _] diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 6134bde7..2bc7d81a 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -1,21 +1,26 @@ (ns commiteth.update-address (:require [re-frame.core :as rf] - [commiteth.common :refer [input dropdown]] + [commiteth.common :refer [input dropdown checkbox]] [reagent.core :as r] [reagent.crypt :as crypt] [cljs-web3.eth :as web3-eth])) - (defn update-address-page [] (let [db (rf/subscribe [:db]) user (rf/subscribe [:user]) updating-address (rf/subscribe [:get-in [:updating-address]]) - address (r/atom @(rf/subscribe [:get-in [:user :address]]))] + address (r/atom @(rf/subscribe [:get-in [:user :address]])) + hidden (r/atom @(rf/subscribe [:get-in [:user :is_hidden]]))] + + (add-watch hidden + :default + (fn [_ _ _ new-val] + (rf/dispatch [:mark-user-hidden (:id @user) new-val]))) + (fn [] (let [web3 (:web3 @db) web3-accounts (when web3 (web3-eth/accounts web3))] - (println "web3-accounts" web3-accounts) [:div.ui.container.grid [:div.ui.form.sixteen.wide.column [:h3 "Update address"] @@ -41,4 +46,9 @@ :class (str "ui button small update-address-button" (when @updating-address " busy loading"))}) - "UPDATE"]]])))) + "UPDATE"] + + [:h3 "Settings"] + [:div + [checkbox hidden {:id :input-hidden}] + [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) From bea4321ca4eea71de8483a4fb30f0531051ddd4a Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 18:47:37 +0300 Subject: [PATCH 09/28] 193 migrations updated --- .../20171226182259-hide-user.down.sql | 37 +++++++++++++++++-- .../20171226182259-hide-user.up.sql | 37 +++++++++++++++++-- resources/sql/queries.sql | 1 + 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/resources/migrations/20171226182259-hide-user.down.sql b/resources/migrations/20171226182259-hide-user.down.sql index e11839ca..3706d483 100644 --- a/resources/migrations/20171226182259-hide-user.down.sql +++ b/resources/migrations/20171226182259-hide-user.down.sql @@ -1,6 +1,35 @@ -begin; +BEGIN; -alter table users - drop column is_hidden; +ALTER TABLE users + DROP COLUMN is_hidden; -commit; +-- restore the previous version of the view +CREATE OR REPLACE VIEW "public"."claims_view" AS +SELECT + i.title AS issue_title, + i.issue_number, + r.repo AS repo_name, + r.owner AS repo_owner, + COALESCE(u.name, u.login) AS user_name, + u.avatar_url AS user_avatar_url, + i.payout_receipt, + p.updated, + i.updated AS issue_updated, + i.balance_eth, + i.tokens, + i.value_usd, + p.state AS pr_state, + i.is_open AS issue_open, + (case when u.address IS NULL THEN false ELSE true END) AS user_has_address + FROM issues i, + users u, + repositories r, + pull_requests p + WHERE r.repo_id = i.repo_id + AND p.issue_id = i.issue_id + AND p.user_id = u.id + AND i.contract_address IS NOT NULL + AND i.comment_id IS NOT NULL + ORDER BY p.updated; + +COMMIT; diff --git a/resources/migrations/20171226182259-hide-user.up.sql b/resources/migrations/20171226182259-hide-user.up.sql index 96b7fc77..29771802 100644 --- a/resources/migrations/20171226182259-hide-user.up.sql +++ b/resources/migrations/20171226182259-hide-user.up.sql @@ -1,6 +1,35 @@ -begin; +BEGIN; -alter table users - add column is_hidden boolean not null default false; +ALTER TABLE users + ADD COLUMN is_hidden BOOLEAN NOT NULL DEFAULT FALSE; -commit; +CREATE OR REPLACE VIEW "public"."claims_view" AS +SELECT + i.title AS issue_title, + i.issue_number, + r.repo AS repo_name, + r.owner AS repo_owner, + COALESCE(u.name, u.login) AS user_name, + u.avatar_url AS user_avatar_url, + i.payout_receipt, + p.updated, + i.updated AS issue_updated, + i.balance_eth, + i.tokens, + i.value_usd, + p.state AS pr_state, + i.is_open AS issue_open, + (case when u.address IS NULL THEN false ELSE true END) AS user_has_address + FROM issues i, + users u, + repositories r, + pull_requests p + WHERE r.repo_id = i.repo_id + AND p.issue_id = i.issue_id + AND p.user_id = u.id + AND i.contract_address IS NOT NULL + AND i.comment_id IS NOT NULL + AND NOT u.is_hidden -- added + ORDER BY p.updated; + +COMMIT; diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index e8a31154..9d9acf2d 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -571,6 +571,7 @@ WHERE pr.commit_sha = i.commit_sha AND u.id = pr.user_id AND i.payout_receipt IS NOT NULL +AND NOT u.is_hidden GROUP BY u.id ORDER BY total_usd DESC LIMIT 5; From fea8d4f0b5f1167042631efb31c079bf4a4280c0 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 19:01:27 +0300 Subject: [PATCH 10/28] 193 style added --- src/less/style.less | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/less/style.less b/src/less/style.less index 2c0c2e49..516c60c2 100644 --- a/src/less/style.less +++ b/src/less/style.less @@ -46,12 +46,20 @@ } } +label[for="input-hidden"] { + padding-left: 8px; +} + +#input-hidden { + vertical-align: bottom; + position: relative; + top: -4px; +} .login-button { background-color: rgba(255,255,255,0.2)!important; } - .commiteth-header { background-color: #57a7ed!important; border-radius: 0em; From 559f4f4212959474e16b9d035cd0b05af1904408 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 21:04:32 +0300 Subject: [PATCH 11/28] 193 checkbox updated --- src/cljs/commiteth/common.cljs | 15 --------------- src/cljs/commiteth/update_address.cljs | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/cljs/commiteth/common.cljs b/src/cljs/commiteth/common.cljs index 6802845c..9d302f0f 100644 --- a/src/cljs/commiteth/common.cljs +++ b/src/cljs/commiteth/common.cljs @@ -10,21 +10,6 @@ :value @val-ratom :on-change #(reset! val-ratom (-> % .-target .-value))})])) -(defn checkbox - "Common checkbox widget. Takes a boolean value wrapped into an atom - and updates its state when clicking in it. An additional `opt` map - is to override its attributes (class, id, etc)." - [val-atom & [opt]] - [:input - (merge - {:type :checkbox - :checked @val-atom - :on-change - (fn [e] - (let [value (-> e .-target .-checked)] - (reset! val-atom value)))} - opt)]) - (defn dropdown [props title val-ratom items] (fn [] (if (= 1 (count items)) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 2bc7d81a..e0153c85 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -1,6 +1,6 @@ (ns commiteth.update-address (:require [re-frame.core :as rf] - [commiteth.common :refer [input dropdown checkbox]] + [commiteth.common :refer [input dropdown]] [reagent.core :as r] [reagent.crypt :as crypt] [cljs-web3.eth :as web3-eth])) @@ -10,12 +10,7 @@ user (rf/subscribe [:user]) updating-address (rf/subscribe [:get-in [:updating-address]]) address (r/atom @(rf/subscribe [:get-in [:user :address]])) - hidden (r/atom @(rf/subscribe [:get-in [:user :is_hidden]]))] - - (add-watch hidden - :default - (fn [_ _ _ new-val] - (rf/dispatch [:mark-user-hidden (:id @user) new-val]))) + hidden (rf/subscribe [:get-in [:user :is_hidden]])] (fn [] (let [web3 (:web3 @db) @@ -50,5 +45,14 @@ [:h3 "Settings"] [:div - [checkbox hidden {:id :input-hidden}] + + [:input + {:type :checkbox + :id :input-hidden + :checked @hidden + :on-change + (fn [e] + (let [value (-> e .-target .-checked)] + (rf/dispatch [:mark-user-hidden (:id @user) value])))}] + [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) From 78d8b2885d34ae22c473ab60e608f82b3d365e74 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 21:07:42 +0300 Subject: [PATCH 12/28] 193 transaction removed --- src/clj/commiteth/routes/services.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index fb35a924..e36a7ae7 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -240,8 +240,7 @@ :auth-rules authenticated? :body-params [user-id :- Long, hidden :- Boolean] :summary "(Un)mark a user as being hidden (not visible in rating tables)." - (db/with-trx - (db/update! :users {:is_hidden hidden} ["id = ?" user-id])) + (db/update! :users {:is_hidden hidden} ["id = ?" user-id]) (ok)) (GET "/repositories" {:keys [params]} From 085e8ef844002322d14a236de7fe3b1438d148dc Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 31 Jan 2018 17:13:33 +0300 Subject: [PATCH 13/28] 193 rolled back --- .gitignore | 2 -- Makefile | 41 ----------------------------------- README.md | 9 +------- project.clj | 1 + src/clj/commiteth/config.clj | 8 +------ src/clj/commiteth/core.clj | 16 +++++--------- src/clj/commiteth/db/core.clj | 12 +++------- 7 files changed, 11 insertions(+), 78 deletions(-) delete mode 100644 Makefile diff --git a/.gitignore b/.gitignore index f5f86ee0..f14b872b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,4 @@ profiles.clj resources/contracts node_modules .DS_Store -src/java -yarn.lock env/dev/resources/config.edn diff --git a/Makefile b/Makefile deleted file mode 100644 index 68a2a23d..00000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ - -all: uberjar - -.PHONY: contracts -contracts: - ./build_contracts.sh - -less: - lein less once - -less-auto: - lein less auto - -repl: - lein repl - -uberjar: - lein uberjar - -yarn: - yarn install - -cljsbuild: yarn - lein cljsbuild once - -figwheel: yarn - rlwrap lein figwheel - -.PHONY: test -test: - lein test - -migrate: - lein migratus migrate - -create-migration: - @read -p "Enter migration name: " migration \ - && lein migratus create $$migration - -orig: - find . -name '*.orig' -delete diff --git a/README.md b/README.md index 2ebf4b24..eedcafd5 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,7 @@ Web3j [2.3.0](https://github.com/web3j/web3j/releases/tag/v2.3.0) is required an ## Running -Prepare your local git-ignored config file: - -``` -cd env/dev/resources -cp config.example.edn config.edn -``` - -Make sure `config.edn` is correctly populated. +Make sure `env/dev/resources/config.edn` is correctly populated. Lauch a local geth node with the bot account unlocked: diff --git a/project.clj b/project.clj index ae4d2452..fb6d0547 100644 --- a/project.clj +++ b/project.clj @@ -71,6 +71,7 @@ [lein-shell "0.5.0"] [lein-sha-version "0.1.1"]] + :less {:source-paths ["src/less"] :target-path "resources/public/css"} diff --git a/src/clj/commiteth/config.clj b/src/clj/commiteth/config.clj index 9e76f7c0..9a284f26 100644 --- a/src/clj/commiteth/config.clj +++ b/src/clj/commiteth/config.clj @@ -1,16 +1,10 @@ (ns commiteth.config (:require [cprop.core :refer [load-config]] [cprop.source :as source] - [mount.core :refer [args defstate] :as mount])) + [mount.core :refer [args defstate]])) (defstate env :start (load-config :merge [(args) (source/from-system-props) (source/from-env)])) - -(defn start! [] - (mount/start #'env)) - -(defn stop! [] - (mount/stop #'env)) diff --git a/src/clj/commiteth/core.clj b/src/clj/commiteth/core.clj index 352bf1f6..e6177082 100644 --- a/src/clj/commiteth/core.clj +++ b/src/clj/commiteth/core.clj @@ -16,23 +16,17 @@ :parse-fn #(Integer/parseInt %)]]) (mount/defstate - http-server +http-server :start (http/start - (-> env - (assoc :handler (handler/app)) - (update :port #(or (-> env :options :port) %)))) + (-> env + (assoc :handler (handler/app)) + (update :port #(or (-> env :options :port) %)))) :stop (http/stop http-server)) -(defn start! [] - (mount/start #'http-server)) - -(defn stop! [] - (mount/stop #'http-server)) - (mount/defstate ^{:on-reload :noop} - repl-server +repl-server :start (when-let [nrepl-port (env :nrepl-port)] (log/info "Starting NREPL server on port" nrepl-port) diff --git a/src/clj/commiteth/db/core.clj b/src/clj/commiteth/db/core.clj index 0742d6b5..fa5deb79 100644 --- a/src/clj/commiteth/db/core.clj +++ b/src/clj/commiteth/db/core.clj @@ -4,7 +4,7 @@ [clojure.java.jdbc :as jdbc] [conman.core :as conman] [commiteth.config :refer [env]] - [mount.core :refer [defstate] :as mount] + [mount.core :refer [defstate]] [migratus.core :as migratus] [mpg.core :as mpg] [clojure.string :as str]) @@ -20,7 +20,7 @@ (mpg/patch) -(defn db-start [] +(defn start [] (let [db (env :jdbc-database-url) migratus-config {:store :database :migration-dir "migrations/" @@ -31,15 +31,9 @@ db)) (defstate ^:dynamic *db* - :start (db-start) + :start (start) :stop (conman/disconnect! *db*)) -(defn start! [] - (mount/start #'*db*)) - -(defn stop! [] - (mount/stop #'*db*)) - (conman/bind-connection *db* "sql/queries.sql") (defn to-date [^java.sql.Date sql-date] From 07bb457dfa10d73e0812d34a2831f542b4cc4391 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 17:09:08 +0300 Subject: [PATCH 14/28] 193 user exists query added --- resources/sql/queries.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 9d9acf2d..082c636b 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -17,6 +17,12 @@ WHERE NOT exists(SELECT 1 WHERE id = :id) RETURNING id, login, name, email, avatar_url, address, created; +-- :name user-exists? :? :1 +-- :doc Checks where a user exists in the database. +select 1 +from users u +where u.id = :id; + -- :name update-user! :! :n -- :doc updates an existing user record UPDATE users From 50e3045a2c58d0e26c12b9ab831619f3d95d11d1 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 17:09:28 +0300 Subject: [PATCH 15/28] 193 address + hidden routes mixed --- src/clj/commiteth/routes/services.clj | 52 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index e36a7ae7..d71869c1 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -215,33 +215,45 @@ (do (log/debug "/usage-metrics" user) (ok (usage-metrics/usage-metrics-by-day)))) + (context "/user" [] + (GET "/" {:keys [params]} :auth-rules authenticated? :current-user user (ok (handle-get-user user (:token params)))) - (POST "/address" [] - :auth-rules authenticated? - :body-params [user-id :- Long, address :- String] - :summary "Update user address" - (if-not (eth/valid-address? address) - (do - (log/debug "POST /address: invalid input" address) - {:status 400 - :body (str "Invalid Ethereum address '" address "'")}) - (let [result (users/update-user-address - user-id - address)] - (if (= 1 result) - (ok) - (internal-server-error))))) - (POST "/hidden" [] + (POST "/" [] :auth-rules authenticated? - :body-params [user-id :- Long, hidden :- Boolean] - :summary "(Un)mark a user as being hidden (not visible in rating tables)." - (db/update! :users {:is_hidden hidden} ["id = ?" user-id]) - (ok)) + :current-user user + :body [body {:user-id s/Int + (s/optional-key :address) s/Str + (s/optional-key :is_hidden) s/Bool}] + :summary "Updates user's fields." + + (let [{:keys [user-id]} body + fields (select-keys body [:address :is_hidden])] + + (when-not (= (:id user) user-id) + (log/debugf "User %s tries to update user's %s fields" (:id user) user-id) + (forbidden! (format "Cannot access a user %s" user-id))) + + (when (empty? fields) + (bad-request! "No incoming fields were found.")) + + (when-let [address (:address fields)] + (when-not (eth/valid-address? address) + (log/debugf "POST /user: Wrong address %s" address) + (bad-request! (format "Invalid Ethereum address: %s" address)))) + + (db/with-trx + + (when-not (db/user-exists? {:user-id user}) + (not-found! "No such a user.")) + + (db/update! :users fields ["id = ?" user-id])) + + (ok))) (GET "/repositories" {:keys [params]} :auth-rules authenticated? From 8937816a8c830a8eb3119f0c2567b34fb284d253 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 19:58:26 +0300 Subject: [PATCH 16/28] 193 query field updated --- src/clj/commiteth/routes/services.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index d71869c1..fecf724c 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -248,7 +248,7 @@ (db/with-trx - (when-not (db/user-exists? {:user-id user}) + (when-not (db/user-exists? {:id user-id}) (not-found! "No such a user.")) (db/update! :users fields ["id = ?" user-id])) From 2b7dff964858f1ed9126e96f0e1c39d9874e7cfa Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 19:58:39 +0300 Subject: [PATCH 17/28] 193 UI updated --- src/cljs/commiteth/handlers.cljs | 53 +++++++++++--------------- src/cljs/commiteth/update_address.cljs | 11 +++--- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 21717648..c6cfdd97 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -62,6 +62,10 @@ (fn [db [_ path value]] (assoc-in db path value))) +(reg-event-db + :update-in + (fn [db [_ path func & args]] + (apply update-in db path func args))) (reg-event-db :set-active-page @@ -311,48 +315,35 @@ {:db db :dispatch [:set-active-page :update-address]})) -(reg-event-fx - :save-user-address - (fn [{:keys [db]} [_ user-id address]] - (prn "save-user-address" user-id address) - {:db (assoc db :updating-address true) - :http {:method POST - :url "/api/user/address" - :on-success #(do - (dispatch [:assoc-in [:user :address] address]) - (dispatch [:set-flash-message - :success - "Address saved"])) - :on-error #(do - (println %) - (dispatch [:set-flash-message - :error - (:response %)])) - :finally #(dispatch [:clear-updating-address]) - :params {:user-id user-id :address address}}})) (reg-event-fx - :mark-user-hidden - (fn [{:keys [db]} [_ user-id hidden]] - {:http {:method POST - :url "/api/user/hidden" + :save-user-fields + (fn [{:keys [db]} [_ user-id fields]] + (prn (merge {:user-id user-id} fields)) + {:dispatch [:set-updating-user] + :http {:method POST + :url "/api/user" :on-success #(do - (dispatch [:assoc-in [:user :is_hidden] hidden]) + (dispatch [:update-in [:user] merge fields]) (dispatch [:set-flash-message :success "Settings saved"])) - :on-error #(do - (dispatch [:set-flash-message - :error (:response %)])) - :params {:user-id user-id :hidden hidden}}})) - + :on-error #(dispatch [:set-flash-message + :error + (:response %)]) + :finally #(dispatch [:clear-updating-user]) + :params (merge {:user-id user-id} fields)}})) (reg-event-db - :clear-updating-address + :set-updating-user (fn [db _] - (dissoc db :updating-address))) + (assoc db :updating-user true))) +(reg-event-db + :clear-updating-user + (fn [db _] + (dissoc db :updating-user))) (reg-event-fx :save-payout-hash diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index e0153c85..77bea912 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -8,7 +8,7 @@ (defn update-address-page [] (let [db (rf/subscribe [:db]) user (rf/subscribe [:user]) - updating-address (rf/subscribe [:get-in [:updating-address]]) + updating-user (rf/subscribe [:get-in [:updating-user]]) address (r/atom @(rf/subscribe [:get-in [:user :address]])) hidden (rf/subscribe [:get-in [:user :is_hidden]])] @@ -35,11 +35,9 @@ :max-length 42}]])] [:button (merge {:on-click - #(rf/dispatch [:save-user-address - (:id @user) - @address]) + #(rf/dispatch [:save-user-fields (:id @user) {:address @address}]) :class (str "ui button small update-address-button" - (when @updating-address + (when @updating-user " busy loading"))}) "UPDATE"] @@ -48,11 +46,12 @@ [:input {:type :checkbox + :disabled @updating-user :id :input-hidden :checked @hidden :on-change (fn [e] (let [value (-> e .-target .-checked)] - (rf/dispatch [:mark-user-hidden (:id @user) value])))}] + (rf/dispatch [:save-user-fields (:id @user) {:is_hidden value}])))}] [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) From 6107fec01d57bc43423337965c178bd7b5bbd719 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 19:58:48 +0300 Subject: [PATCH 18/28] 193 gitignore fix --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index f14b872b..0e3eb683 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,3 @@ profiles.clj resources/contracts node_modules .DS_Store -env/dev/resources/config.edn From fb95fe6697ebbc0ec8c6675fcec5edb45572f551 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 20:01:19 +0300 Subject: [PATCH 19/28] 193 print removed --- src/cljs/commiteth/handlers.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index c6cfdd97..e9c6d4ae 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -319,7 +319,6 @@ (reg-event-fx :save-user-fields (fn [{:keys [db]} [_ user-id fields]] - (prn (merge {:user-id user-id} fields)) {:dispatch [:set-updating-user] :http {:method POST :url "/api/user" From c860db533a35b89ac06106d79dc802a5cf0852f8 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 20:08:23 +0300 Subject: [PATCH 20/28] 193 config.example deleted --- env/dev/resources/config.example.edn | 47 ---------------------------- 1 file changed, 47 deletions(-) delete mode 100644 env/dev/resources/config.example.edn diff --git a/env/dev/resources/config.example.edn b/env/dev/resources/config.example.edn deleted file mode 100644 index 1ee92642..00000000 --- a/env/dev/resources/config.example.edn +++ /dev/null @@ -1,47 +0,0 @@ -{:dev true - :port 3000 - ;; when :nrepl-port is set the application starts the nREPL server on load - :nrepl-port 7000 - :jdbc-database-url "jdbc:postgresql://localhost/commiteth?user=commiteth&password=commiteth" - ;; this needs to resolve to your local machine from the public internet - :server-address "http://PUBLIC-DNS:3000" - - ;; eth address of bot account - :eth-account "0x..." - :eth-password "XXX" - - ;; RPC URL to ethereum node to be used - :eth-rpc-url "http://localhost:8547" - :eth-wallet-file "/some/location" - - ;; address of token registry to be used - :tokenreg-addr "0x..." - ;; format of tokenreg records' base field, possible values :status, :parity - :tokenreg-base-format :parity - - ;; address of factory contract used for deploying bounty contracts - :contract-factory-addr "0x..." - - ;; commiteth-test-tpatja - :github-client-id "CLIENT ID" - :github-client-secret "CLIENT SECRET" - - ;; github username + password for bot account - :github-user "commiteth" - :github-password "XXX" - - ;; Add Github App webhook secret here to verify GH origin - :webhook-secret "XXX" - - ;; set to true when on Ropsten testnet - :on-testnet true - - ;; feature toggles - :add-bounties-for-existing-issues false - :hubspot-contact-create-enabled false - - ;; needeed when :hubspot-contact-create-enabled - :hubspot-api-key "xxxxxxx-xxxx-x-xxxx-xxxx" - - ;; used for blacklisting tokens from token registry data - :token-blacklist #{}} From b162bba9b35bc38073355979998a86bfa092733d Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 6 Feb 2018 20:10:08 +0300 Subject: [PATCH 21/28] 193 config file restored --- env/dev/resources/config.edn | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 env/dev/resources/config.edn diff --git a/env/dev/resources/config.edn b/env/dev/resources/config.edn new file mode 100644 index 00000000..1ee92642 --- /dev/null +++ b/env/dev/resources/config.edn @@ -0,0 +1,47 @@ +{:dev true + :port 3000 + ;; when :nrepl-port is set the application starts the nREPL server on load + :nrepl-port 7000 + :jdbc-database-url "jdbc:postgresql://localhost/commiteth?user=commiteth&password=commiteth" + ;; this needs to resolve to your local machine from the public internet + :server-address "http://PUBLIC-DNS:3000" + + ;; eth address of bot account + :eth-account "0x..." + :eth-password "XXX" + + ;; RPC URL to ethereum node to be used + :eth-rpc-url "http://localhost:8547" + :eth-wallet-file "/some/location" + + ;; address of token registry to be used + :tokenreg-addr "0x..." + ;; format of tokenreg records' base field, possible values :status, :parity + :tokenreg-base-format :parity + + ;; address of factory contract used for deploying bounty contracts + :contract-factory-addr "0x..." + + ;; commiteth-test-tpatja + :github-client-id "CLIENT ID" + :github-client-secret "CLIENT SECRET" + + ;; github username + password for bot account + :github-user "commiteth" + :github-password "XXX" + + ;; Add Github App webhook secret here to verify GH origin + :webhook-secret "XXX" + + ;; set to true when on Ropsten testnet + :on-testnet true + + ;; feature toggles + :add-bounties-for-existing-issues false + :hubspot-contact-create-enabled false + + ;; needeed when :hubspot-contact-create-enabled + :hubspot-api-key "xxxxxxx-xxxx-x-xxxx-xxxx" + + ;; used for blacklisting tokens from token registry data + :token-blacklist #{}} From a61885d5be908f95c4b8e1020cc30d4f13ac356a Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 7 Feb 2018 11:33:48 +0300 Subject: [PATCH 22/28] 193 get rid of passing user-id --- src/clj/commiteth/routes/services.clj | 9 ++------- src/cljs/commiteth/handlers.cljs | 4 ++-- src/cljs/commiteth/update_address.cljs | 5 ++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index fecf724c..26f6dc4c 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -226,18 +226,13 @@ (POST "/" [] :auth-rules authenticated? :current-user user - :body [body {:user-id s/Int - (s/optional-key :address) s/Str + :body [body {(s/optional-key :address) s/Str (s/optional-key :is_hidden) s/Bool}] :summary "Updates user's fields." - (let [{:keys [user-id]} body + (let [user-id (:id user) fields (select-keys body [:address :is_hidden])] - (when-not (= (:id user) user-id) - (log/debugf "User %s tries to update user's %s fields" (:id user) user-id) - (forbidden! (format "Cannot access a user %s" user-id))) - (when (empty? fields) (bad-request! "No incoming fields were found.")) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 549d22b0..c9c1c747 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -325,7 +325,7 @@ (reg-event-fx :save-user-fields - (fn [{:keys [db]} [_ user-id fields]] + (fn [{:keys [db]} [_ fields]] {:dispatch [:set-updating-user] :http {:method POST :url "/api/user" @@ -338,7 +338,7 @@ :error (:response %)]) :finally #(dispatch [:clear-updating-user]) - :params (merge {:user-id user-id} fields)}})) + :params fields}})) (reg-event-db diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 77bea912..c1ba88d8 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -7,7 +7,6 @@ (defn update-address-page [] (let [db (rf/subscribe [:db]) - user (rf/subscribe [:user]) updating-user (rf/subscribe [:get-in [:updating-user]]) address (r/atom @(rf/subscribe [:get-in [:user :address]])) hidden (rf/subscribe [:get-in [:user :is_hidden]])] @@ -35,7 +34,7 @@ :max-length 42}]])] [:button (merge {:on-click - #(rf/dispatch [:save-user-fields (:id @user) {:address @address}]) + #(rf/dispatch [:save-user-fields {:address @address}]) :class (str "ui button small update-address-button" (when @updating-user " busy loading"))}) @@ -52,6 +51,6 @@ :on-change (fn [e] (let [value (-> e .-target .-checked)] - (rf/dispatch [:save-user-fields (:id @user) {:is_hidden value}])))}] + (rf/dispatch [:save-user-fields {:is_hidden value}])))}] [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) From c66691ca2363dd4499569999320db01afd98d308 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Thu, 8 Feb 2018 15:27:46 +0300 Subject: [PATCH 23/28] 193 review fixes --- project.clj | 1 + .../migrations/20171226182259-hide-user.down.sql | 6 +++--- resources/migrations/20171226182259-hide-user.up.sql | 4 ++-- src/clj/commiteth/db/core.clj | 2 +- src/clj/commiteth/routes/services.clj | 8 +++----- src/cljs/commiteth/handlers.cljs | 11 +++++------ src/cljs/commiteth/update_address.cljs | 11 +++++------ 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/project.clj b/project.clj index ccb500f6..06784706 100644 --- a/project.clj +++ b/project.clj @@ -69,6 +69,7 @@ [lein-auto "0.1.2"] [lein-less "1.7.5"] [lein-shell "0.5.0"] + [cider/cider-nrepl "0.15.0-SNAPSHOT"] [lein-sha-version "0.1.1"]] diff --git a/resources/migrations/20171226182259-hide-user.down.sql b/resources/migrations/20171226182259-hide-user.down.sql index 3706d483..1b3dcc81 100644 --- a/resources/migrations/20171226182259-hide-user.down.sql +++ b/resources/migrations/20171226182259-hide-user.down.sql @@ -1,8 +1,5 @@ BEGIN; -ALTER TABLE users - DROP COLUMN is_hidden; - -- restore the previous version of the view CREATE OR REPLACE VIEW "public"."claims_view" AS SELECT @@ -32,4 +29,7 @@ SELECT AND i.comment_id IS NOT NULL ORDER BY p.updated; +ALTER TABLE users + DROP COLUMN is_hidden_in_hunters; + COMMIT; diff --git a/resources/migrations/20171226182259-hide-user.up.sql b/resources/migrations/20171226182259-hide-user.up.sql index 29771802..a1aa2338 100644 --- a/resources/migrations/20171226182259-hide-user.up.sql +++ b/resources/migrations/20171226182259-hide-user.up.sql @@ -1,7 +1,7 @@ BEGIN; ALTER TABLE users - ADD COLUMN is_hidden BOOLEAN NOT NULL DEFAULT FALSE; + ADD COLUMN is_hidden_in_hunters BOOLEAN NOT NULL DEFAULT FALSE; CREATE OR REPLACE VIEW "public"."claims_view" AS SELECT @@ -29,7 +29,7 @@ SELECT AND p.user_id = u.id AND i.contract_address IS NOT NULL AND i.comment_id IS NOT NULL - AND NOT u.is_hidden -- added + AND NOT u.is_hidden_in_hunters -- added ORDER BY p.updated; COMMIT; diff --git a/src/clj/commiteth/db/core.clj b/src/clj/commiteth/db/core.clj index fa5deb79..2ca5ff74 100644 --- a/src/clj/commiteth/db/core.clj +++ b/src/clj/commiteth/db/core.clj @@ -85,7 +85,7 @@ IPersistentVector (sql-value [value] (to-pg-json value))) -(defmacro with-trx [& body] +(defmacro with-tx [& body] "Performs a set of queries in transaction." `(conman/with-transaction [*db*] ~@body)) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 26f6dc4c..15b85196 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -227,11 +227,11 @@ :auth-rules authenticated? :current-user user :body [body {(s/optional-key :address) s/Str - (s/optional-key :is_hidden) s/Bool}] + (s/optional-key :is_hidden_in_hunters) s/Bool}] :summary "Updates user's fields." (let [user-id (:id user) - fields (select-keys body [:address :is_hidden])] + fields (select-keys body [:address :is_hidden_in_hunters])] (when (empty? fields) (bad-request! "No incoming fields were found.")) @@ -241,11 +241,9 @@ (log/debugf "POST /user: Wrong address %s" address) (bad-request! (format "Invalid Ethereum address: %s" address)))) - (db/with-trx - + (db/with-tx (when-not (db/user-exists? {:id user-id}) (not-found! "No such a user.")) - (db/update! :users fields ["id = ?" user-id])) (ok))) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index c9c1c747..00ad0dfd 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -62,11 +62,6 @@ (fn [db [_ path value]] (assoc-in db path value))) -(reg-event-db - :update-in - (fn [db [_ path func & args]] - (apply update-in db path func args))) - (reg-event-db :set-active-page (fn [db [_ page]] @@ -322,6 +317,10 @@ {:db db :dispatch [:set-active-page :update-address]})) +(reg-event-db + :update-user + (fn [db [_ fields]] + (update db :user merge fields))) (reg-event-fx :save-user-fields @@ -330,7 +329,7 @@ :http {:method POST :url "/api/user" :on-success #(do - (dispatch [:update-in [:user] merge fields]) + (dispatch [:update-user fields]) (dispatch [:set-flash-message :success "Settings saved"])) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index e062bac3..939b14e1 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -10,7 +10,7 @@ (let [db (rf/subscribe [:db]) updating-user (rf/subscribe [:get-in [:updating-user]]) address (r/atom @(rf/subscribe [:get-in [:user :address]])) - hidden (rf/subscribe [:get-in [:user :is_hidden]])] + is-hidden (rf/subscribe [:get-in [:user :is_hidden_in_hunters]])] (fn [] (let [web3 (:web3 @db) @@ -23,7 +23,7 @@ [:div.field (if-not (empty? web3-accounts) ; Add value of address if it's missing from items list. - ; If address is empty, add title + ; If address is empty, add title (let [accounts (map str/lower-case web3-accounts) addr @address title "Select address" @@ -35,7 +35,7 @@ items (cond->> web3-accounts addr-not-in-web3? (into [addr]) (not addr) (into [title]))] - [dropdown {:class "address-input"} + [dropdown {:class "address-input"} title address items]) @@ -55,15 +55,14 @@ [:h3 "Settings"] [:div - [:input {:type :checkbox :disabled @updating-user :id :input-hidden - :checked @hidden + :checked @is-hidden :on-change (fn [e] (let [value (-> e .-target .-checked)] - (rf/dispatch [:save-user-fields {:is_hidden value}])))}] + (rf/dispatch [:save-user-fields {:is_hidden_in_hunters value}])))}] [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) From 56d1425b17c8a00d1c05c255822635f29dff58ee Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Thu, 8 Feb 2018 15:29:26 +0300 Subject: [PATCH 24/28] 193 sql fix --- resources/sql/queries.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 082c636b..1421ced7 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -577,7 +577,7 @@ WHERE pr.commit_sha = i.commit_sha AND u.id = pr.user_id AND i.payout_receipt IS NOT NULL -AND NOT u.is_hidden +AND NOT u.is_hidden_in_hunters GROUP BY u.id ORDER BY total_usd DESC LIMIT 5; From 21c869af49c4882238ba1880892ad5e4ec010c97 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Thu, 8 Feb 2018 15:33:24 +0300 Subject: [PATCH 25/28] 193 blank line removed --- src/cljs/commiteth/update_address.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 939b14e1..fcb25143 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -64,5 +64,4 @@ (fn [e] (let [value (-> e .-target .-checked)] (rf/dispatch [:save-user-fields {:is_hidden_in_hunters value}])))}] - [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) From 4717a1a590404fae977caa718febc93648219c08 Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Mon, 12 Feb 2018 18:07:41 +0300 Subject: [PATCH 26/28] 193 review fixes --- src/clj/commiteth/routes/services.clj | 18 +++++++---------- src/cljs/commiteth/update_address.cljs | 28 +++++++++++++++----------- src/less/style.less | 3 +-- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 15b85196..d8139624 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -226,25 +226,21 @@ (POST "/" [] :auth-rules authenticated? :current-user user - :body [body {(s/optional-key :address) s/Str - (s/optional-key :is_hidden_in_hunters) s/Bool}] + :body [body {:address s/Str + :is_hidden_in_hunters s/Bool}] :summary "Updates user's fields." (let [user-id (:id user) - fields (select-keys body [:address :is_hidden_in_hunters])] + {:keys [address]} body] - (when (empty? fields) - (bad-request! "No incoming fields were found.")) - - (when-let [address (:address fields)] - (when-not (eth/valid-address? address) - (log/debugf "POST /user: Wrong address %s" address) - (bad-request! (format "Invalid Ethereum address: %s" address)))) + (when-not (eth/valid-address? address) + (log/debugf "POST /user: Wrong address %s" address) + (bad-request! (format "Invalid Ethereum address: %s" address))) (db/with-tx (when-not (db/user-exists? {:id user-id}) (not-found! "No such a user.")) - (db/update! :users fields ["id = ?" user-id])) + (db/update! :users body ["id = ?" user-id])) (ok))) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index fcb25143..e5c066dd 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -10,7 +10,7 @@ (let [db (rf/subscribe [:db]) updating-user (rf/subscribe [:get-in [:updating-user]]) address (r/atom @(rf/subscribe [:get-in [:user :address]])) - is-hidden (rf/subscribe [:get-in [:user :is_hidden_in_hunters]])] + hidden (r/atom @(rf/subscribe [:get-in [:user :is_hidden_in_hunters]]))] (fn [] (let [web3 (:web3 @db) @@ -45,23 +45,27 @@ :auto-correct "off" :spell-check "false" :max-length 42}]])] - [:button - (merge {:on-click - #(rf/dispatch [:save-user-fields {:address @address}]) - :class (str "ui button small update-address-button" - (when @updating-user - " busy loading"))}) - "UPDATE"] - [:h3 "Settings"] [:div [:input {:type :checkbox :disabled @updating-user :id :input-hidden - :checked @is-hidden + :checked @hidden :on-change (fn [e] (let [value (-> e .-target .-checked)] - (rf/dispatch [:save-user-fields {:is_hidden_in_hunters value}])))}] - [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) + (reset! hidden value)))}] + + [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]] + + [:button + (merge {:on-click + #(rf/dispatch [:save-user-fields {:address @address + :is_hidden_in_hunters @hidden}]) + :class (str "ui button small update-address-button" + (when @updating-user + " busy loading"))}) + "UPDATE"] + + ]])))) diff --git a/src/less/style.less b/src/less/style.less index 43d13985..747afcfb 100644 --- a/src/less/style.less +++ b/src/less/style.less @@ -41,6 +41,7 @@ .update-address-button { background-color: #57a7ed!important; + margin-top: 10px !important; &:hover { background-color: #57a7ed!important; } @@ -1291,5 +1292,3 @@ body { color: #8d99a4; padding-top: 20px; } - - From 092713a5415c1c3493851624d005bbbbcde87fde Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Mon, 12 Feb 2018 18:13:55 +0300 Subject: [PATCH 27/28] 193 merge artifacts --- src/cljs/commiteth/update_address.cljs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 2e4ec4be..54471f9e 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -22,8 +22,6 @@ [:div.field (if-not (empty? web3-accounts) [dropdown {:class "address-input"} "Select address" - ; If address is empty, add title - [dropdown {:class "address-input"} address (vec (for [acc web3-accounts] From 9732b7c948ff9ceffab06392914b684aa4d21c4c Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Mon, 12 Feb 2018 18:17:45 +0300 Subject: [PATCH 28/28] 193 h3 added --- src/cljs/commiteth/update_address.cljs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 54471f9e..be98a871 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -33,6 +33,8 @@ :spell-check "false" :max-length 42}]])] + [:h3 "Settings"] + [:div [:input {:type :checkbox