Skip to content

Commit

Permalink
Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Feb 24, 2020
1 parent a4b0229 commit 8ea0175
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 160 deletions.
12 changes: 8 additions & 4 deletions src/status_im/hardwallet/common.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@
(fx/merge cofx
{:dismiss-keyboard true}
(bottom-sheet/show-bottom-sheet
{:view {:content #(keycard-sheet/connect-keycard
{:on-cancel (fn [] (re-frame/dispatch on-cancel))
:on-connect ::on-card-connected
:on-disconnect ::on-card-disconnected})}})))
{:view {:show-handle? false
:backdrop-dismiss? false
:disable-drag? true
:content #(keycard-sheet/connect-keycard
{:on-cancel (fn [] (re-frame/dispatch on-cancel))
:on-connect ::on-card-connected
:on-disconnect ::on-card-disconnected})}})))

(fx/defn hide-pair-sheet
[{:keys [db] :as cofx}]
Expand All @@ -186,6 +189,7 @@
{:status nil
:login (get-in db [:hardwallet :pin :original])
:export-key []
:sign []
:puk []
:current []
:original []
Expand Down
52 changes: 26 additions & 26 deletions src/status_im/hardwallet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
:import-multiaccount []
:current []}))}
(common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-recovery-pin nil)))
(navigation/navigate-replace-cofx :keycard-recovery-pin nil)))

(fx/defn proceed-setup-with-initialized-card
[{:keys [db] :as cofx} flow instance-uid]
Expand Down Expand Up @@ -215,31 +215,27 @@
setup? (boolean (get-in db [:hardwallet :setup-step]))
exporting? (get-in db [:hardwallet :on-export-success])]
(log/debug "[hardwallet] verify pin error" error)
(cond 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/verify-pin))

(re-matches common/pin-mismatch-error (:error error))
(fx/merge cofx
{:db (update-in db [:hardwallet :pin] merge {:status :error
:enter-step :current
:puk []
:current []
:original []
:confirmation []
:sign []
:error-label :t/pin-mismatch})}
(when-not setup?
(if exporting?
(navigation/navigate-back)
(navigation/navigate-to-cofx :enter-pin-settings nil)))
(common/get-application-info (common/get-pairing db) nil))

:else
(common/show-wrong-keycard-alert nil true))))
(when-not tag-was-lost?
(if (re-matches common/pin-mismatch-error (:error error))
(fx/merge cofx
{:db (update-in db [:hardwallet :pin] merge {:status :error
:enter-step :current
:puk []
:current []
:original []
:confirmation []
:sign []
:error-label :t/pin-mismatch})}
(common/hide-pair-sheet)
(when-not setup?
(if exporting?
(navigation/navigate-back)
(navigation/navigate-to-cofx :enter-pin-settings nil)))
(common/get-application-info (common/get-pairing db) nil))

(fx/merge cofx
(common/hide-pair-sheet)
(common/show-wrong-keycard-alert true))))))

(fx/defn verify-pin
{:events [:hardwallet/verify-pin]}
Expand Down Expand Up @@ -412,6 +408,8 @@
(onboarding/proceed-with-generating-key))
(when (= flow :import)
(load-recovery-pin-screen))
;; TODO: If card is already initialized show pin then go to mnenmonic
;; https://github.com/status-im/status-react/issues/9451
(when (= flow :create)
(mnemonic/set-mnemonic)))))

Expand Down Expand Up @@ -451,6 +449,8 @@
:cancel-button-text ""
:confirm-button-text :t/okay}})

;; NOTE: Maybe replaced by multiple events based on on flow to make it easier to maintain.
;; Because there are many execution paths it is harder to follow all possible states.
(fx/defn check-card-state
{:events [:hardwallet/check-card-state]}
[{:keys [db] :as cofx}]
Expand Down
9 changes: 5 additions & 4 deletions src/status_im/hardwallet/login.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))

(fx/defn login-got-it-pressed
{:events [:keycard.login.pin.ui/cancel-pressed]}
{:events [:keycard.login.pin.ui/got-it-pressed
:keycard.login.pin.ui/cancel-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
{:db db}
Expand Down Expand Up @@ -67,17 +68,17 @@
(empty? key-uid)
(fx/merge cofx
(common/hide-pair-sheet)
(navigation/navigate-to-cofx cofx :keycard-blank nil))
(navigation/navigate-to-cofx :keycard-blank nil))

multiaccount-mismatch?
(fx/merge cofx
(common/hide-pair-sheet)
(navigation/navigate-to-cofx cofx :keycard-wrong nil))
(navigation/navigate-to-cofx :keycard-wrong nil))

(empty? pairing)
(fx/merge cofx
(common/hide-pair-sheet)
(navigation/navigate-to-cofx cofx :keycard-unpaired nil))
(navigation/navigate-to-cofx :keycard-unpaired nil))

