From ebccb8e020f1ee3d2211d4f4ddca719e96f35b5a Mon Sep 17 00:00:00 2001 From: Dmitry Novotochinov Date: Mon, 15 Apr 2019 19:46:41 +0300 Subject: [PATCH] [#7908] [#7909] handle wrong pairing password * show 'invalid pairing password' on failed pairing * wrap view into scroll view Signed-off-by: Dmitry Novotochinov --- src/status_im/hardwallet/core.cljs | 25 ++++++++--- .../ui/screens/hardwallet/setup/views.cljs | 44 +++++++++++-------- translations/en.json | 1 + 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/status_im/hardwallet/core.cljs b/src/status_im/hardwallet/core.cljs index 9a8bcef3db..619b03f7ae 100644 --- a/src/status_im/hardwallet/core.cljs +++ b/src/status_im/hardwallet/core.cljs @@ -145,7 +145,8 @@ (set-setup-step card-state) (if (= :pre-init card-state) (navigation/navigate-to-cofx :hardwallet-setup nil) - (navigation/navigate-to-cofx :hardwallet-authentication-method nil)) + (when-not (= :not-paired card-state) + (navigation/navigate-to-cofx :hardwallet-authentication-method nil))) (when (= card-state :blank) (show-no-keycard-applet-alert)) (when (= card-state :account) @@ -539,9 +540,15 @@ (dispatch-event :hardwallet/pair) (navigation/navigate-to-cofx :hardwallet-connect nil))))) -(fx/defn pair [cofx] - (let [{:keys [password]} (get-in cofx [:db :hardwallet :secrets])] - {:hardwallet/pair {:password password}})) +(fx/defn pair + [{:keys [db] :as cofx}] + (let [{:keys [password]} (get-in cofx [:db :hardwallet :secrets]) + card-connected? (get-in db [:hardwallet :card-connected?])] + (if card-connected? + {:hardwallet/pair {:password password}} + (fx/merge cofx + {:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/pair)} + (navigation/navigate-to-cofx :hardwallet-connect nil))))) (fx/defn return-back-from-nfc-settings [{:keys [db]}] (when (= :hardwallet-connect (:view-id db)) @@ -985,9 +992,13 @@ (fx/defn on-pairing-error [{:keys [db] :as cofx} {:keys [error code]}] (log/debug "[hardwallet] pairing error: " error) - (fx/merge cofx - {:db (assoc-in db [:hardwallet :setup-error] error)} - (process-error code))) + (let [setup-step (get-in db [:hardwallet :setup-step])] + (fx/merge cofx + {:db (-> db + (assoc-in [:hardwallet :setup-error] (i18n/label :t/invalid-pairing-password)) + (assoc-in [:hardwallet :on-card-connected] nil))} + (when (not= setup-step :enter-pair-code) + (process-error code))))) (fx/defn on-generate-mnemonic-success [{:keys [db]} mnemonic] diff --git a/src/status_im/ui/screens/hardwallet/setup/views.cljs b/src/status_im/ui/screens/hardwallet/setup/views.cljs index 10669b8c46..2a49ddc95b 100644 --- a/src/status_im/ui/screens/hardwallet/setup/views.cljs +++ b/src/status_im/ui/screens/hardwallet/setup/views.cljs @@ -206,25 +206,33 @@ (defview enter-pair-code [] (letsubs [pair-code [:hardwallet-pair-code] + error [:hardwallet-setup-error] width [:dimensions/window-width]] - [react/view styles/enter-pair-code-container - [react/view styles/enter-pair-code-title-container - [react/view - [react/text {:style styles/enter-pair-code-title-text} - (i18n/label :t/enter-pair-code)] - [react/text {:style styles/enter-pair-code-explanation-text} - (i18n/label :t/enter-pair-code-description)]] - [react/view (styles/enter-pair-code-input-container width) - [text-input/text-input-with-label - {:on-change-text #(re-frame/dispatch [:hardwallet.ui/pair-code-input-changed %]) - :placeholder ""}]]] - [react/view styles/next-button-container - [react/view components.styles/flex] - [react/view {:margin-right 20} - [components.common/bottom-button - {:on-press #(re-frame/dispatch [:hardwallet.ui/pair-code-next-button-pressed]) - :disabled? (empty? pair-code) - :forward? true}]]]])) + [react/scroll-view + [react/view styles/enter-pair-code-container + [react/view styles/enter-pair-code-title-container + [react/view + [react/text {:style styles/enter-pair-code-title-text} + (i18n/label :t/enter-pair-code)] + [react/text {:style styles/enter-pair-code-explanation-text} + (i18n/label :t/enter-pair-code-description)]] + (when error + [react/view + [react/text {:style {:font-weight "700" + :padding-top 10 + :color colors/red}} + error]]) + [react/view (styles/enter-pair-code-input-container width) + [text-input/text-input-with-label + {:on-change-text #(re-frame/dispatch [:hardwallet.ui/pair-code-input-changed %]) + :placeholder ""}]]] + [react/view styles/next-button-container + [react/view components.styles/flex] + [react/view {:margin-right 20} + [components.common/bottom-button + {:on-press #(re-frame/dispatch [:hardwallet.ui/pair-code-next-button-pressed]) + :disabled? (empty? pair-code) + :forward? true}]]]]])) (defn- card-with-button-view [{:keys [text-label button-label button-container-style on-press show-icon?]}] diff --git a/translations/en.json b/translations/en.json index 4bf9e6bba4..d290e1da1a 100644 --- a/translations/en.json +++ b/translations/en.json @@ -903,6 +903,7 @@ "help": "help", "help-capitalized": "Help", "pairing-card": "Pairing card", + "invalid-pairing-password": "Invalid pairing password", "complete-exclamation": "Complete!", "complete-hardwallet-setup": "This card is now an essential part your account security. Transactions can't be sent without it.", "okay": "Okay",