[#10101] Reintroduce account generation on keycard multiaccount

This commit is contained in:
Roman Volosovskyi 2020-03-17 10:30:25 +02:00
parent d24f4690b8
commit ebf2600fdc
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
8 changed files with 128 additions and 86 deletions

View File

@ -461,3 +461,5 @@
(restore-on-card-connected) (restore-on-card-connected)
(restore-on-card-read))) (restore-on-card-read)))
(defn keycard-multiaccount? [db]
(boolean (get-in db [:multiaccount :keycard-pairing])))

View File

@ -315,7 +315,7 @@
(and (= enter-step :export-key) (and (= enter-step :export-key)
(= pin-code-length numbers-entered)) (= pin-code-length numbers-entered))
(wallet/generate-new-keycard-account) (wallet/hide-pin-sheet)
(and (= enter-step :sign) (and (= enter-step :sign)
(= pin-code-length numbers-entered)) (= pin-code-length numbers-entered))

View File

@ -3,30 +3,47 @@
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.hardwallet.common :as common] [status-im.hardwallet.common :as common]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.ethereum.eip55 :as eip55])) [status-im.ethereum.eip55 :as eip55]
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
(fx/defn show-pin-sheet
{:events [:hardwallet/new-account-pin-sheet]}
[{:keys [db] :as cofx} sheet-options]
(fx/merge
cofx
{:db (assoc-in db [:hardwallet :pin :enter-step] :export-key)}
(bottom-sheet/show-bottom-sheet sheet-options)))
(fx/defn hide-pin-sheet
{:events [:hardwallet/hide-new-account-pin-sheet]}
[{:keys [db] :as cofx}]
(fx/merge
cofx
{:utils/dispatch-later
;; We need to give previous sheet some time to be fully hidden
[{:ms 200
:dispatch [:wallet.accounts/generate-new-keycard-account]}]}
(bottom-sheet/hide-bottom-sheet)))
(fx/defn generate-new-keycard-account (fx/defn generate-new-keycard-account
{:events [:wallet.accounts/generate-new-keycard-account]} {:events [:wallet.accounts/generate-new-keycard-account]}
[{:keys [db] :as cofx}] [cofx]
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path])) (common/show-connection-sheet
path (str constants/path-wallet-root "/" path-num) cofx
pin (common/vector->string (get-in db [:hardwallet :pin :export-key])) {:on-card-connected :wallet.accounts/generate-new-keycard-account
pairing (common/get-pairing db)] :handler
(common/show-connection-sheet (fn [{:keys [db]}]
cofx (let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
{:on-card-connected :hardwallet/load-loading-keys-screen path (str constants/path-wallet-root "/" path-num)
:handler pin (common/vector->string (get-in db [:hardwallet :pin :export-key]))
(fn [cofx] pairing (common/get-pairing db)]
(fx/merge {:db
cofx (assoc-in
{:db db [:hardwallet :on-export-success]
(assoc-in #(vector :wallet.accounts/account-stored
db [:hardwallet :on-export-success] {;; Strip leading 04 prefix denoting uncompressed key format
#(vector :wallet.accounts/account-stored :address (eip55/address->checksum (str "0x" (ethereum/public-key->address (subs % 2))))
{;; Strip leading 04 prefix denoting uncompressed key format :public-key (str "0x" %)
:address (eip55/address->checksum (str "0x" (ethereum/public-key->address (subs % 2)))) :path path}))
:public-key (str "0x" %)
:path path}))
:hardwallet/export-key {:pin pin :pairing pairing :path path}} :hardwallet/export-key {:pin pin :pairing pairing :path path}}))}))
(common/set-on-card-connected :wallet.accounts/generate-new-keycard-account)))})))

View File

@ -57,4 +57,4 @@
[react/view {:position :absolute :left @title-padding :right @title-padding [react/view {:position :absolute :left @title-padding :right @title-padding
:top 0 :bottom 0 :align-items :center :justify-content :center} :top 0 :bottom 0 :align-items :center :justify-content :center}
[react/text {:style {:typography :title-bold :text-align :center} :number-of-lines 2} [react/text {:style {:typography :title-bold :text-align :center} :number-of-lines 2}
(utils.label/stringify title)]])])))) (utils.label/stringify title)]])]))))

View File

