-
Notifications
You must be signed in to change notification settings - Fork 986
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
Changing the PIN of the Keycard #22008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
(ns status-im.contexts.keycard.change-pin.events | ||
(:require [status-im.contexts.keycard.utils :as utils] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf] | ||
[utils.security.core :as security])) | ||
|
||
(rf/reg-event-fx :keycard/change-pin.enter-current-pin | ||
(fn [{:keys [db]}] | ||
{:db (update db :keycard dissoc :change-pin) | ||
:fx [[:dispatch [:navigate-back]] | ||
[:dispatch | ||
[:open-modal :screen/keycard.pin.enter | ||
{:title (i18n/label :t/enter-current-keycard-pin) | ||
:on-complete (fn [current-pin] | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:keycard/change-pin.save-current-pin current-pin]) | ||
(rf/dispatch [:keycard/change-pin.enter-new-pin]))}]]]})) | ||
|
||
(rf/reg-event-fx :keycard/change-pin.save-current-pin | ||
(fn [{:keys [db]} [pin]] | ||
{:db (assoc-in db [:keycard :change-pin :current-pin] (security/mask-data pin))})) | ||
|
||
(rf/reg-event-fx :keycard/change-pin.enter-new-pin | ||
(fn [_] | ||
{:fx [[:dispatch | ||
[:open-modal :screen/keycard.pin.create | ||
{:title (i18n/label :t/create-new-keycard-pin) | ||
:repeat-stage-title (i18n/label :t/repeat-new-keycard-pin) | ||
:on-complete (fn [new-pin] | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:keycard/change-pin.save-new-pin new-pin]) | ||
(rf/dispatch [:open-modal :screen/keycard.ready-to-change-pin]))}]]]})) | ||
|
||
(rf/reg-event-fx :keycard/change-pin.save-new-pin | ||
(fn [{:keys [db]} [pin]] | ||
{:db (assoc-in db [:keycard :change-pin :new-pin] (security/mask-data pin))})) | ||
|
||
(defn- change-pin-and-continue | ||
[current-pin new-pin] | ||
(rf/dispatch [:keycard/change-pin | ||
{:on-success (fn [] | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:keycard/disconnect]) | ||
(rf/dispatch [:open-modal :screen/keycard.pin-change-success])) | ||
:on-failure (fn [] | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:keycard/disconnect]) | ||
(rf/dispatch [:open-modal :screen/keycard.pin-change-failed])) | ||
:current-pin current-pin | ||
:new-pin new-pin}])) | ||
|
||
(defn- verify-pin-and-continue | ||
[current-pin new-pin] | ||
(rf/dispatch | ||
[:keycard/verify-pin | ||
{:pin current-pin | ||
:on-success #(change-pin-and-continue current-pin new-pin) | ||
:on-failure (fn [error] | ||
(when-not (utils/tag-lost? (:error error)) | ||
(rf/dispatch [:keycard/disconnect]) | ||
(rf/dispatch [:keycard/on-action-with-pin-error error]) | ||
(rf/dispatch [:keycard/change-pin.enter-current-pin])))}])) | ||
|
||
(rf/reg-event-fx :keycard/change-pin.verify-current-pin-and-continue | ||
(fn [{:keys [db]}] | ||
(let [{:keys [current-pin new-pin]} (get-in db [:keycard :change-pin]) | ||
unmasked-current-pin (security/safe-unmask-data current-pin) | ||
unmasked-new-pin (security/safe-unmask-data new-pin)] | ||
{:fx [[:dispatch | ||
[:keycard/connect | ||
{:key-uid (get-in db [:profile/profile :key-uid]) | ||
:on-success #(verify-pin-and-continue unmasked-current-pin unmasked-new-pin)}]]]}))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
(ns status-im.contexts.keycard.change-pin.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 change-pin-confirmation-sheet | ||
[] | ||
[quo/documentation-drawers | ||
{:title (i18n/label :t/change-pin-keycard) | ||
:shell? true} | ||
[rn/view | ||
[quo/text {:size :paragraph-2} | ||
(i18n/label :t/change-pin-keycard-message)] | ||
[quo/bottom-actions | ||
{:actions :two-actions | ||
:container-style {:margin-horizontal -20} | ||
:blur? true | ||
:button-one-label (i18n/label :t/continue) | ||
:button-one-props {:on-press #(rf/dispatch [:keycard/change-pin.enter-current-pin])} | ||
:button-two-label (i18n/label :t/cancel) | ||
:button-two-props {:on-press events-helper/hide-bottom-sheet | ||
:type :grey}}]]]) | ||
|
||
(defn ready-to-change-pin | ||
[] | ||
[:<> | ||
[quo/page-nav | ||
{:icon-name :i/close | ||
:on-press events-helper/navigate-back}] | ||
[quo/page-top | ||
{:title (i18n/label :t/ready-to-change-pin)}] | ||
[rn/view {:style {:flex 1 :align-items :center :justify-content :center}} | ||
[rn/image | ||
{:resize-mode :contain}]] | ||
[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/change-pin.verify-current-pin-and-continue])}}]]) | ||
|
||
(defn pin-change-success | ||
[] | ||
[:<> | ||
[quo/page-nav | ||
{:icon-name :i/close | ||
:on-press events-helper/navigate-back}] | ||
[quo/page-top | ||
{:title (i18n/label :t/keycard-pin-changed) | ||
:description :text | ||
:description-text (i18n/label :t/keycard-pin-changed-description)}] | ||
[rn/view {:style {:flex 1 :align-items :center :justify-content :center}} | ||
[rn/image | ||
{:resize-mode :contain}]] | ||
[quo/bottom-actions | ||
{:actions :one-action | ||
:button-one-label (i18n/label :t/done) | ||
:button-one-props {:on-press events-helper/navigate-back}}]]) | ||
|
||
(defn pin-change-failed | ||
[] | ||
[:<> | ||
[quo/page-nav | ||
{:icon-name :i/close | ||
:on-press events-helper/navigate-back}] | ||
[quo/page-top | ||
{:title (i18n/label :t/keycard-pin-change-failed) | ||
:description :text | ||
:description-text (i18n/label :t/keycard-pin-change-failed-description)}] | ||
[rn/view {:style {:flex 1 :align-items :center :justify-content :center}} | ||
[rn/image | ||
{:resize-mode :contain}]] | ||
[common.view/tips] | ||
[quo/bottom-actions | ||
{:actions :one-action | ||
:button-one-label (i18n/label :t/try-again) | ||
:button-one-props {:on-press (fn [] | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:open-modal :screen/keycard.ready-to-change-pin]))}}]]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,9 +164,9 @@ | |
theme)}) | ||
options | ||
(when sheet? | ||
options/sheet-options))}}]}}))) | ||
(state/navigation-state-push {:id component | ||
:type :modal}))) | ||
options/sheet-options))}}]}}) | ||
(state/navigation-state-push {:id component | ||
:type :modal}))))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did something change here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes,
|
||
|
||
(rf/reg-fx :open-modal-fx open-modal) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is being duplicated too much. As of this PR, I see it duplicated 12 times across keycard namespaces. We can simply create a style namespace at
contexts/keycard/
for example and reuse. Or even simpler have a common component using this style map and reuse it across keycard views.Not a blocker for this PR, but I think we can do better in a subsequent PR.