:else
(common/get-keys-from-keycard cofx))))
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/hardwallet/mnemonic.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(assoc-in [:hardwallet :setup-step] :recovery-phrase)
(assoc-in [:hardwallet :secrets :mnemonic] mnemonic))}
(common/clear-on-card-connected)
(navigation/navigate-to-cofx :keycard-onboarding-recovery-phrase nil)))
(navigation/navigate-replace-cofx :keycard-onboarding-recovery-phrase nil)))

(fx/defn set-mnemonic
{:events [:test-mnemonic]}
Expand Down
18 changes: 9 additions & 9 deletions src/status_im/hardwallet/onboarding.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
(assoc-in [:hardwallet :pin :confirmation] []))})

(fx/defn start-installation
{:events [:hardwallet/start-installation]}
[{:keys [db] :as cofx}]
(let [card-state (get-in db [:hardwallet :card-state])
pin (common/vector->string (get-in db [:hardwallet :pin :original]))]
(log/debug "start-installation: card-state" card-state)
(case card-state

:pre-init
Expand All @@ -44,7 +44,7 @@
{:db (assoc-in db [:hardwallet :setup-step] :preparing)}
(common/set-on-card-connected :hardwallet/load-preparing-screen)
(if card-connected?
{:dispatch [:hardwallet/start-installation]}
(start-installation)
(common/show-pair-sheet {:on-cancel [::cancel-pressed]})))))

(fx/defn load-pairing-screen
Expand All @@ -56,7 +56,7 @@
{:db (assoc-in db [:hardwallet :setup-step] :pairing)}
(common/set-on-card-connected :hardwallet/load-pairing-screen)
(if card-connected?
{:dispatch [:hardwallet/pair]}
(common/dispatch-event :hardwallet/pair)
(common/show-pair-sheet {:on-cancel [::cancel-pressed]})))))

(fx/defn puk-code-next-pressed
Expand All @@ -78,7 +78,7 @@
{:db (assoc-in db [:hardwallet :setup-step] :loading-keys)}
(common/set-on-card-connected :hardwallet/load-finishing-screen)
(if card-connected?
{:dispatch [:hardwallet/generate-and-load-key]}
(common/dispatch-event :hardwallet/generate-and-load-key)
(common/show-pair-sheet {:on-cancel [::cancel-pressed]})))))

(fx/defn recovery-phrase-learn-more-pressed
Expand Down Expand Up @@ -158,7 +158,7 @@
(if (= (:view-id db) :keycard-onboarding-recovery-phrase-confirm-word1)
(fx/merge cofx
(recovery-phrase-next-word)
(navigation/navigate-to-cofx :keycard-onboarding-recovery-phrase-confirm-word2 nil))
(navigation/navigate-replace-cofx :keycard-onboarding-recovery-phrase-confirm-word2 nil))
(proceed-with-generating-key cofx))
{:db (assoc-in db [:hardwallet :recovery-phrase :confirm-error] (i18n/label :t/wrong-word))})))

Expand Down Expand Up @@ -254,7 +254,7 @@
(update-in [:hardwallet :secrets] merge secrets'))}
(common/hide-pair-sheet)
(common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-puk-code nil))))
(navigation/navigate-replace-cofx :keycard-onboarding-puk-code nil))))

(fx/defn on-install-applet-and-init-card-error
{:events [:hardwallet.callback/on-install-applet-and-init-card-error
Expand All @@ -281,8 +281,7 @@
(fx/merge cofx
{:hardwallet/generate-and-load-key {:mnemonic mnemonic'
:pairing pairing
:pin pin'}}
(navigation/navigate-to-cofx :keycard-onboarding-finishing nil))))
:pin pin'}})))

(fx/defn begin-setup-pressed
{:events [:keycard.onboarding.intro.ui/begin-setup-pressed]}
Expand All @@ -297,12 +296,13 @@
(assoc-in [:hardwallet :pin :on-verified] nil))}
(common/set-on-card-connected :hardwallet/get-application-info)
(common/set-on-card-read :hardwallet/check-card-state)
(common/show-pair-sheet {:on-cancel [::cancel-pressed]})))
(common/show-pair-sheet {})))

(fx/defn cancel-confirm
{:events [::cancel-confirm]}
[cofx]
(fx/merge cofx
(navigation/navigate-back)
(common/cancel-sheet-confirm)))

