Skip to content

Commit

Permalink
[#9749] Support importing private key and seed
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Feb 28, 2020
1 parent de8d109 commit 18d2221
Show file tree
Hide file tree
Showing 14 changed files with 393 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,23 @@ public void run() {
StatusThreadPoolExecutor.getInstance().execute(r);
}

@ReactMethod
public void multiAccountImportPrivateKey(final String json, final Callback callback) {
Log.d(TAG, "multiAccountImportPrivateKey");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.multiAccountImportPrivateKey(json);
callback.invoke(res);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}

@ReactMethod
public void hashTransaction(final String txArgsJSON, final Callback callback) {
Log.d(TAG, "hashTransaction");
Expand Down
10 changes: 10 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ - (void)handleSignal:(NSString *)signal
callback(@[result]);
}

//////////////////////////////////////////////////////////////////// multiAccountImportPrivateKey
RCT_EXPORT_METHOD(multiAccountImportPrivateKey:(NSString *)json
callback:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"MultiAccountImportPrivateKey() method called");
#endif
NSString *result = StatusgoMultiAccountImportPrivateKey(json);
callback(@[result]);
}

//////////////////////////////////////////////////////////////////// multiAccountImportMnemonic
RCT_EXPORT_METHOD(multiAccountImportMnemonic:(NSString *)json
callback:(RCTResponseSenderBlock)callback) {
Expand Down
8 changes: 3 additions & 5 deletions src/status_im/hardwallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
(if card-connected?
(fx/merge cofx
{:db (assoc-in db [:hardwallet :on-export-success]
#(vector :wallet.accounts/account-generated
{:name (str "Account " path-num)
;; Strip leading 04 prefix denoting uncompressed key format
#(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
:color (rand-nth colors/account-colors)}))
:path path}))
:hardwallet/export-key {:pin pin :pairing pairing :path path}}
(navigation/navigate-to-cofx :keycard-processing nil)
(common/set-on-card-connected :wallet.accounts/generate-new-keycard-account))
Expand Down
8 changes: 7 additions & 1 deletion src/status_im/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,15 @@
(types/clj->json {:mnemonicPhrase mnemonic
;;NOTE this is not the multiaccount password
:Bip39Passphrase password})

callback))

(defn multiaccount-import-private-key
[private-key callback]
(log/debug "[native-module] multiaccount-import-private-key")
(.multiAccountImportPrivateKey (status)
(types/clj->json {:privateKey private-key})
callback))

(defn verify
"NOTE: beware, the password has to be sha3 hashed"
[address hashed-password callback]
Expand Down
22 changes: 13 additions & 9 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,19 @@
:add-account-disabled?
:<- [:multiaccount/accounts]
:<- [:add-account]
(fn [[accounts {:keys [address]}]]
(or (not (ethereum/address? address))
(some #(when (= (:address %) address) %) accounts))))

(re-frame/reg-sub
:add-account-scanned-address
:<- [:add-account]
(fn [add-account]
(get add-account :scanned-address)))
(fn [[accounts {:keys [address type account seed private-key]}]]
(or (string/blank? (:name account))
(case type
:generate
false
:watch
(or (not (ethereum/address? address))
(some #(when (= (:address %) address) %) accounts))
:key
(string/blank? (security/safe-unmask-data private-key))
:seed
(string/blank? (security/safe-unmask-data seed))
false))))

;;CHAT ==============================================================================================================

Expand Down
2 changes: 0 additions & 2 deletions src/status_im/ui/screens/routing/back_actions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
:new-public-chat :default
:wallet-account :default
:add-new-account :default
:add-watch-account :default
:add-new-account-password :default
:add-new-account-pin :default
:about-app :default
:help-center :default
Expand Down
3 changes: 0 additions & 3 deletions src/status_im/ui/screens/routing/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@
:welcome [:modal home/welcome]
:keycard-welcome keycard/welcome
:add-new-account add-account/add-account
:add-watch-account add-account/add-watch-account
:add-new-account-password add-account/password
:add-new-account-pin add-account/pin
:account-added account-settings/account-added
:account-settings account-settings/account-settings})

(defn get-screen [screen]
Expand Down
3 changes: 0 additions & 3 deletions src/status_im/ui/screens/routing/wallet_stack.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
:screens (cond-> [:wallet
:wallet-account
:add-new-account
:add-watch-account
:add-new-account-password
:add-new-account-pin
:account-added
:account-settings
:collectibles-list
:wallet-onboarding-setup
Expand Down
42 changes: 1 addition & 41 deletions src/status_im/ui/screens/wallet/account_settings/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
[status-im.i18n :as i18n]
[status-im.ui.components.icons.vector-icons :as icons]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.button :as button]
[clojure.string :as string]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.components.copyable-text :as copyable-text]
[reagent.core :as reagent]
Expand All @@ -33,45 +31,6 @@
:label (i18n/label :t/cancel)
:type :secondary}}]]))