@ -1,5 +1,6 @@
(ns status-im.ui.screens.hardwallet.settings.subs (ns status-im.ui.screens.hardwallet.settings.subs
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.hardwallet.common :as common]
[status-im.utils.datetime :as utils.datetime])) [status-im.utils.datetime :as utils.datetime]))
(re-frame/reg-sub (re-frame/reg-sub
@ -37,6 +38,4 @@
(re-frame/reg-sub (re-frame/reg-sub
:keycard-multiaccount? :keycard-multiaccount?
(fn [db] common/keycard-multiaccount?)
(boolean
(get-in db [:multiaccount :keycard-pairing]))))

View File

@ -59,39 +59,42 @@
:address (:address account)}])}]]) :address (:address account)}])}]])
(defn add-account [] (defn add-account []
[react/view (let [keycard? @(re-frame/subscribe [:keycard-multiaccount?])]
[list-item/list-item [react/view
{:title :t/generate-a-new-account [list-item/list-item
:theme :action {:title :t/generate-a-new-account
:icon :main-icons/add :theme :action
:accessibility-label :add-account-sheet-generate :icon :main-icons/add
:on-press #(hide-sheet-and-dispatch :accessibility-label :add-account-sheet-generate
[:wallet.accounts/start-adding-new-account :on-press #(hide-sheet-and-dispatch
{:type :generate}])}] [:wallet.accounts/start-adding-new-account
[list-item/list-item {:type :generate}])}]
{:theme :action [list-item/list-item
:title :t/add-a-watch-account {:theme :action
:icon :main-icons/watch :title :t/add-a-watch-account
:accessibility-label :add-account-sheet-watch :icon :main-icons/watch
:on-press #(hide-sheet-and-dispatch :accessibility-label :add-account-sheet-watch
[:wallet.accounts/start-adding-new-account :on-press #(hide-sheet-and-dispatch
{:type :watch}])}] [:wallet.accounts/start-adding-new-account
[list-item/list-item {:type :watch}])}]
{:title :t/enter-a-seed-phrase (when-not keycard?
:theme :action [list-item/list-item
:icon :main-icons/text {:title :t/enter-a-seed-phrase
:accessibility-label :add-account-sheet-seed :theme :action
:on-press #(hide-sheet-and-dispatch :icon :main-icons/text
[:wallet.accounts/start-adding-new-account :accessibility-label :add-account-sheet-seed
{:type :seed}])}] :on-press #(hide-sheet-and-dispatch
[list-item/list-item [:wallet.accounts/start-adding-new-account
{:title :t/enter-a-private-key {:type :seed}])}])
:theme :action (when-not keycard?
:icon :main-icons/address [list-item/list-item
:accessibility-label :add-account-sheet-private-key {:title :t/enter-a-private-key
:on-press #(hide-sheet-and-dispatch :theme :action
[:wallet.accounts/start-adding-new-account :icon :main-icons/address
{:type :key}])}]]) :accessibility-label :add-account-sheet-private-key
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :key}])}])]))
(defn account-settings [] (defn account-settings []
[react/view [react/view
@ -101,4 +104,4 @@
:accessibility-label :account-settings-bottom-sheet :accessibility-label :account-settings-bottom-sheet
:icon :main-icons/info :icon :main-icons/info
:on-press #(hide-sheet-and-dispatch :on-press #(hide-sheet-and-dispatch
[:navigate-to :account-settings])}]]) [:navigate-to :account-settings])}]])

View File

