Skip to content

Commit 34b4372

Browse files
committed
[#9749] Support importing private key and seed
1 parent 001264b commit 34b4372

File tree

14 files changed

+422
-308
lines changed

14 files changed

+422
-308
lines changed

modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java

+17
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,23 @@ public void run() {
776776
StatusThreadPoolExecutor.getInstance().execute(r);
777777
}
778778

779+
@ReactMethod
780+
public void multiAccountImportPrivateKey(final String json, final Callback callback) {
781+
Log.d(TAG, "multiAccountImportPrivateKey");
782+
if (!checkAvailability()) {
783+
callback.invoke(false);
784+
return;
785+
}
786+
Runnable r = new Runnable() {
787+
@Override
788+
public void run() {
789+
String res = Statusgo.multiAccountImportPrivateKey(json);
790+
callback.invoke(res);
791+
}
792+
};
793+
StatusThreadPoolExecutor.getInstance().execute(r);
794+
}
795+
779796
@ReactMethod
780797
public void hashTransaction(final String txArgsJSON, final Callback callback) {
781798
Log.d(TAG, "hashTransaction");

modules/react-native-status/ios/RCTStatus/RCTStatus.m

+10
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ - (void)handleSignal:(NSString *)signal
266266
callback(@[result]);
267267
}
268268

269+
//////////////////////////////////////////////////////////////////// multiAccountImportPrivateKey
270+
RCT_EXPORT_METHOD(multiAccountImportPrivateKey:(NSString *)json
271+
callback:(RCTResponseSenderBlock)callback) {
272+
#if DEBUG
273+
NSLog(@"MultiAccountImportPrivateKey() method called");
274+
#endif
275+
NSString *result = StatusgoMultiAccountImportPrivateKey(json);
276+
callback(@[result]);
277+
}
278+
269279
//////////////////////////////////////////////////////////////////// multiAccountImportMnemonic
270280
RCT_EXPORT_METHOD(multiAccountImportMnemonic:(NSString *)json
271281
callback:(RCTResponseSenderBlock)callback) {

src/status_im/hardwallet/wallet.cljs

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
(if card-connected?
1919
(fx/merge cofx
2020
{:db (assoc-in db [:hardwallet :on-export-success]
21-
#(vector :wallet.accounts/account-generated
22-
{:name (str "Account " path-num)
23-
;; Strip leading 04 prefix denoting uncompressed key format
21+
#(vector :wallet.accounts/account-stored
22+
{;; Strip leading 04 prefix denoting uncompressed key format
2423
:address (eip55/address->checksum (str "0x" (ethereum/public-key->address (subs % 2))))
2524
:public-key (str "0x" %)
26-
:path path
27-
:color (rand-nth colors/account-colors)}))
25+
:path path}))
2826
:hardwallet/export-key {:pin pin :pairing pairing :path path}}
2927
(navigation/navigate-to-cofx :keycard-processing nil)
3028
(common/set-on-card-connected :wallet.accounts/generate-new-keycard-account))

src/status_im/native_module/core.cljs

+7-1
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,15 @@
157157
(types/clj->json {:mnemonicPhrase mnemonic
158158
;;NOTE this is not the multiaccount password
159159
:Bip39Passphrase password})
160-
161160
callback))
162161

