[#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,22 +3,40 @@
[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}]
[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)]
(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]
@ -28,5 +46,4 @@
: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

@ -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,6 +59,7 @@
:address (:address account)}])}]])
(defn add-account []
(let [keycard? @(re-frame/subscribe [:keycard-multiaccount?])]
[react/view
[list-item/list-item
{:title :t/generate-a-new-account
@ -76,6 +77,7 @@
: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
@ -83,7 +85,8 @@
:accessibility-label :add-account-sheet-seed
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :seed}])}]
{:type :seed}])}])
(when-not keycard?
[list-item/list-item
{:title :t/enter-a-private-key
:theme :action
@ -91,7 +94,7 @@
:accessibility-label :add-account-sheet-private-key
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :key}])}]])
{:type :key}])}])]))
(defn account-settings []
[react/view

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,35 +127,16 @@
(re-frame/dispatch [:set-in [:add-account :account-error] nil])
(re-frame/dispatch [:set-in [:add-account :private-key] (security/mask-data %)]))}])])
(defview add-account []
(letsubs [{:keys [type account] :as add-account} [:add-account]
add-account-disabled? [:add-account-disabled?]
entered-password (reagent/atom "")]
[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]
[common-settings account]]
[toolbar/toolbar
{:show-border? true
:right
{: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))))}}]]))
(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]
[topbar/topbar
{:navigation :none
:accessories
[{:label :t/cancel
:handler #(re-frame/dispatch [:bottom-sheet/hide])}]}]
[pin.views/pin-view
{:pin pin
:status status
@ -162,3 +144,38 @@
: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 "")
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}}
(when-not keycard?
[settings add-account entered-password])
[common-settings account]]
[toolbar/toolbar
{:show-border? true
:right
{:type :next
:label :t/add-account
:accessibility-label :add-account-add-account-button
: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)))))}}]]))

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