@ -17,7 +17,8 @@
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.utils.security :as security] [status-im.utils.security :as security]
[clojure.string :as string] [clojure.string :as string]
[status-im.utils.platform :as platform])) [status-im.utils.platform :as platform]
[taoensso.timbre :as log]))
(defn- request-camera-permissions [] (defn- request-camera-permissions []
(let [options {:handler :wallet.add-new/qr-scanner-result}] (let [options {:handler :wallet.add-new/qr-scanner-result}]
@ -126,15 +127,35 @@
(re-frame/dispatch [:set-in [:add-account :account-error] nil]) (re-frame/dispatch [:set-in [:add-account :account-error] nil])
(re-frame/dispatch [:set-in [:add-account :private-key] (security/mask-data %)]))}])]) (re-frame/dispatch [:set-in [:add-account :private-key] (security/mask-data %)]))}])])
(defview pin []
(letsubs [pin [:hardwallet/pin]
status [:hardwallet/pin-status]
error-label [:hardwallet/pin-error-label]]
[react/keyboard-avoiding-view {:style {:flex 1}}
[topbar/topbar
{:navigation :none
:accessories
[{:label :t/cancel
:handler #(re-frame/dispatch [:bottom-sheet/hide])}]}]
[pin.views/pin-view
{:pin pin
:status status
:title-label :t/current-pin
:description-label :t/current-pin-description
:error-label error-label
:step :export-key}]]))
(defview add-account [] (defview add-account []
(letsubs [{:keys [type account] :as add-account} [:add-account] (letsubs [{:keys [type account] :as add-account} [:add-account]
add-account-disabled? [:add-account-disabled?] add-account-disabled? [:add-account-disabled?]
entered-password (reagent/atom "")] entered-password (reagent/atom "")
keycard? [:keycard-multiaccount?]]
[react/keyboard-avoiding-view {:style {:flex 1}} [react/keyboard-avoiding-view {:style {:flex 1}}
[add-account-topbar type] [add-account-topbar type]
[react/scroll-view {:keyboard-should-persist-taps :handled [react/scroll-view {:keyboard-should-persist-taps :handled
:style {:flex 1}} :style {:flex 1}}
[settings add-account entered-password] (when-not keycard?
[settings add-account entered-password])
[common-settings account]] [common-settings account]]
[toolbar/toolbar [toolbar/toolbar
{:show-border? true {:show-border? true
@ -142,23 +163,19 @@
{:type :next {:type :next
:label :t/add-account :label :t/add-account
:accessibility-label :add-account-add-account-button :accessibility-label :add-account-add-account-button
:on-press #(re-frame/dispatch [:wallet.accounts/add-new-account :on-press
(ethereum/sha3 @entered-password)]) (if keycard?
:disabled? (or add-account-disabled? #(re-frame/dispatch [:hardwallet/new-account-pin-sheet
(and {:view {:content pin
(not (= type :watch)) :height 256}}])
(not (spec/valid? ::multiaccounts.db/password @entered-password))))}}]])) #(re-frame/dispatch [:wallet.accounts/add-new-account
(ethereum/sha3 @entered-password)]))
:disabled?
(or add-account-disabled?
(and
(not (= type :watch))
(and
(not keycard?)
(not (spec/valid? ::multiaccounts.db/password
@entered-password)))))}}]]))
(defview pin []
(letsubs [pin [:hardwallet/pin]
status [:hardwallet/pin-status]
error-label [:hardwallet/pin-error-label]]
[react/keyboard-avoiding-view {:style {:flex 1}}
[topbar/topbar]
[pin.views/pin-view
{:pin pin
:status status
:title-label :t/current-pin
:description-label :t/current-pin-description
:error-label error-label
:step :export-key}]]))

View File

@ -17,7 +17,8 @@
[clojure.string :as string] [clojure.string :as string]
[status-im.utils.security :as security] [status-im.utils.security :as security]
[status-im.multiaccounts.recover.core :as recover] [status-im.multiaccounts.recover.core :as recover]
[status-im.ethereum.mnemonic :as mnemonic])) [status-im.ethereum.mnemonic :as mnemonic]
[taoensso.timbre :as log]))
(fx/defn start-adding-new-account (fx/defn start-adding-new-account
{:events [:wallet.accounts/start-adding-new-account]} {:events [:wallet.accounts/start-adding-new-account]}
@ -226,6 +227,9 @@
{:events [:wallet.accounts/add-new-account]} {:events [:wallet.accounts/add-new-account]}
[{:keys [db] :as cofx} hashed-password] [{:keys [db] :as cofx} hashed-password]
(let [{:keys [type step]} (:add-account db)] (let [{:keys [type step]} (:add-account db)]
(log/debug "[wallet] add-new-account"
"type" type
"step" step)
(when-not step (when-not step
(case type (case type
:watch :watch
@ -286,4 +290,4 @@
(fx/defn wallet-accounts-share (fx/defn wallet-accounts-share
{:events [:wallet.accounts/share]} {:events [:wallet.accounts/share]}
[_ address] [_ address]
{:list.selection/open-share {:message (eip55/address->checksum address)}}) {:list.selection/open-share {:message (eip55/address->checksum address)}})