162+
(defn multiaccount-import-private-key
163+
[private-key callback]
164+
(log/debug "[native-module] multiaccount-import-private-key")
165+
(.multiAccountImportPrivateKey (status)
166+
(types/clj->json {:privateKey private-key})
167+
callback))
168+
163169
(defn verify
164170
"NOTE: beware, the password has to be sha3 hashed"
165171
[address hashed-password callback]

src/status_im/subs.cljs

+13-9
Original file line numberDiff line numberDiff line change
@@ -539,15 +539,19 @@
539539
:add-account-disabled?
540540
:<- [:multiaccount/accounts]
541541
:<- [:add-account]
542-
(fn [[accounts {:keys [address]}]]
543-
(or (not (ethereum/address? address))
544-
(some #(when (= (:address %) address) %) accounts))))
545-
546-
(re-frame/reg-sub
547-
:add-account-scanned-address
548-
:<- [:add-account]
549-
(fn [add-account]
550-
(get add-account :scanned-address)))
542+
(fn [[accounts {:keys [address type account seed private-key]}]]
543+
(or (string/blank? (:name account))
544+
(case type
545+
:generate
546+
false
547+
:watch
548+
(or (not (ethereum/address? address))
549+
(some #(when (= (:address %) address) %) accounts))
550+
:key
551+
(string/blank? (security/safe-unmask-data private-key))
552+
:seed
553+
(string/blank? (security/safe-unmask-data seed))
554+
false))))
551555

552556
;;CHAT ==============================================================================================================
553557

src/status_im/ui/screens/routing/back_actions.cljs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
:new-public-chat :default
99
:wallet-account :default
1010
:add-new-account :default
11-
:add-watch-account :default
12-
:add-new-account-password :default
1311
:add-new-account-pin :default
1412
:about-app :default
1513
:help-center :default

src/status_im/ui/screens/routing/screens.cljs

-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@
184184
:welcome [:modal home/welcome]
185185
:keycard-welcome keycard/welcome
186186
:add-new-account add-account/add-account
187-
:add-watch-account add-account/add-watch-account
188-
:add-new-account-password add-account/password
189187
:add-new-account-pin add-account/pin
190-
:account-added account-settings/account-added
191188
:account-settings account-settings/account-settings})
192189

193190
(defn get-screen [screen]

src/status_im/ui/screens/routing/wallet_stack.cljs

-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
:screens (cond-> [:wallet
77
:wallet-account
88
:add-new-account
9-
:add-watch-account
10-
:add-new-account-password
119
:add-new-account-pin
12-
:account-added
1310
:account-settings
1411
:collectibles-list
1512
:wallet-onboarding-setup

src/status_im/ui/screens/wallet/account_settings/views.cljs

+1-41
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
[status-im.i18n :as i18n]
77
[status-im.ui.components.icons.vector-icons :as icons]
88
[status-im.ui.components.colors :as colors]
9-
[status-im.ui.components.button :as button]
10-
[clojure.string :as string]
119
[status-im.ui.components.toolbar :as toolbar]
1210
[status-im.ui.components.copyable-text :as copyable-text]
1311
[reagent.core :as reagent]
@@ -33,45 +31,6 @@
3331
:label (i18n/label :t/cancel)
3432
:type :secondary}}]]))
3533

36-
(defview account-added []
37-
(letsubs [{:keys [account]} [:add-account]]
38-
[react/keyboard-avoiding-view {:flex 1}
39-
[react/scroll-view {:keyboard-should-persist-taps :handled
40-
:style {:margin-top 70 :flex 1}}
41-
[react/view {:align-items :center :padding-horizontal 40}
42-
[react/view {:height 40 :width 40 :border-radius 20 :align-items :center :justify-content :center
43-
:background-color (:color account)}
44-
[icons/icon :main-icons/check {:color colors/white}]]
45-
[react/text {:style {:typography :header :margin-top 16}}
46-
(i18n/label :t/account-added)]
47-
[react/text {:style {:color colors/gray :text-align :center :margin-top 16 :line-height 22}}
48-
(i18n/label :t/you-can-change-account)]]
49-
[react/view {:height 52}]
50-
[react/view {:margin-horizontal 16}
51-
[text-input/text-input-with-label
52-
{:label (i18n/label :t/account-name)
53-
:auto-focus false
54-
:default-value (:name account)
55-
:placeholder (i18n/label :t/account-name)
56-
:on-change-text #(re-frame/dispatch [:set-in [:add-account :account :name] %])}]
57-
[react/text {:style {:margin-top 30}} (i18n/label :t/account-color)]
58-
[react/touchable-highlight
59-
{:on-press #(re-frame/dispatch [:show-popover
60-
{:view [colors-popover (:color account)
61-
(fn [new-color]
62-
(re-frame/dispatch [:set-in [:add-account :account :color] new-color])
63-
(re-frame/dispatch [:hide-popover]))]
64-
:style {:max-height "60%"}}])}
65-
[react/view {:height 52 :margin-top 12 :background-color (:color account) :border-radius 8
66-
:align-items :flex-end :justify-content :center :padding-right 12}
67-
[icons/icon :main-icons/dropdown {:color colors/white}]]]]]
68-
[toolbar/toolbar
69-
{:show-border? true
70-
:right {:type :next
71-
:label (i18n/label :t/finish)
72-
:on-press #(re-frame/dispatch [:wallet.accounts/save-generated-account])
73-
:disabled? (string/blank? (:name account))}}]]))
74-
7534
(defn property [label value]
7635
[react/view {:margin-top 28}
7736
[react/text {:style {:color colors/gray}} label]
@@ -118,6 +77,7 @@
11877
[property (i18n/label :t/type)
11978
(case type
12079
:watch (i18n/label :t/watch-only)
80+
(:key :seed) (i18n/label :t/off-status-tree)
12181
(i18n/label :t/on-status-tree))]
12282
[property (i18n/label :t/wallet-address)
12383
[copyable-text/copyable-text-view

src/status_im/ui/screens/wallet/accounts/sheets.cljs

+40-22
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,29 @@
1515
:title :t/wallet-manage-assets
1616
:icon :main-icons/token
1717
:accessibility-label :wallet-manage-assets
18-
:on-press #(hide-sheet-and-dispatch [:navigate-to :wallet-settings-assets])}]
18+
:on-press #(hide-sheet-and-dispatch
19+
[:navigate-to :wallet-settings-assets])}]
1920
[list-item/list-item
2021
{:theme :action
2122
:title :t/set-currency
2223
:icon :main-icons/language
2324
:accessibility-label :wallet-set-currency
24-
:on-press #(hide-sheet-and-dispatch [:navigate-to :currency-settings])}]
25+
:on-press #(hide-sheet-and-dispatch
26+
[:navigate-to :currency-settings])}]
2527
[list-item/list-item
2628
{:theme :action
2729
:title :t/view-signing
2830
:icon :main-icons/info
29-
:on-press #(hide-sheet-and-dispatch [:show-popover {:view :signing-phrase}])}]
31+
:on-press #(hide-sheet-and-dispatch
32+
[:show-popover {:view :signing-phrase}])}]
3033
(when mnemonic
3134
[list-item/list-item
3235
{:theme :action-destructive
3336
:title :t/wallet-backup-recovery-title
3437
:icon :main-icons/security
3538
:accessibility-label :wallet-backup-recovery-title
36-
:on-press #(hide-sheet-and-dispatch [:navigate-to :backup-seed])}])]))
39+
:on-press #(hide-sheet-and-dispatch
40+
[:navigate-to :backup-seed])}])]))
3741

