Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
Revert "Revert "[FIX #187] Fix address dropdown in My Payment Details""
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Vlasov authored Feb 16, 2018
1 parent c5067ec commit a25bfe4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/cljs/commiteth/common.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/commiteth/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand Down
25 changes: 19 additions & 6 deletions src/cljs/commiteth/update_address.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand All @@ -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"
Expand Down

0 comments on commit a25bfe4

Please sign in to comment.