Skip to content

Commit

Permalink
[#8993] adjust pin screens for small screen devices
Browse files Browse the repository at this point in the history
find account by key-uid

show pairing slots info on pairing

fix pin reset flow

pass retry-counter

fix sign with keycard button in wallet
  • Loading branch information
dmitryn committed Nov 6, 2019
1 parent 2e8e1a3 commit 4fa49fd
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 116 deletions.
63 changes: 38 additions & 25 deletions src/status_im/hardwallet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@

(defn get-pairing
([db]
(get-pairing db (get-in db [:hardwallet :application-info :instance-uid])))
([db instance-uid]
(get-pairing db (get-in db [:hardwallet :application-info :key-uid])))
([db key-uid]
(or
(get-in db [:multiaccount :keycard-pairing])
(get-in db [:hardwallet :secrets :pairing])
(when instance-uid
(when key-uid
(:keycard-pairing
(find-multiaccount-by-keycard-instance-uid db instance-uid))))))
(find-multiaccount-by-keycard-key-uid db key-uid))))))

(fx/defn listen-to-hardware-back-button
[{:keys [db]}]
Expand Down Expand Up @@ -416,7 +416,7 @@
(let [app-info (get-in db [:hardwallet :application-info])
flow (get-in db [:hardwallet :flow])
{:keys [instance-uid key-uid]} app-info
pairing (get-pairing db instance-uid)
pairing (get-pairing db key-uid)
app-info' (if pairing (assoc app-info :paired? true) app-info)
card-state (get-card-state app-info')]
(fx/merge cofx
Expand Down Expand Up @@ -603,6 +603,9 @@
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :pin :enter-step] enter-step)
(update-in [:hardwallet :pin :error-label] #(if (= :puk enter-step)
:t/enter-puk-code-description
%))
(assoc-in [:hardwallet :application-info] info')
(assoc-in [:hardwallet :application-info :applet-installed?] true)
(assoc-in [:hardwallet :application-info-error] nil))}
Expand Down Expand Up @@ -1035,11 +1038,12 @@
(fx/merge cofx
{:hardwallet/get-application-info {:pairing pairing}
:db (-> db
(update-in [:hardwallet :pin] merge {:status nil
:enter-step :original
:current [0 0 0 0 0 0]
:puk []
:error-label nil}))}
(update-in [:hardwallet :pin] merge {:status nil
:enter-step :original
:current [0 0 0 0 0 0]
:confirmation []
:puk []
:error-label nil}))}
(navigation/navigate-to-cofx :enter-pin-settings nil))))

(defn on-unblock-pin-error
Expand All @@ -1053,10 +1057,10 @@
:puk []})}))
(fx/defn get-application-info
[{:keys [db]} pairing on-card-read]
(let [instance-uid (get-in db [:hardwallet :application-info :instance-uid])
(let [key-uid (get-in db [:hardwallet :application-info :key-uid])
pairing' (or pairing
(when instance-uid
(get-pairing db instance-uid)))]
(when key-uid
(get-pairing db key-uid)))]
{:hardwallet/get-application-info {:pairing pairing'
:on-success on-card-read}}))

Expand Down Expand Up @@ -1117,15 +1121,22 @@

(fx/defn on-change-pin-success
[{:keys [db] :as cofx}]
(let [pin (vector->string (get-in db [:hardwallet :pin :original]))]
(let [pin (get-in db [:hardwallet :pin :original])]
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :on-card-connected] nil)
(assoc-in [:hardwallet :pin] {:status nil
:error-label nil}))
(assoc-in [:hardwallet :pin] {:status nil
:login pin
:confirmation []
:error-label nil}))
:utils/show-popup {:title ""
:content (i18n/label :t/pin-changed)}}
(multiaccounts.logout/logout))))
(when (:multiaccounts/login db)
(navigation/navigate-to-cofx :keycard-login-pin nil))
(when (:multiaccounts/login db)
(get-keys-from-keycard))
(when (:multiaccount/multiaccount db)
(multiaccounts.logout/logout)))))

