Merge pull request #240 from status-im/fix/metamask-address-not-updated-#187

[FIX #187] Fix address dropdown in My Payment Details
This commit is contained in:
Vitaliy Vlasov 2018-02-06 16:21:35 +02:00 committed by GitHub
commit 83d37cd5e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 14 deletions

View File

@ -12,16 +12,17 @@
:on-change #(reset! val-ratom (-> % .-target .-value))})])) :on-change #(reset! val-ratom (-> % .-target .-value))})]))
(defn dropdown [props title val-ratom items] (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 [] (fn []
(if (= 1 (count items))
(reset! val-ratom (first items)))
[:select.ui.basic.selection.dropdown [:select.ui.basic.selection.dropdown
(merge props {:on-change (merge props {:on-change
#(reset! val-ratom (-> % .-target .-value))}) #(reset! val-ratom (-> % .-target .-value))
(doall (for [item items] :default-value (or @val-ratom title)})
^{:key item} [:option (for [item items]
{:value item} ^{:key item} [:option {:value item
item]))])) :disabled (= item title)}
item])]))
(defn moment-timestamp [time] (defn moment-timestamp [time]
(let [now (.now js/Date.) (let [now (.now js/Date.)

View File

@ -327,7 +327,7 @@
:http {:method POST :http {:method POST
:url "/api/user/address" :url "/api/user/address"
:on-success #(do :on-success #(do
(dispatch [:assoc-in [:user [:address] address]]) (dispatch [:assoc-in [:user :address] address])
(dispatch [:set-flash-message (dispatch [:set-flash-message
:success :success
"Address saved"])) "Address saved"]))

View File

@ -3,6 +3,7 @@
[commiteth.common :refer [input dropdown]] [commiteth.common :refer [input dropdown]]
[reagent.core :as r] [reagent.core :as r]
[reagent.crypt :as crypt] [reagent.crypt :as crypt]
[clojure.string :as str]
[cljs-web3.eth :as web3-eth])) [cljs-web3.eth :as web3-eth]))
@ -22,11 +23,23 @@
[:p "Insert your Ethereum address in hex format."] [:p "Insert your Ethereum address in hex format."]
[:div.field [:div.field
(if-not (empty? web3-accounts) (if-not (empty? web3-accounts)
[dropdown {:class "address-input"} "Select address" ; 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 address
(vec items])
(for [acc web3-accounts]
acc))]
[:div.ui.input.address-input [:div.ui.input.address-input
[input address {:placeholder "0x0000000000000000000000000000000000000000" [input address {:placeholder "0x0000000000000000000000000000000000000000"
:auto-complete "off" :auto-complete "off"