Skip to content

Commit 41d81f6

Browse files
committed
review
1 parent cbe0bcd commit 41d81f6

File tree

6 files changed

+61
-48
lines changed

6 files changed

+61
-48
lines changed

src/status_im/contexts/wallet/create_account/select_keypair/view.cljs

+8-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[utils.i18n :as i18n]
1111
[utils.re-frame :as rf]))
1212

13-
(defn keypair-options
13+
(defn- keypair-options
1414
[]
1515
[quo/action-drawer
1616
[[{:icon :i/add
@@ -28,13 +28,13 @@
2828
:accessibility-label :import-private-key
2929
:label (i18n/label :t/import-private-key)}]]])
3030

31-
(defn parse-accounts
31+
(defn- parse-accounts
3232
[given-accounts]
3333
(->> given-accounts
3434
(filter (fn [{:keys [path]}]
3535
(not (string/starts-with? path constants/path-eip1581))))
36-
(map (fn [{:keys [colorId emoji name address]}]
37-
{:account-props {:customization-color (if (not-empty colorId) (keyword colorId) :blue)
36+
(map (fn [{:keys [customization-color emoji name address]}]
37+
{:account-props {:customization-color customization-color
3838
:size 32
3939
:emoji emoji
4040
:type :default
@@ -46,13 +46,13 @@
4646
:state :default
4747
:action :none}))))
4848

49-
(defn keypair
49+
(defn- keypair
5050
[item index _ {:keys [profile-picture compressed-key]}]
5151
(let [main-account (first (:accounts item))
52-
color (keyword (:colorId main-account))
52+
color (:customization-color main-account)
5353
accounts (parse-accounts (:accounts item))]
5454
[quo/keypair
55-
{:customization-color (if (not-empty (:colorId main-account)) color :blue)
55+
{:customization-color (if (not-empty (:customization-color main-account)) color :blue)
5656
:profile-picture (when (zero? index) profile-picture)
5757
:status-indicator false
5858
:type (if (zero? index) :default-keypair :other)
@@ -67,13 +67,12 @@
6767
:default-selected? (zero? index)
6868
:container-style {:margin-horizontal 20
6969
:margin-vertical 8}}]))
70-
(defn- view-internal
70+
(defn view
7171
[]
7272
(let [{:keys [compressed-key customization-color]} (rf/sub [:profile/profile])
7373
profile-with-image (rf/sub [:profile/profile-with-image])
7474
keypairs (rf/sub [:wallet/keypairs])
7575
profile-picture (profile.utils/photo profile-with-image)]
76-
(rn/use-effect #(rf/dispatch [:wallet/get-keypairs]))
7776
[rn/view {:style {:flex 1}}
7877
[quo/page-nav
7978
{:icon-name :i/close
@@ -101,7 +100,3 @@
101100
:button-one-props {:disabled? true
102101
:customization-color customization-color}
103102
:container-style style/bottom-action-container}]]))
104-
105-
(defn view
106-
[]
107-
[:f> view-internal])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(ns status-im.contexts.wallet.create-account.utils)
2+
3+
(defn prepare-new-keypair
4+
[{:keys [new-keypair address account-name account-color emoji derivation-path]}]
5+
(assoc new-keypair
6+
:name (:keypair-name new-keypair)
7+
:key-uid (:keyUid new-keypair)
8+
:type :seed
9+
:derived-from address
10+
:accounts [{:keypair-name (:keypair-name new-keypair)
11+
:key-uid (:keyUid new-keypair)
12+
:seed-phrase (:mnemonic new-keypair)
13+
:public-key (:publicKey new-keypair)
14+
:name account-name
15+
:type :seed
16+
:emoji emoji
17+
:colorID account-color
18+
:path derivation-path
19+
:address (:address new-keypair)}]))

src/status_im/contexts/wallet/create_account/view.cljs

+10-27
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,13 @@
1212
[status-im.constants :as constants]
1313
[status-im.contexts.wallet.common.utils :as utils]
1414
[status-im.contexts.wallet.create-account.style :as style]
15+
[status-im.contexts.wallet.create-account.utils :as create-account.utils]
1516
[utils.i18n :as i18n]
1617
[utils.re-frame :as rf]
1718
[utils.responsiveness :refer [iphone-11-Pro-20-pixel-from-width]]
1819
[utils.security.core :as security]
1920
[utils.string]))
2021

21-
(defn prepare-new-keypair
22-
[{:keys [new-keypair address account-name account-color emoji derivation-path]}]
23-
(assoc
24-
(assoc new-keypair
25-
:name (:keypair-name new-keypair)
26-
:key-uid (:keyUid new-keypair)
27-
:type :seed
28-
:derived-from address)
29-
:accounts
30-
[{:keypair-name (:keypair-name new-keypair)
31-
:key-uid (:keyUid new-keypair)
32-
:seed-phrase (:mnemonic new-keypair)
33-
:public-key (:publicKey new-keypair)
34-
:name account-name
35-
:type :seed
36-
:emoji emoji
37-
:colorID account-color
38-
:path derivation-path
39-
:address (:address new-keypair)}]))
4022

4123
(defn- get-keypair-data
4224
[primary-name derivation-path account-color {:keys [keypair-name]}]
@@ -144,16 +126,17 @@
144126
:on-auth-success (fn [entered-password]
145127
(if new-keypair
146128
(rf/dispatch
147-
[:wallet/finalize-new-keypair
129+
[:wallet/add-keypair-and-create-account
148130
{:sha3-pwd (security/safe-unmask-data
149131
entered-password)
150-
:new-keypair (prepare-new-keypair {:new-keypair new-keypair
151-
:address address
152-
:account-name @account-name
153-
:account-color @account-color
154-
:emoji @emoji
155-
:derivation-path
156-
@derivation-path})}])
132+
:new-keypair (create-account.utils/prepare-new-keypair
133+
{:new-keypair new-keypair
134+
:address address
135+
:account-name @account-name
136+
:account-color @account-color
137+
:emoji @emoji
138+
:derivation-path
139+
@derivation-path})}])
157140
(rf/dispatch [:wallet/derive-address-and-add-account
158141
{:sha3-pwd (security/safe-unmask-data
159142
entered-password)

src/status_im/contexts/wallet/events.cljs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
(ns status-im.contexts.wallet.events
22
(:require
3+
[camel-snake-kebab.core :as csk]
4+
[camel-snake-kebab.extras :as cske]
5+
[clojure.set :as set]
36
[clojure.string :as string]
47
[react-native.background-timer :as background-timer]
58
[react-native.platform :as platform]
@@ -202,15 +205,15 @@
202205
(first derived-address-details)]))]
203206
{:fx [[:dispatch [:wallet/create-derived-addresses account-details on-success]]]})))
204207

205-
(defn finalize-new-keypair
208+
(defn add-keypair-and-create-account
206209
[_ [{:keys [sha3-pwd new-keypair]}]]
207210
{:fx [[:json-rpc/call
208211
[{:method "accounts_addKeypair"
209212
:params [sha3-pwd new-keypair]
210-
:on-success [:wallet/add-account-success (string/lower-case (:address new-keypair))]
213+
:on-success [:wallet/add-account-success (comp string/lower-case (:address new-keypair))]
211214
:on-error #(log/info "failed to create keypair " %)}]]]})
212215

213-
(rf/reg-event-fx :wallet/finalize-new-keypair finalize-new-keypair)
216+
(rf/reg-event-fx :wallet/add-keypair-and-create-account add-keypair-and-create-account)
214217

215218
(defn get-keypairs
216219
[_]
@@ -222,9 +225,11 @@
222225

223226
(rf/reg-event-fx :wallet/get-keypairs get-keypairs)
224227

228+
225229
(defn get-keypairs-success
226230
[{:keys [db]} [keypairs]]
227-
{:db (assoc-in db [:wallet :keypairs] keypairs)})
231+
(let [renamed-data (set/rename-keys keypairs {:colorId :customization-color})]
232+
{:db (assoc-in db [:wallet :keypairs] (cske/transform-keys csk/->kebab-case-keyword renamed-data))}))
228233

229234
(rf/reg-event-fx :wallet/get-keypairs-success get-keypairs-success)
230235

@@ -397,7 +402,8 @@
397402
(fn []
398403
{:fx [[:dispatch [:wallet/start-wallet]]
399404
[:dispatch [:wallet/get-ethereum-chains]]
400-
[:dispatch [:wallet/get-accounts]]]}))
405+
[:dispatch [:wallet/get-accounts]]
406+
[:dispatch [:wallet/get-keypairs]]]}))
401407

402408
(rf/reg-event-fx :wallet/share-account
403409
(fn [_ [{:keys [content title]}]]

src/status_im/contexts/wallet/events_test.cljs

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@
5555
effects (events/clear-new-keypair {:db db})]
5656
(is (match? (:db effects) expected-db))))
5757

58-
(deftest finalize-new-keypair
58+
(deftest add-keypair-and-create-account
5959
(let [db {}
6060
sha3-pwd "password"
6161
new-keypair {:public-key "public_key" :private-key "private_key"}
6262
expected-db {:wallet {:ui {:create-account {:new-keypair "test-keypair"}}
6363
:keypairs [new-keypair]}}
64-
effects (events/finalize-new-keypair {:db db}
65-
[{:sha3-pwd sha3-pwd :new-keypair new-keypair}])
64+
effects (events/add-keypair-and-create-account {:db db}
65+
[{:sha3-pwd sha3-pwd
66+
:new-keypair new-keypair}])
6667
result-db (:db effects)]
6768
(is (match? result-db expected-db))))
6869

src/status_im/subs/wallet/wallet_test.cljs

+9
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,12 @@
497497
(get "0x3")
498498
(assoc :network-preferences-names #{}))]
499499
(rf/sub [sub-name])))))
500+
501+
(h/deftest-sub :wallet/keypairs
502+
[sub-name]
503+
(testing "returns all keypairs"
504+
(swap! rf-db/app-db
505+
#(assoc-in % [:wallet :keypairs] keypairs))
506+
(is
507+
(= keypairs
508+
(rf/sub [sub-name])))))

0 commit comments

Comments
 (0)