(fx/defn on-change-pin-error
[{:keys [db] :as cofx} error]
Expand Down Expand Up @@ -1205,9 +1216,9 @@
(defn unblock-pin
[{:keys [db] :as cofx}]
(let [puk (vector->string (get-in db [:hardwallet :pin :puk]))
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
key-uid (get-in db [:hardwallet :application-info :key-uid])
card-connected? (get-in db [:hardwallet :card-connected?])
pairing (get-pairing db instance-uid)]
pairing (get-pairing db key-uid)]
(if card-connected?
{:db (assoc-in db [:hardwallet :pin :status] :verifying)
:hardwallet/unblock-pin {:puk puk
Expand Down Expand Up @@ -1299,7 +1310,8 @@
[{:keys [db] :as cofx}]
(let [{:keys [pairing]} (get-in db [:hardwallet :secrets])
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
pairing' (or pairing (get-pairing db instance-uid))
key-uid (get-in db [:hardwallet :application-info :key-uid])
pairing' (or pairing (get-pairing db key-uid))
pin (vector->string (get-in db [:hardwallet :pin :import-multiaccount]))]
(fx/merge cofx
{:db (-> db
Expand Down Expand Up @@ -1403,13 +1415,14 @@
[{:keys [db] :as cofx} _]
(log/debug "[hardwallet] card connected")
(let [instance-uid (get-in db [:hardwallet :application-info :instance-uid])
key-uid (get-in db [:hardwallet :application-info :key-uid])
accounts-screen? (= :multiaccounts (:view-id db))
should-read-instance-uid? (nil? instance-uid)
on-card-connected (get-in db [:hardwallet :on-card-connected])
on-card-read (cond
should-read-instance-uid? :hardwallet/get-application-info
:else (get-in db [:hardwallet :on-card-read]))
pairing (get-pairing db instance-uid)]
pairing (get-pairing db key-uid)]
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :card-connected?] true)
Expand Down Expand Up @@ -1735,7 +1748,7 @@
(let [{:keys [address whisper-address encryption-public-key whisper-private-key] :as account-data} (js->clj data :keywordize-keys true)
address (str "0x" address)
{:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts address])
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
key-uid (get-in db [:hardwallet :application-info :key-uid])
multiaccount-data (types/clj->json {:name name :address address :photo-path photo-path})]
(fx/merge cofx
{:db (-> db
Expand All @@ -1748,7 +1761,7 @@
:address address
:photo-path photo-path
:name name))
:hardwallet/get-application-info {:pairing (get-pairing db instance-uid)}
:hardwallet/get-application-info {:pairing (get-pairing db key-uid)}
:hardwallet/login-with-keycard {:multiaccount-data multiaccount-data
:password encryption-public-key
:chat-key whisper-private-key}})))
Expand All @@ -1757,15 +1770,15 @@
[{:keys [db] :as cofx} error]
(log/debug "[hardwallet] get keys error: " error)
(let [tag-was-lost? (= "Tag was lost." (:error error))
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
key-uid (get-in db [:hardwallet :application-info :key-uid])
flow (get-in db [:hardwallet :flow])]
(if tag-was-lost?
(fx/merge cofx
{:db (assoc-in db [:hardwallet :pin :status] nil)}
(navigation/navigate-to-cofx :keycard-connection-lost nil))
(if (re-matches pin-mismatch-error (:error error))
(fx/merge cofx
{:hardwallet/get-application-info {:pairing (get-pairing db instance-uid)}
{:hardwallet/get-application-info {:pairing (get-pairing db key-uid)}
:db (update-in db [:hardwallet :pin] merge {:status :error
:login []
:import-multiaccount []
Expand Down
6 changes: 6 additions & 0 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@
:<- [:dimensions/window]
:height)

(re-frame/reg-sub
:dimensions/small-screen?
:<- [:dimensions/window-height]
(fn [height]
(< height 550)))

(re-frame/reg-sub
:get-screen-params
:<- [:screen-params]
Expand Down
36 changes: 18 additions & 18 deletions src/status_im/ui/screens/hardwallet/pin/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
(styles/def pin-container
{:flex 1
:flex-direction :column
:justify-content :space-between
:android {:margin-top 10}
:ios {:margin-top 10}})
:justify-content :space-between})

(styles/def error-container
{:height 22})
(styles/defn error-container [small-screen?]
{:height (if small-screen? 18 22)
:margin-top (if small-screen? 14 10)
:margin-bottom (if small-screen? 10 0)})

(def error-text
(defn error-text [small-screen?]
{:color colors/red
:font-size 15
:font-size (if small-screen? 12 15)
:text-align :center})

(defn center-container [title]
Expand Down Expand Up @@ -59,29 +59,29 @@
{:margin-top 26})

(def numpad-container
{:margin-top 20})
{:margin-top 18})

(def numpad-row-container
(defn numpad-row-container [small-screen?]
{:flex-direction :row
:justify-content :center
:align-items :center
:margin-vertical 12})
:margin-vertical (if small-screen? 4 10)})

(def numpad-button
{:width 64
:margin-horizontal 16
:height 64
(defn numpad-button [small-screen?]
{:width (if small-screen? 50 64)
:margin-horizontal (if small-screen? 10 14)
:height (if small-screen? 50 64)
:align-items :center
:justify-content :center
:flex-direction :row
:border-radius 50
:background-color colors/blue-light})

(def numpad-delete-button
(assoc numpad-button :background-color colors/white))
(defn numpad-delete-button [small-screen?]
(assoc (numpad-button small-screen?) :background-color colors/white))

(def numpad-empty-button
(assoc numpad-button :background-color colors/white
(defn numpad-empty-button [small-screen?]
(assoc (numpad-button small-screen?) :background-color colors/white
:border-color colors/white))

(def numpad-button-text
Expand Down
55 changes: 27 additions & 28 deletions src/status_im/ui/screens/hardwallet/pin/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@
[status-im.ui.components.toolbar.actions :as actions]
[status-im.ui.components.toolbar.actions :as toolbar.actions]))

(defn numpad-button [n step enabled?]
(defn numpad-button [n step enabled? small-screen?]
[react/touchable-highlight
{:on-press #(when enabled?
(re-frame/dispatch [:hardwallet.ui/pin-numpad-button-pressed n step]))}
[react/view styles/numpad-button
[react/view (styles/numpad-button small-screen?)
[react/text {:style styles/numpad-button-text}
n]]])

(defn numpad-row [[a b c] step enabled?]
[react/view styles/numpad-row-container
[numpad-button a step enabled?]
[numpad-button b step enabled?]
[numpad-button c step enabled?]])
(defn numpad-row [[a b c] step enabled? small-screen?]
[react/view (styles/numpad-row-container small-screen?)
[numpad-button a step enabled? small-screen?]
[numpad-button b step enabled? small-screen?]
[numpad-button c step enabled? small-screen?]])

(defn numpad [step enabled?]
(defn numpad [step enabled? small-screen?]
[react/view styles/numpad-container
[numpad-row [1 2 3] step enabled?]
[numpad-row [4 5 6] step enabled?]
[numpad-row [7 8 9] step enabled?]
[react/view styles/numpad-row-container
[react/view styles/numpad-empty-button]
[numpad-button 0 step enabled?]
[numpad-row [1 2 3] step enabled? small-screen?]
[numpad-row [4 5 6] step enabled? small-screen?]
[numpad-row [7 8 9] step enabled? small-screen?]
[react/view (styles/numpad-row-container small-screen?)
[react/view (styles/numpad-empty-button small-screen?)]
[numpad-button 0 step enabled? small-screen?]
[react/touchable-highlight
{:on-press #(when enabled?
(re-frame/dispatch [:hardwallet.ui/pin-numpad-delete-button-pressed step]))}
[react/view styles/numpad-delete-button
[react/view (styles/numpad-delete-button small-screen?)
[vector-icons/icon :main-icons/backspace {:color colors/blue}]]]]])

(defn pin-indicator [pressed? status]
Expand All @@ -60,18 +60,18 @@
nil)))))])

(defn puk-indicators [puk status]
[react/view
[react/view {:margin-top 28}
(map-indexed
(fn [i puk-group]
^{:key i}
[pin-indicators puk-group status {:margin-top 15}])
[pin-indicators puk-group status {:margin-top 8}])
(partition 6
(concat puk
(repeat (- 12 (count puk))
nil))))])

(defn pin-view [{:keys [pin title-label description-label step status error-label
retry-counter]}]
retry-counter small-screen?]}]
(let [enabled? (not= status :verifying)]
[react/scroll-view
[react/view styles/pin-container
Expand All @@ -83,24 +83,23 @@
[react/text {:style styles/create-pin-text
:number-of-lines 2}
(i18n/label description-label)])
[react/view {:height 10}
(when retry-counter
[react/text {:style {:font-weight "700"
:color colors/red}}
(i18n/label :t/pin-retries-left {:number retry-counter})])]
[react/view {:height 22}
[react/view {:margin-top 40
:height (if small-screen? 18 22)}
(case status
:verifying [react/view styles/waiting-indicator-container
[react/activity-indicator {:animating true
:size :small}]]
:error [react/view styles/error-container
[react/text {:style styles/error-text}
:error [react/view (styles/error-container small-screen?)
[react/text {:style (styles/error-text small-screen?)}
(i18n/label error-label)]]
nil)]
(when retry-counter
[react/view {:margin-top (if (= step :puk) 24 8)}
[react/text {:style {:text-align :center}}
(i18n/label :t/pin-retries-left {:number retry-counter})]]))]
(if (= step :puk)
[puk-indicators pin status]
[pin-indicators pin status nil])
[numpad step enabled?]]]]))
[numpad step enabled? small-screen?]]]]))

(def pin-retries 3)
(def puk-retries 5)
Expand Down
12 changes: 12 additions & 0 deletions src/status_im/ui/screens/hardwallet/settings/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
(fn [db]
(get-in db [:hardwallet :application-info :puk-retry-counter])))

(re-frame/reg-sub
:hardwallet/retry-counter
:<- [:hardwallet/pin-retry-counter]
:<- [:hardwallet/puk-retry-counter]
(fn [[pin puk]]
(if (zero? pin) puk pin)))

(re-frame/reg-sub
:hardwallet/puk-retry-counter
(fn [db]
(get-in db [:hardwallet :application-info :puk-retry-counter])))

(re-frame/reg-sub
:keycard-reset-card-disabled?
(fn [db]
Expand Down
Loading

0 comments on commit 4fa49fd

Please sign in to comment.