(fx/defn cancel-pressed
Expand Down
1 change: 1 addition & 0 deletions src/status_im/hardwallet/recovery.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
[{:keys [db] :as cofx}]
(fx/merge cofx
(common/cancel-sheet-confirm)
;; TODO: Reviese redirect, the intro screen back navigates to pairing
(if (= (get-in db [:hardwallet :flow]) :import)
(start-import-flow)
(recovery-keycard-selected))))
Expand Down
31 changes: 15 additions & 16 deletions src/status_im/hardwallet/sign.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,19 @@

(fx/defn on-sign-error
{:events [:hardwallet.callback/on-sign-error]}
[cofx error]
[{:keys [db] :as cofx} error]
(log/debug "[hardwallet] sign error: " error)
(fx/merge cofx
(if (re-matches common/pin-mismatch-error (:error error))
(fn [{:keys [db] :as cofx}]
(fx/merge cofx
{:db (-> db
(update-in [:hardwallet :pin] merge {:status :error
:sign []
:error-label :t/pin-mismatch})
(assoc-in [:signing/sign :keycard-step] :pin))}
(common/hide-pair-sheet)
(common/get-application-info (common/get-pairing db) nil)))
(fn [cofx]
(fx/merge cofx
(common/hide-pair-sheet)
(common/show-wrong-keycard-alert true))))))
(let [tag-was-lost? (= "Tag was lost." (:error error))]
(when-not tag-was-lost?
(if (re-matches common/pin-mismatch-error (:error error))
(fx/merge cofx
{:db (-> db
(update-in [:hardwallet :pin] merge {:status :error
:sign []
:error-label :t/pin-mismatch})
(assoc-in [:signing/sign :keycard-step] :pin))}
(common/hide-pair-sheet)
(common/get-application-info (common/get-pairing db) nil))
(fx/merge cofx
(common/hide-pair-sheet)
(common/show-wrong-keycard-alert true))))))
2 changes: 1 addition & 1 deletion src/status_im/ui/components/bottom_sheet/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
(defn bottom-sheet-view [{:keys [window-height]}]
(let [opacity-value (animation/create-value 0)
bottom-value (animation/create-value window-height)
content-height (reagent/atom window-height)
content-height (reagent/atom (* window-height 0.4))
internal-visible (reagent/atom false)
external-visible (reagent/atom false)]
(fn [{:keys [content on-cancel disable-drag? show-handle? show?
Expand Down
31 changes: 30 additions & 1 deletion src/status_im/ui/screens/keycard/components/description.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,40 @@
[status-im.ui.components.react :as react]
[status-im.ui.screens.keycard.components.style :as styles]))

(defn text-block-style [animated]
{:height 66
:margin-bottom 8
:opacity (animation/interpolate animated
{:inputRange [0 1]
:outputRange [1 0]})
:transform [{:translateY (animation/interpolate animated
{:inputRange [0 1]
:outputRange [0 10]})}]})

(def easing (animation/bezier 0.77 0 0.175 1))

(defonce animating (atom nil))

(defn animate-description [animated]
(when-not @animating
(reset! animating true)
;; TODO; Animate exit
(animation/set-value animated 1)
(animation/start
(animation/timing animated
{:toValue 0
:timing 300
:easing easing})
#(reset! animating false))))

(defn animated-description []
(let [current-text (reagent/atom nil)
animated-value (animation/create-value 0)]
(fn [{:keys [title description]}]
[react/animated-view {}
(when-not (= @current-text [title description])
(reset! current-text [title description])
(animate-description animated-value))
[react/animated-view {:style (text-block-style animated-value)}
[react/text {:style styles/title-style
:number-of-lines 1}
title]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
phone-entrace
circles])]
(reset! state :init)
;; TODO: Think how to improve that, this creates desync with animation
(js/setTimeout #(compare-and-set! state :init :awaiting)
phone-enter-at)
(animation/start animation)))
Expand Down
5 changes: 1 addition & 4 deletions src/status_im/ui/screens/keycard/recovery/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@
[react/view styles/container
[toolbar/toolbar
{:transparent? true}
[toolbar/nav-text
{:handler #(re-frame/dispatch [::hardwallet.recovery/cancel-pressed])
:style {:padding-left 21}}
(i18n/label :t/cancel)]
toolbar/default-nav-back
[react/text {:style {:color colors/gray}}
(i18n/label :t/step-i-of-n {:number 2
:step 1})]]
Expand Down
Loading

0 comments on commit 8ea0175

Please sign in to comment.