Skip to content

Commit

Permalink
Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Feb 19, 2020
1 parent 27a2c4b commit 56740bb
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 140 deletions.
1 change: 1 addition & 0 deletions src/status_im/hardwallet/common.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
{:status nil
:login (get-in db [:hardwallet :pin :original])
:export-key []
:sign []
:puk []
:current []
:original []
Expand Down
48 changes: 23 additions & 25 deletions src/status_im/hardwallet/core.cljs
Original file line number Diff line number Diff line change
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 @@ -451,6 +447,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/onboarding.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
(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]}
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))))))
97 changes: 6 additions & 91 deletions src/status_im/ui/screens/keycard/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,12 @@
retry-counter [:hardwallet/retry-counter]]
[react/view styles/container
[topbar/topbar
(cond-> {:accessories [{:icon :main-icons/more
:handler #(re-frame/dispatch [:keycard.login.pin.ui/more-icon-pressed])}]}
;; multiple-multiaccounts?
;; (assoc :navigation
;; {:icon :main-icons/back
;; :accessibility-label :back-button
;; :handler #(re-frame/dispatch [:keycard.login.pin.ui/cancel-pressed])})
)]
{:accessories [{:icon :main-icons/more
:handler #(re-frame/dispatch [:keycard.login.pin.ui/more-icon-pressed])}]
:navigation
{:icon :main-icons/back
:accessibility-label :back-button
:handler #(re-frame/dispatch [:keycard.login.pin.ui/cancel-pressed])}}]
[react/view {:flex 1
:flex-direction :column
:justify-content :space-between
Expand Down Expand Up @@ -294,89 +292,6 @@
[react/text {:style {:color colors/blue}}
(i18n/label :t/recover-key)]]]]]))

(defview login-connect-card []
(letsubs [status [:hardwallet/pin-status]
{:keys [key-uid name] :as account} [:multiaccounts/login]]
(let [in-progress? (= status :verifying)]
[react/view styles/container
[toolbar/toolbar
{:transparent? true}
nil
[react/text {:style {:color colors/gray}}
(i18n/label :t/step-i-of-n {:number 2
:step 2})]
[react/view {:margin-right 20}
[react/touchable-highlight
{:on-press #(re-frame/dispatch [:keycard.login.pin.ui/more-icon-pressed])}
[vector-icons/icon :main-icons/more {:color colors/black
:container-style {:margin-left 5}}]]]]
[react/view {:flex 1
:flex-direction :column
:justify-content :space-between
:align-items :center
:margin-top 15}
[react/view {:flex-direction :column
:justify-content :center
:align-items :center}
[react/view {:margin-horizontal 16
:flex-direction :column}
[react/view {:justify-content :center
:align-items :center
:flex-direction :row}
[react/view {:width 69
:height 69
:justify-content :center
:align-items :center}
;;TODO this should be done in a subscription
[photos/photo (multiaccounts/displayed-photo account) {:size 61}]
[react/view {:justify-content :center
:align-items :center
:width 24
:height 24
:border-radius 24
:position :absolute
:right 0
:bottom 0
:background-color :white
:border-width 1
:border-color colors/black-transparent}
[react/image {:source (resources/get-image :keycard-key)
:style {:width 8
:height 14}}]]]]
[react/text {:style {:text-align :center
:margin-top 12
:color colors/black
:font-weight "500"}
:number-of-lines 1
:ellipsize-mode :middle}
name]
[react/text {:style {:text-align :center
:margin-top 4
:color colors/gray
:font-family "monospace"}
:number-of-lines 1
:ellipsize-mode :middle}
(utils.core/truncate-str key-uid 14 true)]]]
[react/view {:margin-bottom 12
:flex 1
:align-items :center
:justify-content :center}
[react/image {:source (resources/get-image :keycard-phone)
:resize-mode :center
:style {:width 200
:height 211}}]
[react/view {:margin-top 10}
[react/text {:style {:text-align :center
:color colors/gray
:font-size 15
:line-height 22}}
(i18n/label :t/hold-card)]]]
[react/view {:margin-bottom 50
:height 30}
(when in-progress?
[react/activity-indicator {:size :large
:animating true}])]]])))

(defn- more-sheet-content []
[react/view {:flex 1}
[list-item/list-item
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/ui/screens/routing/intro_login_stack.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
:keycard-wrong
:keycard-unpaired
:keycard-login-pin
:keycard-login-connect-card
:not-keycard
:keycard-onboarding-intro
:keycard-onboarding-puk-code
Expand Down Expand Up @@ -60,7 +59,6 @@
config/hardwallet-enabled?
(concat [:hardwallet-authentication-method
:keycard-login-pin
:keycard-login-connect-card
:keycard-blank
:keycard-wrong
:keycard-unpaired
Expand Down
1 change: 0 additions & 1 deletion src/status_im/ui/screens/routing/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
:keycard-wrong keycard/wrong
:keycard-unpaired keycard/unpaired
:keycard-login-pin keycard/login-pin
:keycard-login-connect-card keycard/login-connect-card
:not-keycard keycard/not-keycard
:home home/home-wrapper
:chat chat/chat
Expand Down

0 comments on commit 56740bb

Please sign in to comment.