(defview account-added []
(letsubs [{:keys [account]} [:add-account]]
[react/keyboard-avoiding-view {:flex 1}
[react/scroll-view {:keyboard-should-persist-taps :handled
:style {:margin-top 70 :flex 1}}
[react/view {:align-items :center :padding-horizontal 40}
[react/view {:height 40 :width 40 :border-radius 20 :align-items :center :justify-content :center
:background-color (:color account)}
[icons/icon :main-icons/check {:color colors/white}]]
[react/text {:style {:typography :header :margin-top 16}}
(i18n/label :t/account-added)]
[react/text {:style {:color colors/gray :text-align :center :margin-top 16 :line-height 22}}
(i18n/label :t/you-can-change-account)]]
[react/view {:height 52}]
[react/view {:margin-horizontal 16}
[text-input/text-input-with-label
{:label (i18n/label :t/account-name)
:auto-focus false
:default-value (:name account)
:placeholder (i18n/label :t/account-name)
:on-change-text #(re-frame/dispatch [:set-in [:add-account :account :name] %])}]
[react/text {:style {:margin-top 30}} (i18n/label :t/account-color)]
[react/touchable-highlight
{:on-press #(re-frame/dispatch [:show-popover
{:view [colors-popover (:color account)
(fn [new-color]
(re-frame/dispatch [:set-in [:add-account :account :color] new-color])
(re-frame/dispatch [:hide-popover]))]
:style {:max-height "60%"}}])}
[react/view {:height 52 :margin-top 12 :background-color (:color account) :border-radius 8
:align-items :flex-end :justify-content :center :padding-right 12}
[icons/icon :main-icons/dropdown {:color colors/white}]]]]]
[toolbar/toolbar
{:show-border? true
:right {:type :next
:label (i18n/label :t/finish)
:on-press #(re-frame/dispatch [:wallet.accounts/save-generated-account])
:disabled? (string/blank? (:name account))}}]]))

(defn property [label value]
[react/view {:margin-top 28}
[react/text {:style {:color colors/gray}} label]
Expand Down Expand Up @@ -118,6 +77,7 @@
[property (i18n/label :t/type)
(case type
:watch (i18n/label :t/watch-only)
(:key :seed) (i18n/label :t/off-status-tree)
(i18n/label :t/on-status-tree))]
[property (i18n/label :t/wallet-address)
[copyable-text/copyable-text-view
Expand Down
62 changes: 40 additions & 22 deletions src/status_im/ui/screens/wallet/accounts/sheets.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@
:title :t/wallet-manage-assets
:icon :main-icons/token
:accessibility-label :wallet-manage-assets
:on-press #(hide-sheet-and-dispatch [:navigate-to :wallet-settings-assets])}]
:on-press #(hide-sheet-and-dispatch
[:navigate-to :wallet-settings-assets])}]
[list-item/list-item
{:theme :action
:title :t/set-currency
:icon :main-icons/language
:accessibility-label :wallet-set-currency
:on-press #(hide-sheet-and-dispatch [:navigate-to :currency-settings])}]
:on-press #(hide-sheet-and-dispatch
[:navigate-to :currency-settings])}]
[list-item/list-item
{:theme :action
:title :t/view-signing
:icon :main-icons/info
:on-press #(hide-sheet-and-dispatch [:show-popover {:view :signing-phrase}])}]
:on-press #(hide-sheet-and-dispatch
[:show-popover {:view :signing-phrase}])}]
(when mnemonic
[list-item/list-item
{:theme :action-destructive
:title :t/wallet-backup-recovery-title
:icon :main-icons/security
:accessibility-label :wallet-backup-recovery-title
:on-press #(hide-sheet-and-dispatch [:navigate-to :backup-seed])}])]))
:on-press #(hide-sheet-and-dispatch
[:navigate-to :backup-seed])}])]))

(defn send-receive [account type]
[react/view
Expand All @@ -43,7 +47,8 @@
:title :t/wallet-send
:icon :main-icons/send
:accessibility-label :send-transaction-button
:on-press #(hide-sheet-and-dispatch [:wallet/prepare-transaction-from-wallet account])}])
:on-press #(hide-sheet-and-dispatch
[:wallet/prepare-transaction-from-wallet account])}])
[list-item/list-item
{:theme :action
:title :t/receive
Expand All @@ -56,27 +61,40 @@
(defn add-account []
[react/view
[list-item/list-item
{:theme :action
:title :t/add-an-account
{:title :t/generate-a-new-account
:theme :action
:icon :main-icons/add
:on-press #(hide-sheet-and-dispatch [:navigate-to :add-new-account])}]
: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
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :watch}])}]
[list-item/list-item
{:theme :action
:title :t/add-a-watch-account
:icon :main-icons/watch
:on-press #(hide-sheet-and-dispatch [:wallet.accounts/start-adding-new-account {:type :watch}])}]])
{:title :t/enter-a-seed-phrase
:theme :action
:icon :main-icons/text
: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
:on-press #(hide-sheet-and-dispatch
[:wallet.accounts/start-adding-new-account
{:type :key}])}]])

(defn account-settings []
[react/view
[list-item/list-item
{:theme :action
:title :t/account-settings
{:theme :action
:title :t/account-settings
:accessibility-label :account-settings-bottom-sheet
:icon :main-icons/info
:on-press #(hide-sheet-and-dispatch [:navigate-to :account-settings])}]
;; Commented out for v1
#_[list-item/list-item
{:theme :action
:title :t/export-account
:icon :main-icons/copy
:disabled? true}]])
:icon :main-icons/info
:on-press #(hide-sheet-and-dispatch
[:navigate-to :account-settings])}]])
2 changes: 1 addition & 1 deletion src/status_im/ui/screens/wallet/accounts/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(defn add-card []
[react/touchable-highlight {:on-press #(re-frame/dispatch [:bottom-sheet/show-sheet
{:content sheets/add-account
:content-height 130}])}
:content-height 260}])}
[react/view {:style styles/add-card}
[react/view {:width 40 :height 40 :justify-content :center :border-radius 20
:align-items :center :background-color colors/blue-transparent-10 :margin-bottom 8}
Expand Down
Loading

0 comments on commit 18d2221

Please sign in to comment.