3842
(defn send-receive [account type]
3943
[react/view
@@ -43,7 +47,8 @@
4347
:title :t/wallet-send
4448
:icon :main-icons/send
4549
:accessibility-label :send-transaction-button
46-
:on-press #(hide-sheet-and-dispatch [:wallet/prepare-transaction-from-wallet account])}])
50+
:on-press #(hide-sheet-and-dispatch
51+
[:wallet/prepare-transaction-from-wallet account])}])
4752
[list-item/list-item
4853
{:theme :action
4954
:title :t/receive
@@ -56,27 +61,40 @@
5661
(defn add-account []
5762
[react/view
5863
[list-item/list-item
59-
{:theme :action
60-
:title :t/add-an-account
64+
{:title :t/generate-a-new-account
65+
:theme :action
6166
:icon :main-icons/add
62-
:on-press #(hide-sheet-and-dispatch [:navigate-to :add-new-account])}]
67+
:on-press #(hide-sheet-and-dispatch
68+
[:wallet.accounts/start-adding-new-account
69+
{:type :generate}])}]
70+
[list-item/list-item
71+
{:theme :action
72+
:title :t/add-a-watch-account
73+
:icon :main-icons/watch
74+
:on-press #(hide-sheet-and-dispatch
75+
[:wallet.accounts/start-adding-new-account
76+
{:type :watch}])}]
6377
[list-item/list-item
64-
{:theme :action
65-
:title :t/add-a-watch-account
66-
:icon :main-icons/watch
67-
:on-press #(hide-sheet-and-dispatch [:wallet.accounts/start-adding-new-account {:type :watch}])}]])
78+
{:title :t/enter-a-seed-phrase
79+
:theme :action
80+
:icon :main-icons/text
81+
:on-press #(hide-sheet-and-dispatch
82+
[:wallet.accounts/start-adding-new-account
83+
{:type :seed}])}]
84+
[list-item/list-item
85+
{:title :t/enter-a-private-key
86+
:theme :action
87+
:icon :main-icons/address
88+
:on-press #(hide-sheet-and-dispatch
89+
[:wallet.accounts/start-adding-new-account
90+
{:type :key}])}]])
6891

6992
(defn account-settings []
7093
[react/view
7194
[list-item/list-item
72-
{:theme :action
73-
:title :t/account-settings
95+
{:theme :action
96+
:title :t/account-settings
7497
:accessibility-label :account-settings-bottom-sheet
75-
:icon :main-icons/info
76-
:on-press #(hide-sheet-and-dispatch [:navigate-to :account-settings])}]
77-
;; Commented out for v1
78-
#_[list-item/list-item
79-
{:theme :action
80-
:title :t/export-account
81-
:icon :main-icons/copy
82-
:disabled? true}]])
98+
:icon :main-icons/info
99+
:on-press #(hide-sheet-and-dispatch
100+
[:navigate-to :account-settings])}]])

src/status_im/ui/screens/wallet/accounts/views.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
(defn add-card []
4646
[react/touchable-highlight {:on-press #(re-frame/dispatch [:bottom-sheet/show-sheet
4747
{:content sheets/add-account
48-
:content-height 130}])}
48+
:content-height 260}])}
4949
[react/view {:style styles/add-card}
5050
[react/view {:width 40 :height 40 :justify-content :center :border-radius 20
5151
:align-items :center :background-color colors/blue-transparent-10 :margin-bottom 8}

0 commit comments

Comments
 (0)