From 264a83c38497ec1b17fe51272def6a71e81e955e Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Tue, 26 Dec 2017 18:14:54 +0300 Subject: [PATCH 01/34] 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 0e3eb68..178a289 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 eedcafd..f73ecc2 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/34] 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 0000000..68a2a23 --- /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/34] 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 0000000..e11839c --- /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 0000000..96b7fc7 --- /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/34] 193 cider plugin removed --- project.clj | 2 -- 1 file changed, 2 deletions(-) diff --git a/project.clj b/project.clj index 9a0ea35..ae4d245 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/34] 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 178a289..f5f86ee 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 f73ecc2..2ebf4b2 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/34] 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 9a284f2..9e76f7c 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 e617708..352bf1f 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 a33f2e0..162c418 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/34] 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 162c418..0742d6b 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 82c5633..fb35a92 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/34] 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 9d302f0..6802845 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 528c116..2171764 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 6134bde..2bc7d81 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/34] 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 e11839c..3706d48 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 96b7fc7..2977180 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 e8a3115..9d9acf2 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/34] 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 2c0c2e4..516c60c 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/34] 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 6802845..9d302f0 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 2bc7d81..e0153c8 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/34] 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 fb35a92..e36a7ae 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/34] 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 f5f86ee..f14b872 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 68a2a23..0000000 --- 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 2ebf4b2..eedcafd 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 ae4d245..fb6d054 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 9e76f7c..9a284f2 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 352bf1f..e617708 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 0742d6b..fa5deb7 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/34] 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 9d9acf2..082c636 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/34] 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 e36a7ae..d71869c 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/34] 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 d71869c..fecf724 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/34] 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 2171764..c6cfdd9 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 e0153c8..77bea91 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/34] 193 gitignore fix --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index f14b872..0e3eb68 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/34] 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 c6cfdd9..e9c6d4a 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/34] 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 1ee9264..0000000 --- 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/34] 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 0000000..1ee9264 --- /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/34] 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 fecf724..26f6dc4 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 549d22b..c9c1c74 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 77bea91..c1ba88d 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/34] 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 ccb500f..0678470 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 3706d48..1b3dcc8 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 2977180..a1aa233 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 fa5deb7..2ca5ff7 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 26f6dc4..15b8519 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 c9c1c74..00ad0df 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 e062bac..939b14e 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/34] 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 082c636..1421ced 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/34] 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 939b14e..fcb2514 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/34] 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 15b8519..d813962 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 fcb2514..e5c066d 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 43d1398..747afcf 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/34] 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 2e4ec4b..54471f9 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/34] 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 54471f9..be98a87 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 From a25bfe419e365ff4e45082a627a99a25980b31ee Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Fri, 16 Feb 2018 13:06:35 +0200 Subject: [PATCH 29/34] Revert "Revert "[FIX #187] Fix address dropdown in My Payment Details"" --- src/cljs/commiteth/common.cljs | 15 ++++++++------- src/cljs/commiteth/handlers.cljs | 2 +- src/cljs/commiteth/update_address.cljs | 25 +++++++++++++++++++------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/cljs/commiteth/common.cljs b/src/cljs/commiteth/common.cljs index 1213395..4399156 100644 --- a/src/cljs/commiteth/common.cljs +++ b/src/cljs/commiteth/common.cljs @@ -12,16 +12,17 @@ :on-change #(reset! val-ratom (-> % .-target .-value))})])) (defn dropdown [props title val-ratom items] + "If val-ratom is set, preselect it in the dropdown. + Otherwise, prepend title as a disabled option." (fn [] - (if (= 1 (count items)) - (reset! val-ratom (first items))) [:select.ui.basic.selection.dropdown (merge props {:on-change - #(reset! val-ratom (-> % .-target .-value))}) - (doall (for [item items] - ^{:key item} [:option - {:value item} - item]))])) + #(reset! val-ratom (-> % .-target .-value)) + :default-value (or @val-ratom title)}) + (for [item items] + ^{:key item} [:option {:value item + :disabled (= item title)} + item])])) (defn moment-timestamp [time] (let [now (.now js/Date.) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 20fdd74..3c6cbcd 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -328,7 +328,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"])) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index b5eb0af..0e6e0df 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -3,6 +3,7 @@ [commiteth.common :refer [input dropdown]] [reagent.core :as r] [reagent.crypt :as crypt] + [clojure.string :as str] [cljs-web3.eth :as web3-eth])) (defn update-address-page-contents [] @@ -21,13 +22,25 @@ [:p "Insert your Ethereum address in hex format."] [:div.field (if-not (empty? web3-accounts) - [dropdown {:class "address-input"} "Select address" - address - (vec - (for [acc web3-accounts] - acc))] + ; Add value of address if it's missing from items list. + ; If address is empty, add title + (let [accounts (map str/lower-case web3-accounts) + addr @address + title "Select address" + addr-not-in-web3? (and addr (as-> web3-accounts acc + (map str/lower-case acc) + (set acc) + (contains? acc addr) + (not acc))) + items (cond->> web3-accounts + addr-not-in-web3? (into [addr]) + (not addr) (into [title]))] + [dropdown {:class "address-input"} + title + address + items]) [:div.ui.input.address-input - [input address {:placeholder "0x0000000000000000000000000000000000000000" + [input address {:placeholder "0x0000000000000000000000000000000000000000" :auto-complete "off" :auto-correct "off" :spell-check "false" From 9f1febc0f35a2ca60365ed2f197d8266dd2cd6b9 Mon Sep 17 00:00:00 2001 From: Rob Culliton Date: Wed, 14 Feb 2018 15:39:55 -0500 Subject: [PATCH 30/34] remove moment.js dependency and replace with goog.date.relative --- project.clj | 1 - src/cljs/commiteth/activity.cljs | 4 ++-- src/cljs/commiteth/bounties.cljs | 4 ++-- src/cljs/commiteth/common.cljs | 10 +++++----- src/cljs/commiteth/manage_payouts.cljs | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/project.clj b/project.clj index ccb500f..ac5d67a 100644 --- a/project.clj +++ b/project.clj @@ -42,7 +42,6 @@ [cheshire "5.8.0"] [mpg "1.3.0"] [pandect "0.6.1"] - [cljsjs/moment "2.17.1-1"] [org.clojure/tools.nrepl "0.2.13"] [com.cemerick/piggieback "0.2.2"] [jarohen/chime "0.2.2"] diff --git a/src/cljs/commiteth/activity.cljs b/src/cljs/commiteth/activity.cljs index 887b8c7..4940085 100644 --- a/src/cljs/commiteth/activity.cljs +++ b/src/cljs/commiteth/activity.cljs @@ -1,7 +1,7 @@ (ns commiteth.activity (:require [re-frame.core :as rf] [reagent.core :as r] - [commiteth.common :refer [moment-timestamp + [commiteth.common :refer [relative-time items-per-page display-data-page issue-url]])) @@ -54,7 +54,7 @@ ^{:key (random-uuid)} [:div.balance-badge.token (str (subs (str tla) 1) " " balance)])]) - [:div.time (moment-timestamp updated)]]]]) + [:div.time (relative-time updated)]]]]) (defn activity-list [{:keys [items item-count page-number total-count] :as activity-page-data} diff --git a/src/cljs/commiteth/bounties.cljs b/src/cljs/commiteth/bounties.cljs index bbdceec..880ad04 100644 --- a/src/cljs/commiteth/bounties.cljs +++ b/src/cljs/commiteth/bounties.cljs @@ -1,7 +1,7 @@ (ns commiteth.bounties (:require [reagent.core :as r] [re-frame.core :as rf] - [commiteth.common :refer [moment-timestamp + [commiteth.common :refer [relative-time display-data-page items-per-page issue-url]] @@ -33,7 +33,7 @@ [:div.open-bounty-item-content [:div.header issue-link] [:div.bounty-item-row - [:div.time (moment-timestamp updated)] + [:div.time (relative-time updated)] [:span.bounty-repo-label repo-link]] [:div.footer-row diff --git a/src/cljs/commiteth/common.cljs b/src/cljs/commiteth/common.cljs index 1213395..6a12648 100644 --- a/src/cljs/commiteth/common.cljs +++ b/src/cljs/commiteth/common.cljs @@ -2,7 +2,7 @@ (:require [reagent.core :as r] [re-frame.core :as rf] [clojure.string :as str] - [cljsjs.moment])) + [goog.date.relative])) (defn input [val-ratom props] (fn [] @@ -23,10 +23,10 @@ {:value item} item]))])) -(defn moment-timestamp [time] - (let [now (.now js/Date.) - js-time (clj->js time)] - (.to (js/moment.utc) js-time))) +(defn relative-time [time] + "converts time in milliseconds to a relative form of '1 hour ago'" + (let [js-time (clj->js time)] + (goog.date.relative/format js-time))) (defn issue-url [owner repo number] (str "https://github.com/" owner "/" repo "/issues/" number)) diff --git a/src/cljs/commiteth/manage_payouts.cljs b/src/cljs/commiteth/manage_payouts.cljs index 746b1a9..eedd7f0 100644 --- a/src/cljs/commiteth/manage_payouts.cljs +++ b/src/cljs/commiteth/manage_payouts.cljs @@ -1,6 +1,6 @@ (ns commiteth.manage-payouts (:require [re-frame.core :as rf] - [commiteth.common :refer [moment-timestamp]])) + [commiteth.common :refer [relative-time]])) @@ -33,7 +33,7 @@ [:div.description (if paid? (str "(paid to " winner-login ")") (str "(" (if merged? "merged" "open") ")"))] - [:div.time (moment-timestamp updated)] + [:div.time (relative-time updated)] [:button.ui.button (merge (if (and merged? (not paid?)) {} From c41f1c5e781c8262ff799cb6da71477da48a9bd4 Mon Sep 17 00:00:00 2001 From: Venkata Chandrasekhar Nainala Date: Tue, 13 Feb 2018 10:22:29 +0000 Subject: [PATCH 31/34] Moving footer out of the vertical segment Avoid the bottom padding from the vertical segment - Semantic UI (Sticks the footer to the base) --- src/cljs/commiteth/core.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cljs/commiteth/core.cljs b/src/cljs/commiteth/core.cljs index 2034449..b6098c3 100644 --- a/src/cljs/commiteth/core.cljs +++ b/src/cljs/commiteth/core.cljs @@ -218,7 +218,7 @@ [:h3.top-hunters-header "Top 5 hunters"] [:div.top-hunters-subheader "All time"] [top-hunters]]])]] - [footer]]]))) + ][footer]]))) (secretary/set-config! :prefix "#") From 3c140a417194065f476e0fe101d82cd17e84ba1d Mon Sep 17 00:00:00 2001 From: Venkata Chandrasekhar Nainala Date: Tue, 13 Feb 2018 10:24:53 +0000 Subject: [PATCH 32/34] Avoid excessing padding on top Moving footer out of the vertical segment creates excessive padding on top. This reduces the padding/gap. --- src/less/style.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/less/style.less b/src/less/style.less index 8b90d73..267042c 100644 --- a/src/less/style.less +++ b/src/less/style.less @@ -986,7 +986,7 @@ z-index: -1; display: flex; justify-content: center; - margin-top: 20px; + margin-top: 10px; } From 207ffca77b2dd40d7bba1deca864efe86060448a Mon Sep 17 00:00:00 2001 From: Venkata Chandrasekhar Nainala Date: Wed, 14 Feb 2018 20:57:33 +0000 Subject: [PATCH 33/34] Sticky footer changes --- src/less/style.less | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/less/style.less b/src/less/style.less index 267042c..175907c 100644 --- a/src/less/style.less +++ b/src/less/style.less @@ -864,6 +864,8 @@ box-shadow: none; border-radius: 0.3em; + min-height: calc(~"100vh - 400px"); + h3 { color: #474951; } @@ -986,7 +988,6 @@ z-index: -1; display: flex; justify-content: center; - margin-top: 10px; } From 0e35273f1cf746d8db0abce873c9274150b41033 Mon Sep 17 00:00:00 2001 From: Venkata Chandrasekhar Nainala Date: Fri, 16 Feb 2018 12:18:36 +0000 Subject: [PATCH 34/34] Aligned the squared brackets with its parent --- src/cljs/commiteth/core.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cljs/commiteth/core.cljs b/src/cljs/commiteth/core.cljs index b6098c3..7fdf659 100644 --- a/src/cljs/commiteth/core.cljs +++ b/src/cljs/commiteth/core.cljs @@ -217,8 +217,8 @@ [:div.ui.container.top-hunters [:h3.top-hunters-header "Top 5 hunters"] [:div.top-hunters-subheader "All time"] - [top-hunters]]])]] - ][footer]]))) + [top-hunters]]])]]] + [footer]]))) (secretary/set-config! :prefix "#")