fixed failed login, disabled address field, added error message

This commit is contained in:
Adrian Tiberius 2016-07-06 23:47:57 +03:00
parent b28427cddd
commit 9d8bd7d740
5 changed files with 38 additions and 22 deletions

View File

@ -117,7 +117,7 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
case GethMessages.MSG_LOGGED_IN: case GethMessages.MSG_LOGGED_IN:
callback = unlockAccountCallbacks.remove(callbackIdentifier); callback = unlockAccountCallbacks.remove(callbackIdentifier);
if (callback != null) { if (callback != null) {
callback.invoke(null, "{ \"result\": \"" + data.getString("result") + "\"}"); callback.invoke(data.getString("result"));
} }
break; break;
default: default:

View File

@ -45,15 +45,23 @@
(.createAccount geth password (fn [result] (account-created db result password))) (.createAccount geth password (fn [result] (account-created db result password)))
db))) db)))
(register-handler :login-account (defn login [db address]
(-> (fn [db [_ address password]]
(.login geth address password (fn [result]
(let [account (get-in db [:accounts address])] (let [account (get-in db [:accounts address])]
(log/debug "Logged in account: " address result)
(dispatch [:set :login {}]) (dispatch [:set :login {}])
(dispatch [:set :current-account account]) (dispatch [:set :current-account account])
(dispatch [:initialize-protocol account]) (dispatch [:initialize-protocol account])
(when (:signed-up db) (dispatch [:navigate-to-clean default-view]))))) (when (:signed-up db) (dispatch [:navigate-to-clean default-view]))))
(register-handler :login-account
(-> (fn [db [_ address password]]
(.login geth address password (fn [result]
(let [data (json->clj result)
error (:error data)
success (zero? (count error))]
(log/debug "Logged in account: " address result)
(if success
(login db address)
(dispatch [:set-in [:login :error] error])))))
db))) db)))
(defn load-accounts! [db _] (defn load-accounts! [db _]

View File

@ -24,6 +24,7 @@
(def default-props {:wrapperStyle {} (def default-props {:wrapperStyle {}
:inputStyle {} :inputStyle {}
:lineStyle {} :lineStyle {}
:editable true
:labelColor "#838c93" :labelColor "#838c93"
:lineColor "#0000001f" :lineColor "#0000001f"
:focusLineColor "#0000001f" :focusLineColor "#0000001f"
@ -141,16 +142,17 @@
max-line-width] :as state} (r/state component) max-line-width] :as state} (r/state component)
{:keys [wrapperStyle inputStyle lineColor focusLineColor {:keys [wrapperStyle inputStyle lineColor focusLineColor
labelColor errorColor error label value onFocus onBlur labelColor errorColor error label value onFocus onBlur
onChangeText onChange] :as props} (merge default-props (r/props component)) onChangeText onChange editable] :as props} (merge default-props (r/props component))
lineColor (if error errorColor lineColor) lineColor (if error errorColor lineColor)
focusLineColor (if error errorColor focusLineColor) focusLineColor (if error errorColor focusLineColor)
labelColor (if (and error (not float-label?)) errorColor labelColor) labelColor (if (and error (not float-label?)) errorColor labelColor)
label (if error (str label " *") label)] label (if error (str label " *") label)]
(log/debug "reagent-render: " data state) (log/debug "reagent-render: " data)
[view (merge st/text-field-container wrapperStyle) [view (merge st/text-field-container wrapperStyle)
[animated-text {:style (st/label label-top label-font-size labelColor)} label] [animated-text {:style (st/label label-top label-font-size labelColor)} label]
[text-input {:style (merge st/text-input inputStyle) [text-input {:style (merge st/text-input inputStyle)
:placeholder "" :placeholder ""
:editable editable
:onFocus #(on-focus {:component component :onFocus #(on-focus {:component component
:animation {:top label-top :animation {:top label-top
:to-top (:label-top config) :to-top (:label-top config)

View File

@ -33,6 +33,7 @@
[view button-input-container [view button-input-container
[text-field [text-field
{:value address {:value address
:editable false
:label (label :t/address) :label (label :t/address)
:labelColor "#ffffff80" :labelColor "#ffffff80"
:lineColor :white :lineColor :white
@ -45,22 +46,26 @@
; :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])}] ; :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])}]
]) ])
(defview password-input [] (defview password-input [error]
[text-field [text-field
{:value "" {:value ""
:error (when (pos? (count error)) (label :t/wrong-password))
:errorColor :white
:label (label :t/password) :label (label :t/password)
:labelColor "#ffffff80" :labelColor "#ffffff80"
:lineColor :white :lineColor :white
:inputStyle st/input-style :inputStyle st/input-style
:onChangeText #(dispatch [:set-in [:login :password] %])}]) :onChangeText #(do
(dispatch [:set-in [:login :password] %])
(dispatch [:set-in [:login :error] ""]))}])
(defview login [] (defview login []
[{:keys [address password]} [:get :login]] [{:keys [address password error]} [:get :login]]
[view st/screen-container [view st/screen-container
[linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"]
:start [0, 0] :start [0, 0]
:end [0.5, 1] :end [0.5, 1]
:locations [0, 0.8 ,1] :locations [0, 0.8, 1]
:style st/gradient-background}] :style st/gradient-background}]
[toolbar {:background-color :transparent [toolbar {:background-color :transparent
@ -72,7 +77,7 @@
:handler #()}}] :handler #()}}]
[view st/form-container [view st/form-container
[address-input (or address "")] [address-input (or address "")]
[password-input] [password-input error]
] ]
[view st/bottom-actions-container [view st/bottom-actions-container
[view st/recover-text-container [view st/recover-text-container

View File

@ -132,6 +132,7 @@
:address "Address" :address "Address"
:password "Password" :password "Password"
:login "Login" :login "Login"
:wrong-password "Wrong password"
;users ;users
:add-account "Add account" :add-account "Add account"