diff --git a/android/app/src/main/java/com/statusim/geth/module/GethModule.java b/android/app/src/main/java/com/statusim/geth/module/GethModule.java index 058ab03667..2aeb3b0902 100644 --- a/android/app/src/main/java/com/statusim/geth/module/GethModule.java +++ b/android/app/src/main/java/com/statusim/geth/module/GethModule.java @@ -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: diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 2f9e3b0d27..9b0e59f444 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -45,15 +45,23 @@ (.createAccount geth password (fn [result] (account-created db result password))) db))) +(defn login [db address] + (let [account (get-in db [:accounts address])] + (dispatch [:set :login {}]) + (dispatch [:set :current-account account]) + (dispatch [:initialize-protocol account]) + (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 [account (get-in db [:accounts address])] + (let [data (json->clj result) + error (:error data) + success (zero? (count error))] (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]))))) + (if success + (login db address) + (dispatch [:set-in [:login :error] error]))))) db))) (defn load-accounts! [db _] diff --git a/src/status_im/components/text_field/view.cljs b/src/status_im/components/text_field/view.cljs index 21ca793111..2b78927d0a 100644 --- a/src/status_im/components/text_field/view.cljs +++ b/src/status_im/components/text_field/view.cljs @@ -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) diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs index 81e7409d2c..3329467df6 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/login/screen.cljs @@ -33,6 +33,7 @@ [view button-input-container [text-field {:value address + :editable false :label (label :t/address) :labelColor "#ffffff80" :lineColor :white @@ -45,34 +46,38 @@ ; :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] %])}]) + :inputStyle st/input-style + :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] - :style st/gradient-background}] + [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] + :style st/gradient-background}] [toolbar {:background-color :transparent - :nav-action {:image {:source {:uri :icon_back_white} - :style icon-back} - :handler #(dispatch [:navigate-back])} + :nav-action {:image {:source {:uri :icon_back_white} + :style icon-back} + :handler #(dispatch [:navigate-back])} :custom-content toolbar-title - :action {:image {:style icon-search} + :action {:image {:style icon-search} :handler #()}}] [view st/form-container [address-input (or address "")] - [password-input] + [password-input error] ] [view st/bottom-actions-container [view st/recover-text-container diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 05fa0ab1ac..1da6f4a519 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -132,6 +132,7 @@ :address "Address" :password "Password" :login "Login" + :wrong-password "Wrong password" ;users :add-account "Add account"