Skip to content

Commit

Permalink
Remove signing/in-progress? flag
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Vlasov <siphiuel@gmail.com>
  • Loading branch information
Vitaliy Vlasov committed Apr 30, 2020
1 parent e16ed6d commit 1150626
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
28 changes: 13 additions & 15 deletions src/status_im/signing/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)})))))
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/ui/screens/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?))
Expand Down Expand Up @@ -239,7 +238,6 @@
:bottom-sheet/options
:wallet/custom-token-screen
:wallet/prepare-transaction
:signing/in-progress?
:signing/queue
:signing/sign
:signing/tx
Expand Down
8 changes: 4 additions & 4 deletions test/cljs/status_im/test/signing/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 1150626

Please sign in to comment.