-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8c089bb
commit ed10ed7
Showing
11 changed files
with
221 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
(ns status-im.contexts.keycard.unblock.events | ||
(:require [utils.re-frame :as rf] | ||
[utils.security.core :as security])) | ||
|
||
(rf/reg-event-fx :keycard/unblock.pin-created | ||
(fn [{:keys [db]} [pin]] | ||
{:db (assoc-in db [:keycard :unblock :pin] pin) | ||
:fx [[:dispatch [:navigate-back]] | ||
[:dispatch [:open-modal :screen/keycard.unblock.ready-to-unblock]]]})) | ||
|
||
(rf/reg-event-fx :keycard/unblock.phrase-entered | ||
(fn [{:keys [db]} [{:keys [phrase]}]] | ||
{:db (assoc-in db [:keycard :unblock :masked-phrase] phrase) | ||
:fx [[:dispatch [:navigate-back]] | ||
[:dispatch | ||
[:open-modal :screen/keycard.pin.create | ||
{:on-complete #(rf/dispatch [:keycard/unblock.pin-created %])}]]]})) | ||
|
||
(rf/reg-event-fx :keycard/unblock.generate-and-load-key | ||
(fn [{:keys [db]}] | ||
(let [{:keys [masked-phrase pin]} (get-in db [:keycard :unblock])] | ||
{:fx [[:effects.keycard/generate-and-load-key | ||
{:mnemonic (security/safe-unmask-data masked-phrase) | ||
:pin pin | ||
:on-success (fn [] | ||
(rf/dispatch [:keycard/disconnect]) | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:open-modal :screen/keycard.unblock.success]))}]]}))) | ||
|
||
;; third stage, import keys | ||
(rf/reg-event-fx :keycard/unblock.import-keys | ||
(fn [] | ||
{:fx [[:dispatch | ||
[:keycard/connect.next-stage | ||
{:on-error (fn [error] | ||
(if (= error :keycard/error.keycard-empty) | ||
(rf/dispatch [:keycard/unblock.generate-and-load-key]) | ||
(do | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:keycard/on-application-info-error error]))))}]]]})) | ||
|
||
;; second stage, check if card initialized | ||
(rf/reg-event-fx :keycard/unblock.init-card-or-import-keys | ||
(fn [{:keys [db]}] | ||
(let [pin (get-in db [:keycard :unblock :pin]) | ||
{:keys [initialized?]} (get-in db [:keycard :application-info])] | ||
{:fx [(if initialized? | ||
[:dispatch [:keycard/unblock.import-keys]] | ||
[:effects.keycard/init-card | ||
{:pin pin | ||
:on-success #(rf/dispatch [:keycard/unblock.import-keys])}])]}))) | ||
|
||
;; second stage, init card with pin | ||
(defn init-with-pin | ||
[] | ||
(rf/dispatch | ||
[:keycard/connect.next-stage | ||
{:on-error (fn [error] | ||
(if (= error :keycard/error.keycard-empty) | ||
(rf/dispatch [:keycard/unblock.init-card-or-import-keys]) | ||
(do | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:keycard/on-application-info-error error]))))}])) | ||
|
||
;; first stage, reset card | ||
(rf/reg-event-fx :keycard/unblock | ||
(fn [{:keys [db]}] | ||
{:fx [[:dispatch | ||
[:keycard/connect | ||
{:key-uid (get-in db [:keycard :application-info :key-uid]) | ||
:on-error (fn [error] | ||
(cond | ||
(or (= error :keycard/error.keycard-frozen) | ||
(= error :keycard/error.keycard-locked)) | ||
(rf/dispatch [:keycard/factory-reset {:on-success init-with-pin}]) | ||
|
||
(= error :keycard/error.keycard-empty) | ||
(init-with-pin) | ||
|
||
:else | ||
(do | ||
(rf/dispatch [:navigate-back]) | ||
(if (= error :keycard/error.keycard-wrong-profile) | ||
(do | ||
(rf/dispatch [:keycard/disconnect]) | ||
(rf/dispatch [:open-modal :screen/keycard.different-card])) | ||
(rf/dispatch [:keycard/on-application-info-error error])))))}]]]})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
(ns status-im.contexts.keycard.unblock.view | ||
(:require [quo.core :as quo] | ||
[react-native.core :as rn] | ||
[status-im.common.events-helper :as events-helper] | ||
[status-im.contexts.keycard.common.view :as common.view] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn success-view | ||
[] | ||
[:<> | ||
[quo/page-nav | ||
{:icon-name :i/close | ||
:on-press events-helper/navigate-back}] | ||
[quo/page-top | ||
{:title (i18n/label :t/keycard-unblocked)}] | ||
[rn/view {:style {:flex 1}}] | ||
[rn/view {:style {:padding-horizontal 20}} | ||
[quo/button {:on-press events-helper/navigate-back} | ||
(i18n/label :t/done)]]]) | ||
|
||
(defn ready-to-unblock | ||
[] | ||
[:<> | ||
[quo/page-nav | ||
{:icon-name :i/close | ||
:on-press events-helper/navigate-back}] | ||
[quo/page-top | ||
{:title (i18n/label :t/ready-to-unblock-keycard)}] | ||
[rn/view {:style {:flex 1}}] | ||
[common.view/tips] | ||
[quo/bottom-actions | ||
{:actions :one-action | ||
:button-one-label (i18n/label :t/scan-keycard) | ||
:button-one-props {:on-press #(rf/dispatch [:keycard/unblock])}}]]) | ||
|
||
(defn sheet | ||
[] | ||
(let [customization-color (rf/sub [:profile/customization-color])] | ||
[:<> | ||
[quo/drawer-top {:title (i18n/label :t/unblock-keycard-recovery)}] | ||
[quo/text | ||
{:style {:padding-horizontal 20 | ||
:padding-vertical 8}} | ||
(i18n/label :t/unblock-keycard-instructions)] | ||
[quo/bottom-actions | ||
{:actions :two-actions | ||
:button-one-label (i18n/label :t/continue) | ||
:button-one-props {:customization-color | ||
customization-color | ||
:on-press | ||
(fn [] | ||
(rf/dispatch [:hide-bottom-sheet]) | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch | ||
[:open-modal :screen/use-recovery-phrase-dark | ||
{:on-success #(rf/dispatch [:keycard/unblock.phrase-entered %])}]))} | ||
:button-two-label (i18n/label :t/cancel) | ||
:button-two-props {:type :grey | ||
:on-press #(rf/dispatch [:hide-bottom-sheet])}}]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.