[FIX #187] Add dummy value to Metamask dropdown;

do not automatically preselect first item in the list;
convert addresses to lower-case
This commit is contained in:
Vitaliy Vlasov 2018-01-29 19:07:54 +02:00
parent 3f883a36c1
commit 3c4413b160
2 changed files with 17 additions and 14 deletions

View File

@ -10,18 +10,19 @@
(merge props {:type "text"
:value @val-ratom
:on-change #(reset! val-ratom (-> % .-target .-value))})]))
(defn dropdown [props title val-ratom items]
(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]))]))
#(let [selected-value (-> % .-target .-value)]
(when (not= selected-value title)
(reset! val-ratom selected-value)))
:default-value (if (contains? (set items) @val-ratom)
@val-ratom
title)})
(conj (doall (for [item items]
^{:key item} [:option {:value item} item]))
^{:key title} [:option {:value title :disabled true} title])]))
(defn moment-timestamp [time]
(let [now (.now js/Date.)

View File

@ -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]))
@ -10,7 +11,9 @@
(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 (-> @(rf/subscribe [:get-in [:user :address]])
str/lower-case
r/atom)]
(fn []
(let [web3 (:web3 @db)
web3-accounts (when web3
@ -22,13 +25,12 @@
[:p "Insert your Ethereum address in hex format."]
[:div.field
(if-not (empty? web3-accounts)
[dropdown {:class "address-input"} "Select address"
[dropdown {:class "address-input"}
"Select address"
address
(vec
(for [acc web3-accounts]
acc))]
(map str/lower-case web3-accounts)]
[:div.ui.input.address-input
[input address {:placeholder "0x0000000000000000000000000000000000000000"
[input address {:placeholder "0x0000000000000000000000000000000000000000"
:auto-complete "off"
:auto-correct "off"
:spell-check "false"