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:
callback = unlockAccountCallbacks.remove(callbackIdentifier);
if (callback != null) {
callback.invoke(null, "{ \"result\": \"" + data.getString("result") + "\"}");
callback.invoke(data.getString("result"));
}
break;
default:

View File

@ -45,15 +45,23 @@
(.createAccount geth password (fn [result] (account-created db result password)))
db)))
(register-handler :login-account
(-> (fn [db [_ address password]]
(.login geth address password (fn [result]
(defn login [db address]
(let [account (get-in db [:accounts address])]
(log/debug "Logged in account: " address result)
(dispatch [:set :login {}])
(dispatch [:set :current-account 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)))
(defn load-accounts! [db _]

View File

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

View File

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

View File

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