diff --git a/src/clj/commiteth/db/core.clj b/src/clj/commiteth/db/core.clj index 31ee788..a33f2e0 100644 --- a/src/clj/commiteth/db/core.clj +++ b/src/clj/commiteth/db/core.clj @@ -1,12 +1,13 @@ (ns commiteth.db.core (:require - [cheshire.core :refer [generate-string parse-string]] - [clojure.java.jdbc :as jdbc] - [conman.core :as conman] - [commiteth.config :refer [env]] - [mount.core :refer [defstate]] - [migratus.core :as migratus] - [mpg.core :as mpg]) + [cheshire.core :refer [generate-string parse-string]] + [clojure.java.jdbc :as jdbc] + [conman.core :as conman] + [commiteth.config :refer [env]] + [mount.core :refer [defstate]] + [migratus.core :as migratus] + [mpg.core :as mpg] + [clojure.string :as str]) (:import org.postgresql.util.PGobject java.sql.Array clojure.lang.IPersistentMap @@ -75,7 +76,7 @@ (let [conn (.getConnection stmt) meta (.getParameterMetaData stmt) type-name (.getParameterTypeName meta idx)] - (if-let [elem-type (when (= (first type-name) \_) (apply str (rest type-name)))] + (if-let [elem-type (when (= (first type-name) \_) (str/join (rest type-name)))] (.setObject stmt idx (.createArrayOf conn elem-type (to-array v))) (.setObject stmt idx (to-pg-json v)))))) diff --git a/src/clj/commiteth/db/repositories.clj b/src/clj/commiteth/db/repositories.clj index 9477108..7f23f9a 100644 --- a/src/clj/commiteth/db/repositories.clj +++ b/src/clj/commiteth/db/repositories.clj @@ -20,10 +20,10 @@ (defn get-enabled "Lists enabled repository id's for a given user-id" [user-id] - (->> + (mapcat + vals (jdbc/with-db-connection [con-db *db*] - (db/get-enabled-repositories con-db {:user_id user-id})) - (mapcat vals))) + (db/get-enabled-repositories con-db {:user_id user-id})))) (defn update-repo [repo-id updates] diff --git a/src/clj/commiteth/eth/core.clj b/src/clj/commiteth/eth/core.clj index 078435b..5afdc52 100644 --- a/src/clj/commiteth/eth/core.clj +++ b/src/clj/commiteth/eth/core.clj @@ -71,7 +71,7 @@ :gas gas})] (eth-rpc "personal_sendTransaction" - [(if (not (nil? to)) + [(if-not (nil? to) (merge args {:to to}) args) (eth-password)]))) @@ -143,8 +143,7 @@ (log/debug "address hash" hash "addr" addr) (->> (map-indexed (fn [idx _] - (let [hash-ch-int (-> (nth hash idx) - (hex-ch->num)) + (let [hash-ch-int (hex-ch->num (nth hash idx)) ch (nth addr idx) ch-lower (lower-ch ch) ch-upper (upper-ch ch)] diff --git a/src/clj/commiteth/github/core.clj b/src/clj/commiteth/github/core.clj index faacbe7..4ba2152 100644 --- a/src/clj/commiteth/github/core.clj +++ b/src/clj/commiteth/github/core.clj @@ -82,15 +82,15 @@ own login." [token] (let [all-repos-with-admin-access - (->> - (map #(merge - {:owner-login (get-in % [:owner :login])} - {:owner-type (get-in % [:owner :type])} - {:owner-avatar-url (get-in % [:owner :avatar_url])} - (select-keys % repo-fields)) - (repos/repos (merge (auth-params token) {:type "all" - :all-pages true}))) - (filter #(-> % :permissions :admin)))] + (filter #(-> % :permissions :admin) + (map #(merge + {:owner-login (get-in % [:owner :login])} + {:owner-type (get-in % [:owner :type])} + {:owner-avatar-url (get-in % [:owner :avatar_url])} + (select-keys % repo-fields)) + (repos/repos + (merge (auth-params token) {:type "all" + :all-pages true}))))] (group-by :owner-login all-repos-with-admin-access))) (defn get-user diff --git a/src/clj/commiteth/routes/home.clj b/src/clj/commiteth/routes/home.clj index eb0cef1..3996c2c 100644 --- a/src/clj/commiteth/routes/home.clj +++ b/src/clj/commiteth/routes/home.clj @@ -25,5 +25,5 @@ (GET "/" {{user :identity} :session} (home-page user)) (GET "/logout" {session :session} - (-> (redirect "/") - (assoc :session (dissoc session :identity))))) + (assoc (redirect "/") + :session (dissoc session :identity)))) diff --git a/src/clj/commiteth/routes/redirect.clj b/src/clj/commiteth/routes/redirect.clj index 7c84800..aa3f97c 100644 --- a/src/clj/commiteth/routes/redirect.clj +++ b/src/clj/commiteth/routes/redirect.clj @@ -44,7 +44,7 @@ (response/redirect "/") (let [admin-token? (str/includes? scope "repo") token-key (if admin-token? :admin-token :token) - user (-> (get-or-create-user access-token) - (assoc token-key access-token))] - (-> (response/redirect "/") - (assoc :session {:identity user}))))))) + user (assoc (get-or-create-user access-token) + token-key access-token)] + (assoc (response/redirect "/") + :session {:identity user})))))) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index ffa3019..bca7b7d 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -109,8 +109,9 @@ :let [b (update ob :balance decimal->str)]] [(:issue_id b) (conj b - (let [claims (->> (bounties-db/bounty-claims (:issue_id b)) - (map #(update % :balance decimal->str)))] + (let [claims (map + #(update % :balance decimal->str) + (bounties-db/bounty-claims (:issue_id b)))] {:claims claims}))])))) diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index 11a5983..3fbfb4b 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -181,7 +181,7 @@ (mount/defstate scheduler :start (let [every-minute (rest (periodic-seq (t/now) - (-> 1 t/minutes))) + (t/minutes 1))) stop-fn (chime-at every-minute run-periodic-tasks {:error-handler (fn [e] diff --git a/src/clj/commiteth/util/digest.clj b/src/clj/commiteth/util/digest.clj index 563d013..7732c66 100644 --- a/src/clj/commiteth/util/digest.clj +++ b/src/clj/commiteth/util/digest.clj @@ -1,9 +1,10 @@ (ns commiteth.util.digest - (:import [javax.crypto])) + (:import [javax.crypto]) + (:require [clojure.string :as str])) ;; credit: https://gist.github.com/visibletrap/4571244 (defn hex-hmac-sha1 [key input] - (let [secret (javax.crypto.spec.SecretKeySpec. (. key getBytes "UTF-8") "HmacSHA1") + (let [secret (javax.crypto.spec.SecretKeySpec. (.getBytes key "UTF-8") "HmacSHA1") hmac-sha1 (doto (javax.crypto.Mac/getInstance "HmacSHA1") (.init secret)) - bytes (. hmac-sha1 doFinal (. input getBytes "UTF-8"))] - (apply str (map (partial format "%02x") bytes)))) + bytes (.doFinal hmac-sha1 (.getBytes input "UTF-8"))] + (str/join (map (partial format "%02x") bytes)))) diff --git a/src/clj/commiteth/util/png_rendering.clj b/src/clj/commiteth/util/png_rendering.clj index 6679e06..0845bb0 100644 --- a/src/clj/commiteth/util/png_rendering.clj +++ b/src/clj/commiteth/util/png_rendering.clj @@ -26,8 +26,8 @@ (defn gen-comment-image [address balance issue-url] - (let [qr-image (-> (image->base64 (generate-qr-image address)) - (String. "ISO-8859-1")) + (let [qr-image (String. (image->base64 (generate-qr-image address)) + "ISO-8859-1") html (:body (render "bounty.html" {:qr-image qr-image :balance balance @@ -37,7 +37,7 @@ {out :out err :err exit :exit} (sh command "-f" "png" "--quality" "80" "--width" "1336" "-" "-" :out-enc :bytes :in html)] - (if (= 0 exit) + (if (zero? exit) (do (log/debug "PNG generated succesfully" out err exit html) out) diff --git a/src/cljs/commiteth/activity.cljs b/src/cljs/commiteth/activity.cljs index 0abb971..9450c61 100644 --- a/src/cljs/commiteth/activity.cljs +++ b/src/cljs/commiteth/activity.cljs @@ -39,7 +39,7 @@ [:div.description [item-description item]] [:div.footer-row - (when (not (= item-type "new-bounty")) + (when-not (= item-type "new-bounty") [:div.balance-badge (str "ETH " balance )]) [:div.time (moment-timestamp updated)]]]]) diff --git a/src/cljs/commiteth/common.cljs b/src/cljs/commiteth/common.cljs index c9b50f1..9d302f0 100644 --- a/src/cljs/commiteth/common.cljs +++ b/src/cljs/commiteth/common.cljs @@ -25,8 +25,7 @@ (defn moment-timestamp [time] (let [now (.now js/Date.) js-time (clj->js time)] - (-> (js/moment.utc) - (.to js-time)))) + (.to (js/moment.utc) js-time))) (defn issue-url [owner repo number] (str "https://github.com/" owner "/" repo "/issues/" number)) diff --git a/src/cljs/commiteth/core.cljs b/src/cljs/commiteth/core.cljs index 1cca72e..1a53e65 100644 --- a/src/cljs/commiteth/core.cljs +++ b/src/cljs/commiteth/core.cljs @@ -119,7 +119,7 @@ (into [:div.ui.items.top-hunters] (map-indexed (fn [idx hunter] [:div.item - [:div.leader-ordinal (str (+ 1 idx))] + [:div.leader-ordinal (str (inc idx))] [:div.ui..mini.circular.image [:img {:src (:avatar-url hunter)}]] [:div.content diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 9046d7a..18236b3 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -69,7 +69,7 @@ (defn assoc-in-if-not-empty [m path val] - (if (not (empty? val)) + (if (seq val) (assoc-in m path val) m)) @@ -105,7 +105,7 @@ (if-let [res (and ks (dissoc-in (get m k) ks))] (assoc m k res) (let [res (dissoc m k)] - (when-not (empty? res) + (when (seq res) res))))) (reg-event-fx @@ -251,10 +251,12 @@ (reg-event-db :repo-toggle-success (fn [db [_ repo]] - (assoc db :repos (update-repo-state (:repos db) - (:full_name repo) - {:busy? false - :enabled (:enabled repo)} )))) + (update-in db + [:repos] + update-repo-state + (:full_name repo) + {:busy? false + :enabled (:enabled repo)}))) (reg-event-fx :repo-toggle-error @@ -315,11 +317,10 @@ [issue-id] (fn [error payout-hash] (when error - (do - (dispatch [:set-flash-message - :error - (str "Error sending transaction: " error)]) - (dispatch [:payout-confirm-failed issue-id]))) + (dispatch [:set-flash-message + :error + (str "Error sending transaction: " error)]) + (dispatch [:payout-confirm-failed issue-id])) (when payout-hash (dispatch [:save-payout-hash issue-id payout-hash])))) diff --git a/src/cljs/commiteth/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 016d333..8d8c9f0 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -11,7 +11,7 @@ address (r/atom @(rf/subscribe [:get-in [:user :address]]))] (fn [] (let [web3 (.-web3 js/window) - web3-accounts (into [] (when-not (nil? web3) (-> web3 + web3-accounts (vec (when-not (nil? web3) (-> web3 .-eth .-accounts js->clj)))] @@ -24,9 +24,9 @@ (if-not (empty? web3-accounts) [dropdown {:class "address-input"} "Select address" address - (into [] - (for [acc web3-accounts] - acc))] + (vec + (for [acc web3-accounts] + acc))] [:div.ui.input.address-input [input address {:placeholder "0x0000000000000000000000000000000000000000" :auto-complete "off"