Skip to content

Commit 23d9c63

Browse files
J-Son89yevh-berdnyk
authored andcommitted
chore: add ability to create watch address & some related ui changes on account page (#17868)
1 parent 4d8b42f commit 23d9c63

File tree

13 files changed

+137
-107
lines changed

13 files changed

+137
-107
lines changed

src/quo/components/avatars/account_avatar/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
{:accessibility-label :account-emoji
3131
:adjusts-font-size-to-fit true
3232
:style {:font-size emoji-size}}
33-
(string/trim emoji)]]))
33+
(when emoji (string/trim emoji))]]))
3434

3535
(def view (quo.theme/with-theme view-internal))

src/quo/components/avatars/channel_avatar/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
[rn/text
6868
{:style (style/emoji-size size)
6969
:accessibility-label :emoji}
70-
(string/trim emoji)])
70+
(when emoji (string/trim emoji))])
7171
[lock locked? size theme]])
7272

7373
(def view (quo.theme/with-theme view-internal))

src/quo/components/avatars/wallet_user_avatar/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
:size (:font-size (size properties))
5757
:weight (if monospace? :monospace (:font-weight (size properties)))
5858
:style (style/text customization-color neutral? theme)}
59-
(if lowercase? (string/lower-case initials) initials)]]))
59+
(if (and initials lowercase?) (string/lower-case initials) initials)]]))
6060

6161
(def wallet-user-avatar (quo.theme/with-theme view-internal))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
| key | description |
134134
| -------------|-------------|
135135
| `:account-name` | A value representing the account name (default `nil`)
136-
| `:account` | A value that represents if the account is a `:watched-account` or a `:default` account. (default `nil`)
136+
| `:account` | A value that represents if the account is a `:watched-address` or a `:default` account. (default `nil`)
137137
| `:time-frame` | A value that represents the type of the timeframe, Can be from a preset of time frames. `[:1-week :1-month :3-months :1-year :custom]` (default `nil`) if custom is set, We expect a start time and if there's a space between two times that are in `time-frame-string` we'll split them with an arrow to the right icon
138138
| `:loading?` | A value that indicates that component is loading data. (default `nil`)
139139
| `:metrics` | A value that indicates if the account value have increased can be `:positive` or `:negative` (default `nil`)

