From 1150626801e8d62697d85e429aa5fb46d7324d17 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Wed, 29 Apr 2020 15:50:36 +0300 Subject: [PATCH] Remove signing/in-progress? flag Signed-off-by: Vitaliy Vlasov --- src/status_im/signing/core.cljs | 28 ++++++++++------------ src/status_im/ui/screens/db.cljs | 2 -- test/cljs/status_im/test/signing/core.cljs | 8 +++---- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/status_im/signing/core.cljs b/src/status_im/signing/core.cljs index f591b1c5a2..55b68f224c 100644 --- a/src/status_im/signing/core.cljs +++ b/src/status_im/signing/core.cljs @@ -191,7 +191,6 @@ (fx/merge cofx {:db (assoc updated-db - :signing/in-progress? true :signing/queue (drop-last queue) :signing/tx tx :signing/sign {:type (cond pinless? :pinless @@ -206,7 +205,6 @@ (fx/merge cofx {:db (assoc updated-db - :signing/in-progress? true :signing/queue (drop-last queue) :signing/tx (prepare-tx updated-db tx)) :dismiss-keyboard nil} @@ -222,8 +220,8 @@ :error-event :signing/update-gas-price-error}}))))) (fx/defn check-queue [{:keys [db] :as cofx}] - (let [{:signing/keys [in-progress? queue]} db] - (when (and (not in-progress?) (seq queue)) + (let [{:signing/keys [tx queue]} db] + (when (and (not tx) (seq queue)) (show-sign cofx)))) (fx/defn send-transaction-message @@ -250,7 +248,7 @@ [{:keys [db] :as cofx} result tx-obj] (let [{:keys [on-result symbol amount]} (get db :signing/tx)] (fx/merge cofx - {:db (dissoc db :signing/tx :signing/in-progress? :signing/sign) + {:db (dissoc db :signing/tx :signing/sign) :signing/show-transaction-result nil} (prepare-unconfirmed-transaction result tx-obj symbol amount) (check-queue) @@ -265,7 +263,7 @@ (subs transaction-hash 2))] (fx/merge cofx - {:db (dissoc db :signing/tx :signing/in-progress? :signing/sign)} + {:db (dissoc db :signing/tx :signing/sign)} (if (hardwallet.common/keycard-multiaccount? db) (signing.keycard/hash-message {:data data @@ -303,7 +301,7 @@ (if (= code constants/send-transaction-err-decrypt) ;;wrong password {:db (assoc-in db [:signing/sign :error] (i18n/label :t/wrong-password))} - (merge {:db (dissoc db :signing/tx :signing/in-progress? :signing/sign) + (merge {:db (dissoc db :signing/tx :signing/sign) :signing/show-transaction-error message} (when on-error {:dispatch (conj on-error message)}))))) @@ -312,7 +310,7 @@ {:events [:signing/dissoc-entries-and-check-queue]} [{:keys [db] :as cofx}] (fx/merge cofx - {:db (dissoc db :signing/tx :signing/in-progress? :signing/sign)} + {:db (dissoc db :signing/tx :signing/sign)} check-queue)) (fx/defn sign-message-completed @@ -321,9 +319,11 @@ (let [{:keys [result error]} (types/json->clj result) on-result (get-in db [:signing/tx :on-result])] (if error - {:db (-> db - (assoc-in [:signing/sign :error] (if (= 5 (:code error)) (i18n/label :t/wrong-password) (:message error))) - (assoc :signing/in-progress? false))} + {:db (update db :signing/sign + assoc :error (if (= 5 (:code error)) + (i18n/label :t/wrong-password) + (:message error)) + :in-progress? false)} (fx/merge cofx (when-not (= (-> db :signing/sign :type) :pinless) (dissoc-signing-db-entries-and-check-queue)) @@ -337,9 +337,7 @@ {:events [:signing/transaction-completed] :interceptors [(re-frame/inject-cofx :random-id-generator)]} [cofx response tx-obj hashed-password] - (let [cofx-in-progress-false (-> cofx - (assoc-in [:db :signing/in-progress?] false) - (assoc-in [:db :signing/sign :in-progress?] false)) + (let [cofx-in-progress-false (assoc-in cofx [:db :signing/sign :in-progress?] false) {:keys [result error]} (types/json->clj response)] (log/debug "transaction-completed" error tx-obj) (if error @@ -356,7 +354,7 @@ (fx/merge cofx {:db (-> db (assoc-in [:hardwallet :pin :status] nil) - (dissoc :signing/tx :signing/in-progress? :signing/sign))} + (dissoc :signing/tx :signing/sign))} (check-queue) (hardwallet.common/hide-connection-sheet) (hardwallet.common/clear-pin) diff --git a/src/status_im/ui/screens/db.cljs b/src/status_im/ui/screens/db.cljs index 2b200b95a5..c12f71e9f1 100644 --- a/src/status_im/ui/screens/db.cljs +++ b/src/status_im/ui/screens/db.cljs @@ -164,7 +164,6 @@ (spec/def :stickers/recent (spec/nilable vector?)) (spec/def :wallet/custom-token-screen (spec/nilable map?)) -(spec/def :signing/in-progress? (spec/nilable boolean?)) (spec/def :signing/queue (spec/nilable any?)) (spec/def :signing/tx (spec/nilable map?)) (spec/def :signing/sign (spec/nilable map?)) @@ -239,7 +238,6 @@ :bottom-sheet/options :wallet/custom-token-screen :wallet/prepare-transaction - :signing/in-progress? :signing/queue :signing/sign :signing/tx diff --git a/test/cljs/status_im/test/signing/core.cljs b/test/cljs/status_im/test/signing/core.cljs index 8331869284..b59d769671 100644 --- a/test/cljs/status_im/test/signing/core.cljs +++ b/test/cljs/status_im/test/signing/core.cljs @@ -20,7 +20,7 @@ sign-second (signing/sign sign-first second-tx)] (testing "after fist transaction" (testing "signing in progress" - (is (get-in sign-first [:db :signing/in-progress?]))) + (is (get-in sign-first [:db :signing/tx]))) (testing "qieue is empty" (is (= (get-in sign-first [:db :signing/queue]) '()))) (testing "first tx object is parsed" @@ -37,15 +37,15 @@ :amount "10"}))))) (testing "after second transaction" (testing "signing still in progress" - (is (get-in sign-second [:db :signing/in-progress?]))) + (is (get-in sign-second [:db :signing/tx]))) (testing "queue is not empty, second tx in queue" (is (= (get-in sign-second [:db :signing/queue]) (list second-tx)))) (testing "check queue does nothing" (is (not (signing/check-queue sign-second)))) - (let [first-discarded (signing/check-queue (update sign-second :db dissoc :signing/in-progress? :signing/tx))] + (let [first-discarded (signing/check-queue (update sign-second :db dissoc :signing/tx))] (testing "after first transaction discarded" (testing "signing still in progress" - (is (get-in first-discarded [:db :signing/in-progress?]))) + (is (get-in first-discarded [:db :signing/tx]))) (testing "qieue is empty" (is (= (get-in first-discarded [:db :signing/queue]) '()))) (testing "second tx object is parsed"