Skip to content

Commit

Permalink
Use new keycard flow with animation
Browse files Browse the repository at this point in the history
Remove screens that are not needed for new flow

Replace keycard flows with new interaction

If card connected start processing on sheet open

Remove outdated pin screens

Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>

Do not hide sheet when tag was lost during generating keys

Change cancel action for no-key on card recovery

Change pin screen when loading keys to an initialised card

Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>
  • Loading branch information
Ferossgp committed Mar 11, 2020
1 parent cc520a1 commit 826b7df
Show file tree
Hide file tree
Showing 33 changed files with 544 additions and 1,021 deletions.
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))
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

0 comments on commit 826b7df

Please sign in to comment.