From f3c5cd9700450417f2afce85ec7644e73deda241 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 26 Oct 2016 18:30:31 +0300 Subject: [PATCH] reset password after 3 wrong attempts & close transactions screen if there are no transactions (#371, #372) Former-commit-id: bda65d6f1b9d782cd2e0c7352222567f99c9511c --- .../react-native-status/android/build.gradle | 2 +- .../react-native-status/ios/RCTStatus/pom.xml | 2 +- project.clj | 4 +- src/status_im/db.cljs | 6 +-- src/status_im/handlers.cljs | 4 +- src/status_im/transactions/handlers.cljs | 45 ++++++++++++++----- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/modules/react-native-status/android/build.gradle b/modules/react-native-status/android/build.gradle index 7178e15b01..693742cdd0 100644 --- a/modules/react-native-status/android/build.gradle +++ b/modules/react-native-status/android/build.gradle @@ -14,5 +14,5 @@ android { dependencies { compile 'com.facebook.react:react-native:+' - compile(group: 'status-im', name: 'status-go', version: '0.1.2', ext: 'aar') + compile(group: 'status-im', name: 'status-go', version: 'tx-complete-updates-3', ext: 'aar') } diff --git a/modules/react-native-status/ios/RCTStatus/pom.xml b/modules/react-native-status/ios/RCTStatus/pom.xml index 306a915461..3469204d7d 100644 --- a/modules/react-native-status/ios/RCTStatus/pom.xml +++ b/modules/react-native-status/ios/RCTStatus/pom.xml @@ -25,7 +25,7 @@ status-im status-go-ios - 0.1.2 + tx-complete-updates-3 zip true ./ diff --git a/project.clj b/project.clj index 4fce99cfa7..a70b9fea77 100644 --- a/project.clj +++ b/project.clj @@ -7,12 +7,10 @@ [org.clojure/clojurescript "1.9.229"] [reagent "0.5.1" :exclusions [cljsjs/react]] [re-frame "0.7.0"] - [prismatic/schema "1.0.4"] [natal-shell "0.3.0"] [com.andrewmcveigh/cljs-time "0.4.0"] [tailrecursion/cljs-priority-map "1.2.0"] - [com.taoensso/timbre "4.7.4"] - [org.clojure/test.check "0.9.0"]] + [com.taoensso/timbre "4.7.4"]] :plugins [[lein-cljsbuild "1.1.4"] [lein-figwheel "0.5.0-2"]] :clean-targets ["target/" "index.ios.js" "index.android.js"] diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index dd58dd0d7d..cabfc1ad8a 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -1,12 +1,8 @@ (ns status-im.db - (:require [schema.core :as s :include-macros true] - [status-im.components.react :refer [animated]] + (:require [status-im.components.react :refer [animated]] [status-im.components.animation :as anim] [status-im.constants :refer [console-chat-id]])) -;; schema of app-db -(def schema {:greeting s/Str}) - ;; initial state of app-db (def app-db {:identity-password "replace-me-with-user-entered-password" :identity "me" diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index fae1e4f647..fc5db798b3 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -1,8 +1,7 @@ (ns status-im.handlers (:require [re-frame.core :refer [after dispatch dispatch-sync debug]] - [schema.core :as s :include-macros true] - [status-im.db :refer [app-db schema]] + [status-im.db :refer [app-db]] [status-im.data-store.core :as data-store] [taoensso.timbre :as log] [status-im.utils.crypt :refer [gen-random-bytes]] @@ -109,6 +108,7 @@ (let [{:keys [type event]} (t/json->clj event-str)] (case type "transaction.queued" (dispatch [:transaction-queued event]) + "transaction.failed" (dispatch [:transaction-failed event]) "node.started" (log/debug "Event *node.started* received") "module.initialized" (dispatch [:status-module-initialized!]) (log/debug "Event " type " not handled")))))) diff --git a/src/status_im/transactions/handlers.cljs b/src/status_im/transactions/handlers.cljs index d135b9c778..d60112aa36 100644 --- a/src/status_im/transactions/handlers.cljs +++ b/src/status_im/transactions/handlers.cljs @@ -23,7 +23,11 @@ (defmethod nav/preload-data! :confirm [{:keys [transactions-queue] :as db} _] - (assoc db :transactions transactions-queue)) + (-> db + (assoc :transactions transactions-queue + :wrong-password-counter 0 + :wrong-password? false) + (assoc-in [:confirm-transactions :password] 0))) (defn on-unlock [ids password previous-view-id] @@ -69,6 +73,9 @@ (update :transactions-queue #(apply dissoc % hashes))))) (register-handler ::remove-transaction + (after (fn [{:keys [transactions]}] + (when-not (seq transactions) + (dispatch [:navigate-back])))) (fn [db [_ hash]] (-> db (update :transactions dissoc hash) @@ -122,19 +129,11 @@ (register-handler :transaction-completed (u/side-effect! - (fn [{:keys [transactions command->chat]} [_ {:keys [id response previous-view-id]}]] + (fn [{:keys [transactions]} [_ {:keys [id response previous-view-id]}]] (let [{:keys [hash error] :as parsed-response} (t/json->clj response) {:keys [message-id]} (transactions id)] (log/debug :parsed-response parsed-response) - (if (and error (string? error) (not (s/blank? error))) - ;; todo: revisit this - ;; currently transaction is removed after attempt - ;; to complete it with wrong password - (do - (dispatch [::remove-transaction id]) - (dispatch [:set :wrong-password? true]) - (when-let [chat-id (get command->chat message-id)] - (dispatch [:clear-command chat-id message-id]))) + (when-not (and error (string? error) (not (s/blank? error))) (if message-id (do (dispatch [::add-transactions-hash {:id id :hash hash @@ -172,3 +171,27 @@ (when (and pending-message id hash) (dispatch [::send-pending-message message-id hash]) (dispatch [::remove-transaction id])))))) + +(def wrong-password-code "2") + +(register-handler :transaction-failed + (u/side-effect! + (fn [_ [_ {:keys [id message_id error_code]}]] + (if-not (= wrong-password-code error_code) + (do (when message_id + (dispatch [::remove-pending-message message_id])) + (dispatch [::remove-transaction id])) + (dispatch [:set-wrong-password!]))))) + +(def attempts-limit 3) + +(register-handler :set-wrong-password! + (after (fn [{:keys [wrong-password-counter]}] + (when (>= wrong-password-counter attempts-limit) + (dispatch [:set :wrong-password? false]) + (dispatch [:set :wrong-password-counter 0]) + (dispatch [:set-in [:confirm-transactions :password] ""])))) + (fn [db] + (-> db + (assoc :wrong-password? true) + (update :wrong-password-counter (fnil inc 0)))))