From 1f24f1c4f688bd5b6aaa3501319ea5997b4d4c0e Mon Sep 17 00:00:00 2001 From: Dmitry Novotochinov Date: Tue, 30 Apr 2019 13:49:33 +0300 Subject: [PATCH] [#7897] fix navigation bug on keycard tx sign Signed-off-by: Dmitry Novotochinov --- src/status_im/accounts/login/core.cljs | 9 ++- .../chat/commands/impl/transactions.cljs | 1 + src/status_im/hardwallet/core.cljs | 58 ++++++++++--------- src/status_im/models/wallet.cljs | 6 ++ .../ui/components/bottom_bar/core.cljs | 4 +- src/status_im/ui/screens/events.cljs | 12 +++- .../ui/screens/routing/chat_stack.cljs | 33 +++++------ .../ui/screens/routing/intro_login_stack.cljs | 6 +- src/status_im/ui/screens/routing/modals.cljs | 10 ++-- .../ui/screens/routing/profile_stack.cljs | 9 +-- src/status_im/ui/screens/routing/screens.cljs | 8 ++- .../ui/screens/routing/wallet_stack.cljs | 4 +- .../ui/screens/wallet/send/events.cljs | 43 +++++++++++--- 13 files changed, 127 insertions(+), 76 deletions(-) diff --git a/src/status_im/accounts/login/core.cljs b/src/status_im/accounts/login/core.cljs index 7e1a9ba67a..fdbe8b6825 100644 --- a/src/status_im/accounts/login/core.cljs +++ b/src/status_im/accounts/login/core.cljs @@ -263,9 +263,12 @@ (fx/defn open-keycard-login [{:keys [db] :as cofx}] - (fx/merge cofx - {:db (assoc-in db [:hardwallet :pin :enter-step] :login)} - (navigation/navigate-to-cofx :enter-pin nil))) + (let [navigation-stack (:navigation-stack db)] + (fx/merge cofx + {:db (assoc-in db [:hardwallet :pin :enter-step] :login)} + (if (empty? navigation-stack) + (navigation/navigate-to-cofx :accounts nil) + (navigation/navigate-to-cofx :enter-pin-login nil))))) (fx/defn get-user-password [_ address] diff --git a/src/status_im/chat/commands/impl/transactions.cljs b/src/status_im/chat/commands/impl/transactions.cljs index 12327ce079..69633f4183 100644 --- a/src/status_im/chat/commands/impl/transactions.cljs +++ b/src/status_im/chat/commands/impl/transactions.cljs @@ -309,6 +309,7 @@ :wallet-send-modal-stack-with-onboarding)] (fx/merge cofx {:db (-> db + (assoc-in [:navigation/screen-params :wallet-send-modal-stack :modal?] true) (update-in [:wallet :send-transaction] assoc :amount (money/formatted->internal value symbol decimals) diff --git a/src/status_im/hardwallet/core.cljs b/src/status_im/hardwallet/core.cljs index 16e69c786a..8d7a5c55be 100644 --- a/src/status_im/hardwallet/core.cljs +++ b/src/status_im/hardwallet/core.cljs @@ -43,17 +43,15 @@ (fx/defn navigate-back-button-clicked [{:keys [db] :as cofx}] - (let [screen-before (second (get db :navigation-stack)) - navigate-to-browser? (contains? #{:wallet-sign-message-modal - :wallet-send-transaction-modal - :wallet-send-modal-stack} screen-before)] - (if (nil? screen-before) - (navigation/navigate-to-cofx cofx :accounts nil) - (if navigate-to-browser? - (fx/merge cofx - {:db (assoc-in db [:hardwallet :on-card-connected] nil)} - (models.wallet/discard-transaction) - (navigation/navigate-to-cofx :browser nil)) + (let [screen-before (set (take 4 (:navigation-stack db))) + navigate-to-browser? (contains? screen-before :browser-stack)] + (if navigate-to-browser? + (fx/merge cofx + {:db (assoc-in db [:hardwallet :on-card-connected] nil)} + (models.wallet/discard-transaction) + (navigation/navigate-to-cofx :browser nil)) + (if (= :enter-pin-login (:view-id db)) + (navigation/navigate-to-clean cofx :accounts nil) (fx/merge cofx {:db (assoc-in db [:hardwallet :on-card-connected] nil)} (navigation/navigate-back)))))) @@ -174,7 +172,7 @@ (= keycard-instance-uid account-instance-uid))) (fx/merge cofx {:db (assoc-in db [:hardwallet :pin :current] [])} - (navigation/navigate-to-cofx :enter-pin nil)) + (navigation/navigate-to-cofx :enter-pin-settings nil)) (unauthorized-operation cofx)))) (fx/defn navigate-to-authentication-method @@ -282,7 +280,7 @@ {:db (-> db (assoc :accounts/login (select-keys account [:address :name :photo-path])) (assoc-in [:hardwallet :pin :enter-step] :login))} - (navigation/navigate-to-cofx :enter-pin nil)) + (navigation/navigate-to-cofx :enter-pin-login nil)) :else (get-keys-from-keycard cofx)))) @@ -395,7 +393,7 @@ :on-verified :hardwallet/proceed-to-change-pin}))} (if card-connected? (navigate-to-enter-pin-screen) - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil))))) (fx/defn proceed-to-change-pin [{:keys [db]}] @@ -428,7 +426,7 @@ :on-verified :hardwallet/unpair}))} (if card-connected? (navigate-to-enter-pin-screen) - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil))))) (defn- vector->string [v] "Converts numbers stored in vector into string, @@ -459,7 +457,7 @@ :pairing pairing}} (fx/merge cofx {:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/remove-key-with-unpair)} - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil))))) (fx/defn on-remove-key-success [{:keys [db] :as cofx}] @@ -493,7 +491,7 @@ (assoc-in [:hardwallet :pin :status] nil)) :utils/show-popup {:title (i18n/label :t/error) :content (i18n/label :t/cannot-read-card)}} - (navigation/navigate-to-cofx :hardwallet-connect nil)) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil)) (show-wrong-keycard-alert cofx true))))) (fx/defn on-delete-success @@ -535,7 +533,7 @@ (navigation/navigate-to-cofx cofx :reset-card nil) (fx/merge cofx {:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/navigate-to-reset-card-screen)} - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil))))) (fx/defn delete-card [{:keys [db] :as cofx}] @@ -572,7 +570,7 @@ :on-verified :hardwallet/remove-key-with-unpair}))} (if card-connected? (navigate-to-enter-pin-screen) - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil))))) (fx/defn error-button-pressed [{:keys [db] :as cofx}] @@ -604,7 +602,9 @@ (navigation/navigate-to-cofx :hardwallet-connect nil))))) (fx/defn return-back-from-nfc-settings [{:keys [db]}] - (when (= :hardwallet-connect (:view-id db)) + (when (contains? #{:hardwallet-connect + :hardwallet-connect-sign + :hardwallet-connect-settings} (:view-id db)) {:hardwallet/check-nfc-enabled nil})) (defn- proceed-to-pin-confirmation [fx] @@ -651,7 +651,7 @@ :current [0 0 0 0 0 0] :puk [] :error-label nil}))} - (navigation/navigate-to-cofx :enter-pin nil)))) + (navigation/navigate-to-cofx :enter-pin-settings nil)))) (defn on-unblock-pin-error [{:keys [db]} error] @@ -760,7 +760,7 @@ :pairing pairing}} (fx/merge cofx {:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/verify-pin)} - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil))))) (defn- unblock-pin [{:keys [db] :as cofx}] @@ -775,7 +775,7 @@ :pairing pairing}} (fx/merge cofx {:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/unblock-pin)} - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-settings nil))))) (def pin-code-length 6) (def puk-code-length 12) @@ -837,7 +837,7 @@ {:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/sign)} (when-not keycard-match? (show-wrong-keycard-alert card-connected?)) - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx :hardwallet-connect-sign nil))))) (fx/defn prepare-to-sign [{:keys [db] :as cofx}] @@ -847,7 +847,11 @@ (get-application-info cofx pairing :hardwallet/sign) (fx/merge cofx {:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/prepare-to-sign)} - (navigation/navigate-to-cofx :hardwallet-connect nil))))) + (navigation/navigate-to-cofx + (if (= (:view-id db) :enter-pin-modal) + :hardwallet-connect-modal + :hardwallet-connect-sign) + nil))))) ; PIN enter steps: ; login - PIN is used to login @@ -1247,7 +1251,7 @@ :db (update-in db [:hardwallet :pin] merge {:status :error :login [] :error-label :t/pin-mismatch})} - (navigation/navigate-to-cofx :enter-pin nil))))) + (navigation/navigate-to-cofx :enter-pin-login nil))))) (fx/defn send-transaction-with-signature [_ data] @@ -1295,6 +1299,6 @@ {:db (update-in db [:hardwallet :pin] merge {:status :error :sign [] :error-label :t/pin-mismatch})} - (navigation/navigate-to-cofx :enter-pin nil) + (navigation/navigate-to-cofx :enter-pin-sign nil) (get-application-info (get-pairing db) nil)) (show-wrong-keycard-alert cofx true))) diff --git a/src/status_im/models/wallet.cljs b/src/status_im/models/wallet.cljs index 25c773befd..1a6f7ee8b9 100644 --- a/src/status_im/models/wallet.cljs +++ b/src/status_im/models/wallet.cljs @@ -238,6 +238,7 @@ (let [{:keys [gas gas-price]} transaction {:keys [wallet-set-up-passed?]} (:account/account db)] {:db (-> db + (assoc-in [:navigation/screen-params :wallet-send-modal-stack :modal?] true) (assoc-in [:wallet :send-transaction] transaction) (assoc-in [:wallet :send-transaction :original-gas] gas)) :dispatch-n [[:update-wallet] @@ -257,6 +258,7 @@ :wallet-send-modal-stack-with-onboarding)] (fx/merge cofx (cond-> {:db (-> db + (assoc-in [:navigation/screen-params :wallet-send-modal-stack :modal?] true) (assoc-in [:wallet :send-transaction] transaction) (assoc-in [:wallet :send-transaction :original-gas] @@ -274,3 +276,7 @@ :edit? false})) (update-wallet) (navigation/navigate-to-cofx go-to-view-id {})))) + +(defn send-transaction-screen-did-load + [{:keys [db]}] + {:db (assoc-in db [:navigation/screen-params :wallet-send-modal-stack :modal?] false)}) diff --git a/src/status_im/ui/components/bottom_bar/core.cljs b/src/status_im/ui/components/bottom_bar/core.cljs index 196ae51532..2c2e4f0b63 100644 --- a/src/status_im/ui/components/bottom_bar/core.cljs +++ b/src/status_im/ui/components/bottom_bar/core.cljs @@ -130,7 +130,9 @@ (minimize-bar new-view-id)))) :reagent-render (fn [keyboard-shown? view-id tab] - (when (not= view-id :enter-pin) + (when-not (contains? #{:enter-pin-login + :enter-pin-sign + :enter-pin-settings} view-id) (if platform/ios? [tabs-animation-wrapper-ios [react/animated-view diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index 7d3e78781b..ae3a3f87a9 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -33,7 +33,8 @@ [status-im.utils.handlers :as handlers] [status-im.utils.http :as http] [status-im.utils.utils :as utils] - [status-im.utils.fx :as fx])) + [status-im.utils.fx :as fx] + [status-im.models.wallet :as wallet])) (defn- http-get [{:keys [url response-validator success-event-creator failure-event-creator timeout-ms]}] (let [on-success #(re-frame/dispatch (success-event-creator %)) @@ -188,9 +189,16 @@ #(case view-id :keycard-settings (hardwallet/settings-screen-did-load %) :reset-card (hardwallet/reset-card-screen-did-load %) - :enter-pin (hardwallet/enter-pin-screen-did-load %) + :enter-pin-login (hardwallet/enter-pin-screen-did-load %) + :enter-pin-sign (hardwallet/enter-pin-screen-did-load %) + :enter-pin-settings (hardwallet/enter-pin-screen-did-load %) + :enter-pin-modal (hardwallet/enter-pin-screen-did-load %) :hardwallet-connect (hardwallet/hardwallet-connect-screen-did-load %) + :hardwallet-connect-sign (hardwallet/hardwallet-connect-screen-did-load %) + :hardwallet-connect-settings (hardwallet/hardwallet-connect-screen-did-load %) + :hardwallet-connect-modal (hardwallet/hardwallet-connect-screen-did-load %) :hardwallet-authentication-method (hardwallet/authentication-method-screen-did-load %) + :wallet-send-transaction (wallet/send-transaction-screen-did-load %) :accounts (hardwallet/accounts-screen-did-load %) :chat (mark-messages-seen %) nil)))) diff --git a/src/status_im/ui/screens/routing/chat_stack.cljs b/src/status_im/ui/screens/routing/chat_stack.cljs index f381a91bdf..cc42d92640 100644 --- a/src/status_im/ui/screens/routing/chat_stack.cljs +++ b/src/status_im/ui/screens/routing/chat_stack.cljs @@ -1,22 +1,19 @@ -(ns status-im.ui.screens.routing.chat-stack - (:require [status-im.utils.config :as config])) +(ns status-im.ui.screens.routing.chat-stack) (def chat-stack {:name :chat-stack - :screens (cond-> [:home - :chat - :profile - :new - :new-chat - :qr-scanner - :take-picture - :new-group - :add-participants-toggle-list - :contact-toggle-list - :group-chat-profile - :new-public-chat - :stickers - :stickers-pack] - config/hardwallet-enabled? - (concat [:hardwallet-connect :enter-pin])) + :screens [:home + :chat + :profile + :new + :new-chat + :qr-scanner + :take-picture + :new-group + :add-participants-toggle-list + :contact-toggle-list + :group-chat-profile + :new-public-chat + :stickers + :stickers-pack] :config {:initialRouteName :home}}) diff --git a/src/status_im/ui/screens/routing/intro_login_stack.cljs b/src/status_im/ui/screens/routing/intro_login_stack.cljs index 5c2a6fdfd7..6a8285816c 100644 --- a/src/status_im/ui/screens/routing/intro_login_stack.cljs +++ b/src/status_im/ui/screens/routing/intro_login_stack.cljs @@ -10,7 +10,7 @@ :intro :hardwallet-authentication-method :hardwallet-connect - :enter-pin + :enter-pin-login :hardwallet-setup :hardwallet-success}) @@ -25,13 +25,13 @@ config/hardwallet-enabled? (concat [:hardwallet-authentication-method :hardwallet-connect - :enter-pin + :enter-pin-login :hardwallet-setup :hardwallet-success])) :config (if ;; add view-id here if you'd like that view to be ;; first view when app is started - (#{:login :progress :accounts :enter-pin} view-id) + (#{:login :progress :accounts :enter-pin-login} view-id) {:initialRouteName view-id} {:initialRouteName :login})}) diff --git a/src/status_im/ui/screens/routing/modals.cljs b/src/status_im/ui/screens/routing/modals.cljs index ba50b80ccd..20d98b02c9 100644 --- a/src/status_im/ui/screens/routing/modals.cljs +++ b/src/status_im/ui/screens/routing/modals.cljs @@ -5,22 +5,24 @@ :screens [:wallet-send-transaction-modal :wallet-transaction-sent-modal :wallet-transaction-fee - :hardwallet-connect - :enter-pin] + :hardwallet-connect-modal + :enter-pin-modal] :config {:initialRouteName :wallet-send-transaction-modal}} {:name :wallet-send-modal-stack-with-onboarding :screens [:wallet-onboarding-setup-modal :wallet-send-transaction-modal :wallet-transaction-sent-modal :wallet-transaction-fee - :hardwallet-connect - :enter-pin] + :hardwallet-connect-modal + :enter-pin-modal] :config {:initialRouteName :wallet-onboarding-setup-modal}} :chat-modal :show-extension-modal :stickers-pack-modal :tribute-learn-more :wallet-sign-message-modal + :enter-pin-modal + :hardwallet-connect-modal :selection-modal-screen :wallet-settings-assets :wallet-transaction-fee diff --git a/src/status_im/ui/screens/routing/profile_stack.cljs b/src/status_im/ui/screens/routing/profile_stack.cljs index bd3454eaee..773e946899 100644 --- a/src/status_im/ui/screens/routing/profile_stack.cljs +++ b/src/status_im/ui/screens/routing/profile_stack.cljs @@ -32,11 +32,8 @@ :my-profile-ext-settings] config/hardwallet-enabled? - (concat [:hardwallet-authentication-method - :hardwallet-connect - :hardwallet-setup - :hardwallet-success - :keycard-settings + (concat [:keycard-settings :reset-card - :enter-pin])) + :hardwallet-connect-settings + :enter-pin-settings])) :config {:initialRouteName :my-profile}}) diff --git a/src/status_im/ui/screens/routing/screens.cljs b/src/status_im/ui/screens/routing/screens.cljs index b835c38c1e..05fd0886b2 100644 --- a/src/status_im/ui/screens/routing/screens.cljs +++ b/src/status_im/ui/screens/routing/screens.cljs @@ -87,7 +87,13 @@ :intro intro/intro :hardwallet-authentication-method hardwallet.authentication/hardwallet-authentication-method :hardwallet-connect hardwallet.connect/hardwallet-connect - :enter-pin hardwallet.pin/enter-pin + :hardwallet-connect-settings hardwallet.connect/hardwallet-connect + :hardwallet-connect-sign hardwallet.connect/hardwallet-connect + :hardwallet-connect-modal [:modal hardwallet.connect/hardwallet-connect] + :enter-pin-login hardwallet.pin/enter-pin + :enter-pin-settings hardwallet.pin/enter-pin + :enter-pin-sign hardwallet.pin/enter-pin + :enter-pin-modal [:modal hardwallet.pin/enter-pin] :hardwallet-setup hardwallet.setup/hardwallet-setup :hardwallet-success hardwallet.success/hardwallet-success :home home/home-wrapper diff --git a/src/status_im/ui/screens/routing/wallet_stack.cljs b/src/status_im/ui/screens/routing/wallet_stack.cljs index faabfa1c08..1a7608c397 100644 --- a/src/status_im/ui/screens/routing/wallet_stack.cljs +++ b/src/status_im/ui/screens/routing/wallet_stack.cljs @@ -11,8 +11,8 @@ :screens [:wallet-send-transaction :recent-recipients :wallet-transaction-sent - :enter-pin - :hardwallet-connect + :enter-pin-sign + :hardwallet-connect-sign :recipient-qr-code :wallet-send-assets]} {:name :request-transaction-stack diff --git a/src/status_im/ui/screens/wallet/send/events.cljs b/src/status_im/ui/screens/wallet/send/events.cljs index f7fe366ea5..67b16126a0 100644 --- a/src/status_im/ui/screens/wallet/send/events.cljs +++ b/src/status_im/ui/screens/wallet/send/events.cljs @@ -117,7 +117,8 @@ (let [{:keys [id method public-key to symbol amount-text on-result on-error send-transaction-message?]} (get-in db [:wallet :send-transaction]) - db' (assoc-in db [:wallet :send-transaction :in-progress?] false)] + db' (assoc-in db [:wallet :send-transaction :in-progress?] false) + modal-screen-was-used? (get-in db [:navigation/screen-params :wallet-send-modal-stack :modal?])] (if error ;; ERROR (models.wallet/handle-transaction-error (assoc cofx :db db') error) @@ -143,9 +144,9 @@ #(when-not on-result (navigation/navigate-to-clean % - (if (contains? #{:wallet-send-transaction :enter-pin :hardwallet-connect} (:view-id db)) - :wallet-transaction-sent - :wallet-transaction-sent-modal) + (if modal-screen-was-used? + :wallet-transaction-sent-modal + :wallet-transaction-sent) {}))))))) (re-frame/reg-fx @@ -168,7 +169,8 @@ (handlers/register-handler-fx ::hash-message-completed (fn [{:keys [db] :as cofx} [_ {:keys [result error]}]] - (let [db' (assoc-in db [:wallet :send-transaction :in-progress?] false)] + (let [view-id (:view-id db) + db' (assoc-in db [:wallet :send-transaction :in-progress?] false)] (if error ;; ERROR (models.wallet/handle-transaction-error (assoc cofx :db db') error) @@ -177,7 +179,13 @@ {:db (-> db (assoc-in [:hardwallet :pin :enter-step] :sign) (assoc-in [:hardwallet :hash] result))} - (navigation/navigate-to-cofx :enter-pin nil)))))) + (navigation/navigate-to-cofx + (if (contains? + #{:wallet-sign-message-modal :wallet-send-transaction-modal :wallet-send-modal-stack} + view-id) + :enter-pin-modal + :enter-pin-sign) + nil)))))) ;; DISCARD TRANSACTION (handlers/register-handler-fx @@ -345,7 +353,7 @@ (re-frame/reg-fx ::hash-transaction - (fn [{:keys [transaction all-tokens symbol chain on-completed]}] + (fn [{:keys [transaction on-completed]}] (status/hash-transaction (types/clj->json transaction) on-completed))) (re-frame/reg-fx @@ -358,12 +366,23 @@ (fn [{:keys [data on-completed]}] (status/hash-typed-data data on-completed))) +(defn- prepare-keycard-transaction + [transaction from symbol chain all-tokens] + (if (= :ETH symbol) + (models.wallet/prepare-send-transaction from transaction) + (let [contract (:address (tokens/symbol->token all-tokens (keyword chain) symbol)) + {:keys [gas gasPrice to from value]} (models.wallet/prepare-send-transaction from transaction)] + (merge (ethereum/call-params contract "transfer(address,uint256)" to value) + {:from from + :gas gas + :gasPrice gasPrice})))) + (defn send-keycard-transaction [{{:keys [chain] :as db} :db}] (let [{:keys [symbol] :as transaction} (get-in db [:wallet :send-transaction]) all-tokens (:wallet/all-tokens db) from (get-in db [:account/account :address])] - {::hash-transaction {:transaction (models.wallet/prepare-send-transaction from transaction) + {::hash-transaction {:transaction (prepare-keycard-transaction transaction from symbol chain all-tokens) :all-tokens all-tokens :symbol symbol :chain chain @@ -378,7 +397,13 @@ (assoc-in [:hardwallet :pin :enter-step] :sign) (assoc-in [:hardwallet :transaction] transaction) (assoc-in [:hardwallet :hash] hash))} - (navigation/navigate-to-clean :enter-pin nil))))) + (navigation/navigate-to-clean + (if (contains? + #{:wallet-sign-message-modal :wallet-send-transaction-modal :wallet-send-modal-stack} + (:view-id db)) + :enter-pin-modal + :enter-pin-sign) + nil))))) (handlers/register-handler-fx :wallet.ui/sign-transaction-button-clicked