Skip to content

Commit e6e4a29

Browse files
committed
feat: keypair list
1 parent 68235be commit e6e4a29

File tree

5 files changed

+88
-39
lines changed

5 files changed

+88
-39
lines changed

src/quo/components/wallet/keypair/view.cljs

+8-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
:accessibility-label :options-button}]])]))
6161

6262
(defn details-view
63-
[{:keys [details stored blur? theme]}]
63+
[{:keys [details stored type blur? theme]}]
6464
(let [{:keys [address]} details]
6565
[rn/view
6666
{:style {:flex-direction :row
@@ -70,10 +70,11 @@
7070
{:size :paragraph-2
7171
:style (style/subtitle blur? theme)}
7272
address]
73-
[text/text
74-
{:size :paragraph-2
75-
:style (merge (style/subtitle blur? theme) {:bottom (if platform/ios? 2 -2)})}
76-
""]
73+
(when (= type :default-keypair)
74+
[text/text
75+
{:size :paragraph-2
76+
:style (merge (style/subtitle blur? theme) {:bottom (if platform/ios? 2 -2)})}
77+
""])
7778
[text/text
7879
{:size :paragraph-2
7980
:style (style/subtitle blur? theme)}
@@ -87,8 +88,8 @@
8788
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme))}]])]))
8889