src/status_im2/common/bottom_sheet/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
[rn/view
118118
{:style (style/sheet-content theme padding-bottom-override insets shell? bottom-margin)
119119
:on-layout #(reset! sheet-height (.-nativeEvent.layout.height ^js %))}
120-
(when gradient-cover?
120+
(when (and gradient-cover? customization-color)
121121
[rn/view {:style style/gradient-bg}
122122
[quo/gradient-cover
123123
{:customization-color customization-color
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
(ns status-im2.contexts.wallet.account.tabs.about.view
22
(:require
33
[quo.core :as quo]
4-
[quo.foundations.colors :as colors]
5-
[quo.theme :as quo.theme]
64
[react-native.core :as rn]
75
[status-im2.contexts.wallet.account.tabs.about.style :as style]
86
[status-im2.contexts.wallet.common.temp :as temp]
97
[utils.i18n :as i18n]
108
[utils.re-frame :as rf]))
119

12-
(defn description
13-
[{:keys [address theme]}]
14-
(let [networks-list (rf/sub [:wallet/network-details])]
15-
[quo/text {:size :paragraph-2}
16-
(map (fn [{:keys [chain-id short-name network-name]}]
17-
^{:key (str chain-id short-name)}
18-
[quo/text
19-
{:size :paragraph-2
20-
:weight :medium
21-
:style {:color (colors/resolve-color network-name theme)}}
22-
(str short-name ":")])
23-
networks-list)
24-
[quo/text
25-
{:size :paragraph-2
26-
:weight :monospace}
27-
address]]))
28-
2910
(defn about-options
3011
[]
3112
[quo/action-drawer
@@ -51,19 +32,25 @@
5132
:accessibility-label :share-address
5233
:label (i18n/label :t/share-address)}]]])
5334

54-
(defn- view-internal
35+
(defn view
5536
[]
56-
[rn/view {:style style/about-tab}
57-
[quo/data-item
58-
(merge temp/data-item-state
59-
{:custom-subtitle (fn [] [quo/address-text
60-
{:networks [{:network-name :ethereum :short-name "eth"}
61-
{:network-name :optimism :short-name "opt"}
62-
{:network-name :arbitrum :short-name "arb1"}]
63-
:address temp/address
64-
:format :long}])
65-
:container-style {:margin-bottom 12}
66-
:on-press #(rf/dispatch [:show-bottom-sheet {:content about-options}])})]
67-
[quo/account-origin temp/account-origin-state]])
68-
69-
(def view (quo.theme/with-theme view-internal))
37+
(let [{:keys [type address]} (rf/sub [:wallet/current-viewing-account])
38+
networks (rf/sub [:wallet/network-details])
39+
watch-only? (= type :watch)]
40+
[rn/view {:style style/about-tab}
41+
[quo/data-item
42+
{:description :default
43+
:icon-right? true
44+
:right-icon :i/options
45+
:card? true
46+
:label :none
47+
:status :default
48+
:size :default
49+
:title (if watch-only? (i18n/label :t/watched-address) (i18n/label :t/address))
50+
:custom-subtitle (fn [] [quo/address-text
51+
{:networks networks
52+
:address address
53+
:format :long}])
54+
:container-style {:margin-bottom 12}
55+
:on-press #(rf/dispatch [:show-bottom-sheet {:content about-options}])}]
56+
(when (not watch-only?) [quo/account-origin temp/account-origin-state])]))

src/status_im2/contexts/wallet/account/view.cljs

+20-16
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,41 @@
2121
:padding-bottom 8}
2222
:render-fn quo/settings-item}]])
2323

24-
(def tabs-data
25-
[{:id :assets :label (i18n/label :t/assets) :accessibility-label :assets-tab}
26-
{:id :collectibles :label (i18n/label :t/collectibles) :accessibility-label :collectibles-tab}
27-
{:id :activity :label (i18n/label :t/activity) :accessibility-label :activity-tab}
28-
{:id :dapps :label (i18n/label :t/dapps) :accessibility-label :dapps}
29-
{:id :about :label (i18n/label :t/about) :accessibility-label :about}])
24+
(def first-tab-id :assets)
25+
26+
(defn tabs-data
27+
[watch-only?]
28+
(cond-> [{:id :assets :label (i18n/label :t/assets) :accessibility-label :assets-tab}
29+
{:id :collectibles :label (i18n/label :t/collectibles) :accessibility-label :collectibles-tab}
30+
{:id :activity :label (i18n/label :t/activity) :accessibility-label :activity-tab}]
31+
(not watch-only?) (conj {:id :dapps :label (i18n/label :t/dapps) :accessibility-label :dapps})
32+
true (conj {:id :about :label (i18n/label :t/about) :accessibility-label :about})))
3033

3134
(defn view
3235
[]
33-
(let [selected-tab (reagent/atom (:id (first tabs-data)))]
36+
(let [selected-tab (reagent/atom first-tab-id)]
3437
(fn []
35-
(let [{:keys [name color balance]} (rf/sub [:wallet/current-viewing-account])
36-
]
38+
(let [{:keys [name color balance type]} (rf/sub [:wallet/current-viewing-account])
39+
watch-only? (= type :watch)]
3740
[rn/view {:style {:flex 1}}
3841
[account-switcher/view {:on-press #(rf/dispatch [:wallet/close-account-page])}]
3942
[quo/account-overview
4043
{:current-value (utils/prettify-balance balance)
4144
:account-name name
42-
:account :default
45+
:account (if watch-only? :watched-address :default)
4346
:customization-color color}]
4447
[quo/wallet-graph {:time-frame :empty}]
45-
[quo/wallet-ctas
46-
{:send-action #(rf/dispatch [:open-modal :wallet-select-address])
47-
:buy-action #(rf/dispatch [:show-bottom-sheet
48-
{:content buy-drawer}])
49-
:bridge-action #(rf/dispatch [:open-modal :wallet-bridge])}]
48+
(when (not watch-only?)
49+
[quo/wallet-ctas
50+
{:send-action #(rf/dispatch [:open-modal :wallet-select-address])
51+
:buy-action #(rf/dispatch [:show-bottom-sheet
52+
{:content buy-drawer}])
53+
:bridge-action #(rf/dispatch [:open-modal :wallet-bridge])}])
5054
[quo/tabs
5155
{:style style/tabs
5256
:size 32
5357
:default-active @selected-tab
54-
:data tabs-data
58+
:data (tabs-data watch-only?)
5559
:on-change #(reset! selected-tab %)
5660
:scrollable? true
5761
:scroll-on-press? true}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(ns status-im2.contexts.wallet.add-address-to-watch.confirm-address.component-spec
2+
(:require
3+
[re-frame.core :as re-frame]
4+
[status-im2.contexts.wallet.add-address-to-watch.confirm-address.view :as confirm-address]
5+
[test-helpers.component :as h]
6+
[utils.re-frame :as rf]))
7+
8+
(defn setup-subs
9+
[subscriptions]
10+
(doseq [keyval subscriptions]
11+
(re-frame/reg-sub
12+
(key keyval)
13+
(fn [_] (val keyval)))))
14+
15+
(h/describe "Add Watch Only Account Page"
16+
(h/test "Create Account button is disabled while no account name exists"
17+
(let [callback (h/mock-fn)]
18+
(with-redefs [rf/dispatch #(callback)]
19+
(setup-subs {:profile/wallet-accounts []
20+
:get-screen-params {:address "0xmock-address"}})
21+
(h/render [confirm-address/view {}])
22+
(h/is-truthy (h/get-by-text "0xmock-address"))
23+
(h/was-not-called callback)
24+
(h/fire-event :change-text (h/get-by-label-text :profile-title-input) "NAME")
25+
(h/fire-event :press (h/get-by-translation-text :t/add-watched-address))
26+
(h/was-called callback)))))

src/status_im2/contexts/wallet/add_address_to_watch/confirm_address/view.cljs

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[clojure.string :as string]
44
[quo.core :as quo]
55
[quo.foundations.colors :as colors]
6-
[re-frame.core :as re-frame]
76
[react-native.core :as rn]
87
[reagent.core :as reagent]
98
[status-im2.contexts.emoji-picker.utils :as emoji-picker.utils]
@@ -43,8 +42,14 @@
4342
:bottom-action-label :t/add-watched-address
4443
:bottom-action-props {:customization-color @account-color
4544
:disabled? (string/blank? @account-name)
46-
:on-press #(re-frame/dispatch [:navigate-to
47-
:wallet-account])}}
45+
:on-press #(rf/dispatch [:wallet/add-account
46+
nil
47+
{:type :watch
48+
:account-name @account-name
49+
:emoji @account-emoji
50+
:color @account-color}
51+
{:address address
52+
:public-key ""}])}}
4853
[quo/data-item
4954
{:card? true
5055
:right-icon :i/advanced

src/status_im2/contexts/wallet/add_address_to_watch/style.cljs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
:margin-bottom 20})
77

88
(def scan
9-
{:align-self
10-
:flex-end})
9+
{:margin-top 26})
1110

1211
(def input
1312
{:flex 1

src/status_im2/contexts/wallet/events.cljs

+53-45
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,32 @@
1818

1919
(rf/reg-event-fx :wallet/show-account-created-toast
2020
(fn [{:keys [db]} [address]]
21-
(let [{:keys [name]} (get-in db [:wallet :accounts address])]
21+
(let [account (get-in db [:wallet :accounts address])]
2222
{:db (update db :wallet dissoc :navigate-to-account :new-account?)
2323
:fx [[:dispatch
2424
[:toasts/upsert
2525
{:id :new-wallet-account-created
2626
:icon :i/correct
2727
:icon-color colors/success-50
28-
:text (i18n/label :t/account-created {:name name})}]]]})))
28+
:text (i18n/label :t/account-created {:name (:name account)})}]]]})))
2929

3030
(rf/reg-event-fx :wallet/navigate-to-account
3131
(fn [{:keys [db]} [address]]
32-
(let [new-account? (get-in db [:wallet :new-account?])]
33-
(cond-> {:db (assoc-in db [:wallet :current-viewing-account-address] address)
34-
:fx [[:dispatch [:navigate-to :wallet-accounts address]]]}
32+
{:db (assoc-in db [:wallet :current-viewing-account-address] address)
33+
:fx [[:dispatch [:navigate-to :wallet-accounts address]]]}))
3534

36-
new-account?
37-
(update :fx conj [:dispatch [:wallet/show-account-created-toast address]])))))
35+
(rf/reg-event-fx :wallet/navigate-to-new-account
36+
(fn [{:keys [db]} [address]]
37+
{:db (assoc-in db [:wallet :current-viewing-account-address] address)
38+
:fx [[:dispatch [:hide-bottom-sheet]]
39+
[:dispatch-later
40+
[{:dispatch [:navigate-back]
41+
:ms 100}
42+
{:dispatch [:navigate-back]
43+
:ms 100}
44+
{:dispatch [:navigate-to :wallet-accounts address]
45+
:ms 300}]]
46+
[:dispatch [:wallet/show-account-created-toast address]]]}))
3847

3948
(rf/reg-event-fx :wallet/close-account-page
4049
(fn [{:keys [db]}]
@@ -44,24 +53,17 @@
4453
(rf/reg-event-fx
4554
:wallet/get-accounts-success
4655
(fn [{:keys [db]} [accounts]]
47-
(let [wallet-db (get db :wallet)
56+
(let [wallet-accounts (filter #(not (:chat %)) accounts)
57+
wallet-db (get db :wallet)
4858
new-account? (:new-account? wallet-db)
4959
navigate-to-account (:navigate-to-account wallet-db)]
50-
(cond-> {:db (reduce (fn [db {:keys [address] :as account}]
51-
(assoc-in db [:wallet :accounts address] account))
52-
db
53-
(data-store/rpc->accounts accounts))
54-
:fx [[:dispatch [:wallet/get-wallet-token]]]}
55-
56-
new-account?
57-
(update :fx
58-
conj
59-
[:dispatch [:hide-bottom-sheet]]
60-
[:dispatch-later
61-
[{:dispatch [:navigate-back]
62-
:ms 100}
63-
{:dispatch [:wallet/navigate-to-account navigate-to-account]
64-
:ms 300}]])))))
60+
{:db (reduce (fn [db {:keys [address] :as account}]
61+
(assoc-in db [:wallet :accounts address] account))
62+
db
63+
(data-store/rpc->accounts wallet-accounts))
64+
:fx [[:dispatch [:wallet/get-wallet-token]]
65+
(when new-account?
66+
[:dispatch [:wallet/navigate-to-new-account navigate-to-account]])]})))
6567

6668
(rf/reg-event-fx
6769
:wallet/get-accounts
@@ -144,29 +146,35 @@
144146
:on-success on-success
145147
:on-error #(log/info "failed to derive address " %)}]]]})))
146148

147-
(rf/reg-event-fx
148-
:wallet/add-account
149-
(fn [{:keys [db]} [password {:keys [emoji account-name color]} {:keys [public-key address path]}]]
150-
(let [key-uid (get-in db [:profile/profile :key-uid])
151-
sha3-pwd (native-module/sha3 (security/safe-unmask-data password))
152-
account-config {:key-uid key-uid
153-
:wallet false
154-
:chat false
155-
:type :generated
156-
:name account-name
157-
:emoji emoji
158-
:path path
159-
:address address
160-
:public-key public-key
161-
:colorID color}]
162-
{:db (update db
163-
:wallet assoc
164-
:navigate-to-account address
165-
:new-account? true)
166-
:fx [[:json-rpc/call
149+
(rf/reg-event-fx :wallet/add-account-success
150+
(fn [{:keys [db]} [address]]
151+
{:db (update db
152+
:wallet assoc
153+
:navigate-to-account address
154+
:new-account? true)
155+
:fx [[:dispatch [:wallet/get-accounts]]]}))
156+
157+
(rf/reg-event-fx :wallet/add-account
158+
(fn [{:keys [db]}
159+
[password {:keys [emoji account-name color type] :or {type :generated}}
160+
{:keys [public-key address path]}]]
161+
(let [lowercase-address (if address (string/lower-case address) address)
162+
key-uid (get-in db [:profile/profile :key-uid])
163+
sha3-pwd (native-module/sha3 (security/safe-unmask-data password))
164+
account-config {:key-uid (when (= type :generated) key-uid)
165+
:wallet false
166+
:chat false
167+
:type type
168+
:name account-name
169+
:emoji emoji
170+
:path path
171+
:address lowercase-address
172+
:public-key public-key
173+
:colorID color}]
174+
{:fx [[:json-rpc/call
167175
[{:method "accounts_addAccount"
168-
:params [sha3-pwd account-config]
169-
:on-success [:wallet/get-accounts]
176+
:params [(when (= type :generated) sha3-pwd) account-config]
177+
:on-success [:wallet/add-account-success lowercase-address]
170178
:on-error #(log/info "failed to create account " %)}]]]})))
171179

172180
(rf/reg-event-fx

src/status_im2/core_spec.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
[status-im2.contexts.chat.messages.content.audio.component-spec]
55
[status-im2.contexts.communities.actions.community-options.component-spec]
66
[status-im2.contexts.wallet.add-address-to-watch.component-spec]
7+
[status-im2.contexts.wallet.add-address-to-watch.confirm-address.component-spec]
78
[status-im2.contexts.wallet.create-account.edit-derivation-path.component-spec]
89
[status-im2.contexts.wallet.send.input-amount.component-spec]))

src/status_im2/subs/wallet/wallet.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
:<- [:wallet/balances]
4949
:<- [:wallet/tokens-loading?]
5050
(fn [[accounts balances tokens-loading?]]
51-
(mapv (fn [{:keys [color address] :as account}]
51+
(mapv (fn [{:keys [color address type] :as account}]
5252
(assoc account
5353
:customization-color color
54-
:type :empty
54+
:type (if (= type :watch) :watch-only :empty)
5555
:on-press #(rf/dispatch [:wallet/navigate-to-account address])
5656
:loading? tokens-loading?
5757
:balance (utils/prettify-balance (get balances address))))

0 commit comments

Comments
 (0)