Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate keycard interaction animation with keycard flows #10015

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/status_im/hardwallet/card.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

(defonce keycard (.-default js-dependencies/status-keycard))
(defonce event-emitter (.-DeviceEventEmitter js-dependencies/react-native))
(defonce active-listeners (atom []))

(defn- error-object->map [object]
{:code (.-code object)
Expand Down Expand Up @@ -37,6 +38,9 @@
(doseq [event ["keyCardOnConnected" "keyCardOnDisconnected"]]
(.removeAllListeners event-emitter event)))

(defn remove-event-listener [event]
(.remove event))

(defn on-card-connected [callback]
(when (and config/hardwallet-enabled?
platform/android?)
Expand All @@ -48,9 +52,11 @@
(.addListener event-emitter "keyCardOnDisconnected" callback)))

(defn register-card-events []
(remove-event-listeners)
(on-card-connected #(re-frame/dispatch [:hardwallet.callback/on-card-connected %]))
(on-card-disconnected #(re-frame/dispatch [:hardwallet.callback/on-card-disconnected %])))
(doseq [listener @active-listeners]
(remove-event-listener listener))
(reset! active-listeners
[(on-card-connected #(re-frame/dispatch [:hardwallet.callback/on-card-connected]))
(on-card-disconnected #(re-frame/dispatch [:hardwallet.callback/on-card-disconnected]))]))

(defn get-application-info [{:keys [pairing on-success]}]
(log/debug "[keycard] get-application-info")
Expand Down
47 changes: 27 additions & 20 deletions src/status_im/hardwallet/change_pin.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require [status-im.i18n :as i18n]
[status-im.ui.screens.navigation :as navigation]
[status-im.hardwallet.onboarding :as onboarding]
[status-im.multiaccounts.logout.core :as multiaccounts.logout]
[status-im.utils.fx :as fx]
[taoensso.timbre :as log]
[status-im.hardwallet.common :as common]))
Expand Down Expand Up @@ -33,13 +32,23 @@
(assoc-in [:hardwallet :pin :status] nil))}
(navigation/navigate-to-cofx :enter-pin-settings nil)))

(fx/defn discard-pin-change
{:events [::on-cancel]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(common/clear-pin)
(common/hide-pair-sheet)
(if (get-in db [:hardwallet :pin :puk-restore?])
(navigation/navigate-to-cofx :multiaccounts nil)
(navigation/navigate-to-cofx :keycard-settings nil))))

(fx/defn change-pin
{:events [:hardwallet/change-pin]}
[{:keys [db] :as cofx}]
(let [pairing (common/get-pairing db)
new-pin (common/vector->string (get-in db [:hardwallet :pin :original]))
current-pin (common/vector->string (get-in db [:hardwallet :pin :current]))
setup-step (get-in db [:hardwallet :setup-step])
(let [pairing (common/get-pairing db)
new-pin (common/vector->string (get-in db [:hardwallet :pin :original]))
current-pin (common/vector->string (get-in db [:hardwallet :pin :current]))
setup-step (get-in db [:hardwallet :setup-step])
card-connected? (get-in db [:hardwallet :card-connected?])]
(if (= setup-step :pin)
(onboarding/load-preparing-screen cofx)
Expand All @@ -51,40 +60,38 @@
:pairing pairing}})
(fx/merge cofx
(common/set-on-card-connected :hardwallet/change-pin)
(navigation/navigate-to-cofx :hardwallet-connect nil))))))
(common/show-pair-sheet {:on-cancel [::on-cancel]}))))))

(fx/defn on-change-pin-success
{:events [:hardwallet.callback/on-change-pin-success]}
[{:keys [db] :as cofx}]
(let [pin (get-in db [:hardwallet :pin :original])]
(let [pin (get-in db [:hardwallet :pin :original])
puk-restore? (get-in db [:hardwallet :pin :puk-restore?])]
(fx/merge cofx
{:db (assoc-in db [:hardwallet :pin] {:status nil
:login pin
:confirmation []
:error-label nil})
:utils/show-popup {:title ""
:content (i18n/label :t/pin-changed)}}
(common/clear-on-card-connected)
(when (:multiaccounts/login db)
(navigation/navigate-to-cofx :keycard-login-pin nil))
(common/hide-pair-sheet)
(if puk-restore?
(navigation/navigate-to-cofx :multiaccounts nil)
(navigation/navigate-to-cofx :keycard-settings nil))
(when (:multiaccounts/login db)
(common/get-keys-from-keycard))
(when (:multiaccount/multiaccount db)
(multiaccounts.logout/logout)))))
(common/get-keys-from-keycard)))))

(fx/defn on-change-pin-error
{:events [:hardwallet.callback/on-change-pin-error]}
[{:keys [db] :as cofx} error]
(log/debug "[hardwallet] change pin error" error)
(let [tag-was-lost? (= "Tag was lost." (:error error))]
(let [tag-was-lost? (= "Tag was lost." (:error error))
Ferossgp marked this conversation as resolved.
Show resolved Hide resolved
pairing (common/get-pairing db)]
(fx/merge cofx
(if tag-was-lost?
(fx/merge cofx
{:db (assoc-in db [:hardwallet :pin :status] nil)
:utils/show-popup {:title (i18n/label :t/error)
:content (i18n/label :t/cannot-read-card)}}
(common/set-on-card-connected :hardwallet/change-pin)
(navigation/navigate-to-cofx :hardwallet-connect nil))
{:db (assoc-in db [:hardwallet :pin :status] nil)}
(common/set-on-card-connected :hardwallet/change-pin))
(if (re-matches common/pin-mismatch-error (:error error))
(fx/merge cofx
{:db (update-in db [:hardwallet :pin] merge {:status :error
Expand All @@ -96,5 +103,5 @@
:sign []
:error-label :t/pin-mismatch})}
(navigation/navigate-to-cofx :enter-pin-settings nil)
(common/get-application-info (common/get-pairing db) nil))
(common/get-application-info pairing nil))
(common/show-wrong-keycard-alert true))))))
Loading