8990
(defn- view-internal
90-
[]
91-
(let [selected? (reagent/atom true)]
91+
[{:keys [default-selected?]}]
92+
(let [selected? (reagent/atom default-selected?)]
9293
(fn [{:keys [accounts action container-style] :as props}]
9394
[rn/pressable
9495
{:style (merge (style/container (merge props {:selected? @selected?})) container-style)

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

+51-20
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,49 @@
3838
:state :default
3939
:action :none}])
4040

41-
(defn view
41+
(defn parse-accounts
42+
[given-accounts]
43+
(map (fn [{:keys [colorId emoji name address]}]
44+
{:account-props {:customization-color (if (not-empty colorId) (keyword colorId) :blue)
45+
:size 32
46+
:emoji emoji
47+
:type :default
48+
:name name
49+
:address address}
50+
:networks [{:network-name :ethereum :short-name "eth"}
51+
{:network-name :optimism :short-name "opt"}]
52+
:state :default
53+
:action :none})
54+
given-accounts))
55+
56+
(defn keypair
57+
[item index _ {:keys [profile-picture compressed-key]}]
58+
(let [main-account (first (:accounts item))
59+
color (keyword (:colorId main-account))
60+
parsed-accounts (parse-accounts (:accounts item))]
61+
[quo/keypair
62+
{:customization-color (if (not-empty (:colorId main-account)) color :blue)
63+
:profile-picture (when (zero? index) profile-picture)
64+
:status-indicator false
65+
:type (if (zero? index) :default-keypair :other)
66+
:stored :on-device
67+
:on-options-press #(js/alert "Options pressed")
68+
:action :selector
69+
:blur? false
70+
:details {:full-name (:name item)
71+
:address (when (zero? index)
72+
(utils/get-shortened-compressed-key compressed-key))}
73+
:accounts parsed-accounts
74+
:default-selected? (zero? index)
75+
:container-style {:margin-horizontal 20
76+
:margin-vertical 8}}]))
77+
(defn- view-internal
4278
[]
43-
(let [{:keys [public-key compressed-key
44-
customization-color]} (rf/sub [:profile/profile])
45-
[display-name _] (rf/sub [:contacts/contact-two-names-by-identity public-key])
46-
profile-with-image (rf/sub [:profile/profile-with-image])
47-
profile-picture (profile.utils/photo profile-with-image)]
79+
(let [{:keys [compressed-key customization-color]} (rf/sub [:profile/profile])
80+
profile-with-image (rf/sub [:profile/profile-with-image])
81+
keypairs (rf/sub [:wallet/keypairs])
82+
profile-picture (profile.utils/photo profile-with-image)]
83+
(rn/use-effect #(rf/dispatch [:wallet/get-keypairs]))
4884
[rn/view {:style {:flex 1}}
4985
[quo/page-nav
5086
{:icon-name :i/close
@@ -60,23 +96,18 @@
6096
[:show-bottom-sheet {:content keypair-options}])}
6197
:description :text
6298
:description-text (i18n/label :t/keypairs-description)}]
63-
[quo/keypair
64-
{:customization-color customization-color
65-
:profile-picture profile-picture
66-
:status-indicator false
67-
:type :default-keypair
68-
:stored :on-device
69-
:on-options-press #(js/alert "Options pressed")
70-
:action :selector
71-
:blur? false
72-
:details {:full-name display-name
73-
:address (utils/get-shortened-compressed-key compressed-key)}
74-
:accounts accounts
75-
:container-style {:margin-horizontal 20
76-
:margin-vertical 8}}]
99+
[rn/flat-list
100+
{:data keypairs
101+
:render-fn keypair
102+
:render-data {:profile-picture profile-picture
103+
:compressed-key compressed-key}}]
77104
[quo/bottom-actions
78105
{:actions :one-action
79106
:button-one-label (i18n/label :t/confirm-account-origin)
80107
:button-one-props {:disabled? true
81108
:customization-color customization-color}
82109
:container-style style/bottom-action-container}]]))
110+
111+
(defn view
112+
[]
113+
[:f> view-internal])

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@
5555
account-name (reagent/atom "")
5656
placeholder (i18n/label :t/default-account-placeholder
5757
{:number (inc number-of-accounts)})
58-
derivation-path (reagent/atom (utils/get-derivation-path (inc number-of-accounts)))
58+
derivation-path (reagent/atom (utils/get-derivation-path number-of-accounts))
5959
{:keys [public-key address]} (rf/sub [:profile/profile])
6060
on-change-text #(reset! account-name %)
6161
primary-name (first (rf/sub [:contacts/contact-two-names-by-identity
6262
public-key]))
6363
{window-width :width} (rn/get-window)]
6464
(fn [{:keys [theme]}]
6565
(let [{:keys [new-keypair]} (rf/sub [:wallet/create-account])]
66-
(println "qqq" address)
6766
(rn/use-effect (fn [] #(rf/dispatch [:wallet/clear-new-keypair])))
6867
[rn/view {:style {:flex 1}}
6968
[quo/page-nav
@@ -132,14 +131,14 @@
132131
(merge new-keypair
133132
{:name (:keypair-name new-keypair)
134133
:key-uid (:keyUid new-keypair)
135-
:type :generated
134+
:type :seed
136135
:derived-from address})
137136
{:accounts [{:keypair-name (:keypair-name new-keypair)
138137
:key-uid (:keyUid new-keypair)
139138
:seed-phrase (:mnemonic new-keypair)
140139
:public-key (:publicKey new-keypair)
141140
:name @account-name
142-
:type :generated
141+
:type :seed
143142
:emoji @emoji
144143
:colorID @account-color
145144
:path @derivation-path

src/status_im/contexts/wallet/events.cljs

+21-8
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,33 @@
198198
:wallet/derive-address-and-add-account
199199
(fn [_ [account-details]]
200200
(let [on-success (fn [derived-address-details]
201-
(println "dervied d" derived-address-details)
202201
(rf/dispatch [:wallet/add-account account-details
203202
(first derived-address-details)]))]
204203
{:fx [[:dispatch [:wallet/create-derived-addresses account-details on-success]]]})))
205204

206205
(rf/reg-event-fx
207206
:wallet/finalize-new-keypair
208-
(fn [_ [{:keys [sha3-pwd new-keypair] :as account-details}]]
209-
(let [account-config {}]
210-
{:fx [[:json-rpc/call
211-
[{:method "accounts_addKeypair"
212-
:params [sha3-pwd new-keypair]
213-
:on-success #(println "success new keypair: " %)
214-
:on-error #(log/info "failed to create keypair " %)}]]]})))
207+
(fn [_ [{:keys [sha3-pwd new-keypair]}]]
208+
{:fx [[:json-rpc/call
209+
[{:method "accounts_addKeypair"
210+
:params [sha3-pwd new-keypair]
211+
:on-success [:wallet/add-account-success (string/lower-case (:address new-keypair))]
212+
:on-error #(log/info "failed to create keypair " %)}]]]}))
213+
214+
(rf/reg-event-fx
215+
:wallet/get-keypairs
216+
(fn [{:keys [db]}]
217+
{:fx [[:json-rpc/call
218+
[{:method "accounts_getKeypairs"
219+
:params []
220+
:on-success [:wallet/get-keypairs-success]
221+
:on-error #(log/info "failed to get keypairs " %)}]]]}))
222+
223+
(rf/reg-event-fx
224+
:wallet/get-keypairs-success
225+
(fn [{:keys [db]} [keypairs]]
226+
(let []
227+
{:db (assoc-in db [:wallet :keypairs] keypairs)})))
215228

216229
(rf/reg-event-fx :wallet/bridge-select-token
217230
(fn [{:keys [db]} [{:keys [token stack-id]}]]

src/status_im/subs/wallet/wallet.cljs

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
:<- [:wallet/ui]
9494
:-> :watch-address-activity-state)
9595

96+
(rf/reg-sub
97+
:wallet/keypairs
98+
:<- [:wallet]
99+
:-> :keypairs)
100+
96101
(rf/reg-sub
97102
:wallet/accounts
98103
:<- [:wallet]

0 commit comments

Comments
 (0)