[#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-read)))
(defn keycard-multiaccount? [db]
(boolean (get-in db [:multiaccount :keycard-pairing])))

View File

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

View File

@ -3,30 +3,47 @@
[status-im.utils.fx :as fx]
[status-im.hardwallet.common :as common]
[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
{:events [:wallet.accounts/generate-new-keycard-account]}
[{:keys [db] :as cofx}]
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
path (str constants/path-wallet-root "/" path-num)
pin (common/vector->string (get-in db [:hardwallet :pin :export-key]))
pairing (common/get-pairing db)]
(common/show-connection-sheet
cofx
{:on-card-connected :hardwallet/load-loading-keys-screen
:handler
(fn [cofx]
(fx/merge
cofx
{:db
(assoc-in
db [:hardwallet :on-export-success]
#(vector :wallet.accounts/account-stored
{;; Strip leading 04 prefix denoting uncompressed key format
:address (eip55/address->checksum (str "0x" (ethereum/public-key->address (subs % 2))))
:public-key (str "0x" %)
:path path}))
[cofx]
(common/show-connection-sheet
cofx
{:on-card-connected :wallet.accounts/generate-new-keycard-account
:handler
(fn [{:keys [db]}]
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
path (str constants/path-wallet-root "/" path-num)
pin (common/vector->string (get-in db [:hardwallet :pin :export-key]))
pairing (common/get-pairing db)]
{:db
(assoc-in
db [:hardwallet :on-export-success]
#(vector :wallet.accounts/account-stored
{;; Strip leading 04 prefix denoting uncompressed key format
:address (eip55/address->checksum (str "0x" (ethereum/public-key->address (subs % 2))))
:public-key (str "0x" %)
:path path}))
:hardwallet/export-key {:pin pin :pairing pairing :path path}}
(common/set-on-card-connected :wallet.accounts/generate-new-keycard-account)))})))
:hardwallet/export-key {:pin pin :pairing pairing :path path}}))}))

View File

@ -57,4 +57,4 @@
[react/view {:position :absolute :left @title-padding :right @title-padding
:top 0 :bottom 0 :align-items :center :justify-content :center}
[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
(:require [re-frame.core :as re-frame]
[status-im.hardwallet.common :as common]
[status-im.utils.datetime :as utils.datetime]))
(re-frame/reg-sub
@ -37,6 +38,4 @@
(re-frame/reg-sub
:keycard-multiaccount?
(fn [db]
(boolean
(get-in db [:multiaccount :keycard-pairing]))))
common/keycard-multiaccount?)

View File

@ -59,39 +59,42 @@
:address (:address account)}])}]])
(defn add-account []
[react/view
[list-item/list-item
{:title :t/generate-a-new-account
:theme :action
:icon :main-icons/add
:accessibility-label :add-account-sheet-generate
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :generate}])}]
[list-item/list-item
{:theme :action
:title :t/add-a-watch-account
:icon :main-icons/watch
:accessibility-label :add-account-sheet-watch
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :watch}])}]
[list-item/list-item
{:title :t/enter-a-seed-phrase
:theme :action
:icon :main-icons/text
:accessibility-label :add-account-sheet-seed
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :seed}])}]
[list-item/list-item
{:title :t/enter-a-private-key
:theme :action
:icon :main-icons/address
:accessibility-label :add-account-sheet-private-key
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :key}])}]])
(let [keycard? @(re-frame/subscribe [:keycard-multiaccount?])]
[react/view
[list-item/list-item
{:title :t/generate-a-new-account
:theme :action
:icon :main-icons/add
:accessibility-label :add-account-sheet-generate
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :generate}])}]
[list-item/list-item
{:theme :action
:title :t/add-a-watch-account
:icon :main-icons/watch
:accessibility-label :add-account-sheet-watch
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :watch}])}]
(when-not keycard?
[list-item/list-item
{:title :t/enter-a-seed-phrase
:theme :action
:icon :main-icons/text
:accessibility-label :add-account-sheet-seed
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :seed}])}])
(when-not keycard?
[list-item/list-item
{:title :t/enter-a-private-key
:theme :action
:icon :main-icons/address
:accessibility-label :add-account-sheet-private-key
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :key}])}])]))
(defn account-settings []
[react/view
@ -101,4 +104,4 @@
:accessibility-label :account-settings-bottom-sheet
:icon :main-icons/info
: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.utils.security :as security]
[clojure.string :as string]
[status-im.utils.platform :as platform]))
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]))
(defn- request-camera-permissions []
(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 :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 []
(letsubs [{:keys [type account] :as add-account} [:add-account]
add-account-disabled? [:add-account-disabled?]
entered-password (reagent/atom "")]
entered-password (reagent/atom "")
keycard? [:keycard-multiaccount?]]
[react/keyboard-avoiding-view {:style {:flex 1}}
[add-account-topbar type]
[react/scroll-view {:keyboard-should-persist-taps :handled
:style {:flex 1}}
[settings add-account entered-password]
(when-not keycard?
[settings add-account entered-password])
[common-settings account]]
[toolbar/toolbar
{:show-border? true
@ -142,23 +163,19 @@
{:type :next
:label :t/add-account
:accessibility-label :add-account-add-account-button
:on-press #(re-frame/dispatch [:wallet.accounts/add-new-account
(ethereum/sha3 @entered-password)])
:disabled? (or add-account-disabled?
(and
(not (= type :watch))
(not (spec/valid? ::multiaccounts.db/password @entered-password))))}}]]))
:on-press
(if keycard?
#(re-frame/dispatch [:hardwallet/new-account-pin-sheet
{:view {:content pin
:height 256}}])
#(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]
[status-im.utils.security :as security]
[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
{:events [:wallet.accounts/start-adding-new-account]}
@ -226,6 +227,9 @@
{:events [:wallet.accounts/add-new-account]}
[{:keys [db] :as cofx} hashed-password]
(let [{:keys [type step]} (:add-account db)]
(log/debug "[wallet] add-new-account"
"type" type
"step" step)
(when-not step
(case type
:watch
@ -286,4 +290,4 @@
(fx/defn wallet-accounts-share
{:events [:wallet.accounts/share]}
[_ address]
{:list.selection/open-share {:message (eip55/address->checksum address)}})
{:list.selection/open-share {:message (eip55/address->checksum address)}})