From 50036b10dd6f296aa17da7dd93d5f25cc2f40c86 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Thu, 1 Feb 2018 15:40:54 +0200 Subject: [PATCH] Address dropdown: move items list construction to invocation point --- src/cljs/commiteth/common.cljs | 27 ++++++++++---------------- src/cljs/commiteth/update_address.cljs | 19 ++++++++++++++---- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/cljs/commiteth/common.cljs b/src/cljs/commiteth/common.cljs index 0b0898f..4399156 100644 --- a/src/cljs/commiteth/common.cljs +++ b/src/cljs/commiteth/common.cljs @@ -13,23 +13,16 @@ (defn dropdown [props title val-ratom items] "If val-ratom is set, preselect it in the dropdown. - Add value of val-ratom if it's missing from items list. - Otherwise, prepend title as a disabled option" - (let [items (cond->> items - (and @val-ratom - (not (contains? (set items) @val-ratom))) - (into [@val-ratom]) - (not @val-ratom) - (into [title]))] - (fn [] - [:select.ui.basic.selection.dropdown - (merge props {:on-change - #(reset! val-ratom (-> % .-target .-value)) - :default-value (or @val-ratom title)}) - (for [item items] - ^{:key item} [:option {:value item - :disabled (= item title)} - item])]))) + Otherwise, prepend title as a disabled option." + (fn [] + [:select.ui.basic.selection.dropdown + (merge props {:on-change + #(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/update_address.cljs b/src/cljs/commiteth/update_address.cljs index 9261671..60e298f 100644 --- a/src/cljs/commiteth/update_address.cljs +++ b/src/cljs/commiteth/update_address.cljs @@ -24,10 +24,21 @@ [:p "Insert your Ethereum address in hex format."] [:div.field (if-not (empty? web3-accounts) - [dropdown {:class "address-input"} - "Select address" - address - (map str/lower-case web3-accounts)] + ; 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" + items (cond->> accounts + (and addr + (not (contains? (set accounts) addr))) + (into [addr]) + (not addr) + (into [title]))] + [dropdown {:class "address-input"} + title + address + items]) [:div.ui.input.address-input [input address {:placeholder "0x0000000000000000000000000000000000000000" :auto-complete "off"