Skip to content

Commit b5202b4

Browse files
[Feature] Added activity check on entered watch address (#17970)
This commit - implements the activity check for the entered watch address. - added warning colors - fixes bottom inset in add address to watch screen --------- Signed-off-by: Mohamed Javid <[email protected]>
1 parent 210cf64 commit b5202b4

File tree

9 files changed

+103
-18
lines changed

9 files changed

+103
-18
lines changed

Diff for: src/quo/components/info/info_message.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
(case k
1212
:success (colors/resolve-color :success theme)
1313
:error (colors/resolve-color :danger theme)
14+
:warning (colors/resolve-color :warning theme)
1415
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme)))
1516

1617
(defn view-internal

Diff for: src/quo/foundations/colors.cljs

+13-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@
203203
(def danger-50-opa-30 (alpha danger-50 0.3))
204204
(def danger-50-opa-40 (alpha danger-50 0.4))
205205

206+
;;;;Warning
207+
(def warning-50 "#FF7D46")
208+
(def warning-60 "#CC6438")
209+
210+
;;50 with transparency
211+
(def warning-50-opa-5 (alpha warning-50 0.05))
212+
(def warning-50-opa-10 (alpha warning-50 0.1))
213+
(def warning-50-opa-20 (alpha warning-50 0.2))
214+
(def warning-50-opa-30 (alpha warning-50 0.3))
215+
(def warning-50-opa-40 (alpha warning-50 0.4))
206216

207217
;; Colors for customizing users account
208218
(def customization
@@ -256,7 +266,9 @@
256266
:danger {50 danger-50
257267
60 danger-60}
258268
:success {50 success-50
259-
60 success-60}}
269+
60 success-60}
270+
:warning {50 warning-50
271+
60 warning-60}}
260272
customization
261273
networks))
262274

Diff for: src/status_im2/contexts/wallet/add_address_to_watch/component_spec.cljs

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
(h/describe "select address for watch only account"
1515
(h/test "validation messages show for already used addressed"
16-
(setup-subs {:wallet/scanned-address nil
17-
:wallet/addresses (set
18-
["0x12E838Ae1f769147b12956485dc56e57138f3AC8"
19-
"0x22E838Ae1f769147b12956485dc56e57138f3AC8"])
20-
:profile/customization-color :blue})
16+
(setup-subs {:wallet/scanned-address nil
17+
:wallet/addresses #{"0x12E838Ae1f769147b12956485dc56e57138f3AC8"
18+
"0x22E838Ae1f769147b12956485dc56e57138f3AC8"}
19+
:wallet/watch-address-activity-state nil
20+
:profile/customization-color :blue})
2121
(h/render [add-address-to-watch/view])
2222
(h/is-falsy (h/query-by-label-text :error-message))
2323
(h/fire-event :change-text
@@ -26,11 +26,11 @@
2626
(h/is-truthy (h/get-by-translation-text :address-already-in-use))))
2727

2828
(h/test "validation messages show for invalid address"
29-
(setup-subs {:wallet/scanned-address nil
30-
:wallet/addresses (set
31-
["0x12E838Ae1f769147b12956485dc56e57138f3AC8"
32-
"0x22E838Ae1f769147b12956485dc56e57138f3AC8"])
33-
:profile/customization-color :blue})
29+
(setup-subs {:wallet/scanned-address nil
30+
:wallet/addresses #{"0x12E838Ae1f769147b12956485dc56e57138f3AC8"
31+
"0x22E838Ae1f769147b12956485dc56e57138f3AC8"}
32+
:wallet/watch-address-activity-state nil
33+
:profile/customization-color :blue})
3434
(h/render [add-address-to-watch/view])
3535
(h/is-falsy (h/query-by-label-text :error-message))
3636
(h/fire-event :change-text (h/get-by-label-text :add-address-to-watch) "0x12E838Ae1f769147b")

Diff for: src/status_im2/contexts/wallet/add_address_to_watch/view.cljs

+36-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
(let [scanned-address (rf/sub [:wallet/scanned-address])
2828
empty-input? (and (string/blank? @input-value)
2929
(string/blank? scanned-address))
30-
3130
on-change-text (fn [new-text]
3231
(reset! validation-msg (validate new-text))
3332
(reset! input-value new-text)
33+
(if (and (not-empty new-text) (nil? (validate new-text)))
34+
(rf/dispatch [:wallet/get-address-details new-text])
35+
(rf/dispatch [:wallet/clear-address-activity-check]))
3436
(when (and scanned-address (not= scanned-address new-text))
37+
(rf/dispatch [:wallet/clear-address-activity-check])
3538
(rf/dispatch [:wallet/clean-scanned-address])))
3639
paste-on-input #(clipboard/get-string
3740
(fn [clipboard-text]
@@ -67,6 +70,32 @@
6770
:icon-only? true}
6871
:i/scan]]))
6972

73+
(defn activity-indicator
74+
[]
75+
(let [activity-state (rf/sub [:wallet/watch-address-activity-state])
76+
{:keys [accessibility-label icon type message]}
77+
(case activity-state
78+
:has-activity {:accessibility-label :account-has-activity
79+
:icon :i/done
80+
:type :success
81+
:message :t/this-address-has-activity}
82+
:no-activity {:accessibility-label :account-has-no-activity
83+
:icon :i/info
84+
:type :warning
85+
:message :t/this-address-has-no-activity}
86+
{:accessibility-label :searching-for-activity
87+
:icon :i/pending-state
88+
:type :default
89+
:message :t/searching-for-activity})]
90+
(when activity-state
91+
[quo/info-message
92+
{:accessibility-label accessibility-label
93+
:size :default
94+
:icon icon
95+
:type type
96+
:style style/info-message}
97+
(i18n/label message)])))
98+
7099
(defn view
71100
[]
72101
(let [addresses (rf/sub [:wallet/addresses])
@@ -77,9 +106,11 @@
77106
clear-input (fn []
78107
(reset! input-value nil)
79108
(reset! validation-msg nil)
109+
(rf/dispatch [:wallet/clear-address-activity-check])
80110
(rf/dispatch [:wallet/clean-scanned-address]))
81111
customization-color (rf/sub [:profile/customization-color])]
82112
(rf/dispatch [:wallet/clean-scanned-address])
113+
(rf/dispatch [:wallet/clear-address-activity-check])
83114
(fn []
84115
[rn/view
85116
{:style {:flex 1}}
@@ -89,11 +120,12 @@
89120
:icon-name :i/close
90121
:on-press (fn []
91122
(rf/dispatch [:wallet/clean-scanned-address])
123+
(rf/dispatch [:wallet/clear-address-activity-check])
92124
(rf/dispatch [:navigate-back]))}]
93125
:footer
94126
[quo/button
95127
{:customization-color customization-color
96-
:disabled? (string/blank? @input-value)
128+
:disabled? (or (string/blank? @input-value) (some? (validate @input-value)))
97129
:on-press #(rf/dispatch [:navigate-to
98130
:confirm-address-to-watch
99131
{:address @input-value}])
@@ -115,4 +147,5 @@
115147
:icon :i/info
116148
:type :error
117149
:style style/info-message}
118-
@validation-msg])]])))
150+
@validation-msg])
151+
[activity-indicator]]])))

Diff for: src/status_im2/contexts/wallet/events.cljs

+21
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,24 @@
355355
(rf/reg-event-fx :wallet/select-send-address
356356
(fn [{:keys [db]} [address]]
357357
{:db (assoc db :wallet/send-address address)}))
358+
359+
(rf/reg-event-fx :wallet/get-address-details-success
360+
(fn [{:keys [db]} [{:keys [hasActivity]}]]
361+
{:db (assoc-in db
362+
[:wallet :ui :watch-address-activity-state]
363+
(if hasActivity :has-activity :no-activity))}))
364+
365+
(rf/reg-event-fx :wallet/clear-address-activity-check
366+
(fn [{:keys [db]}]
367+
{:db (update-in db [:wallet :ui] dissoc :watch-address-activity-state)}))
368+
369+
(rf/reg-event-fx :wallet/get-address-details
370+
(fn [{:keys [db]} [address]]
371+
{:db (assoc-in db [:wallet :ui :watch-address-activity-state] :scanning)
372+
:fx [[:json-rpc/call
373+
[{:method "wallet_getAddressDetails"
374+
:params [(chain/chain-id db) address]
375+
:on-success [:wallet/get-address-details-success]
376+
:on-error #(log/info "failed to get address details"
377+
{:error %
378+
:event :wallet/get-address-details})}]]]}))

Diff for: src/status_im2/navigation/screens.cljs

+1-2
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@
270270
:component wallet-edit-account/view}
271271

272272
{:name :add-address-to-watch
273-
:options {:insets {:top? true
274-
:bottom? true}}
273+
:options {:insets {:top? true}}
275274
:component add-address-to-watch/view}
276275

277276
{:name :confirm-address-to-watch

Diff for: src/status_im2/subs/wallet/wallet.cljs

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
:<- [:wallet/ui]
1515
:-> :tokens-loading?)
1616

17+
(rf/reg-sub
18+
:wallet/watch-address-activity-state
19+
:<- [:wallet/ui]
20+
:-> :watch-address-activity-state)
21+
1722
(rf/reg-sub
1823
:wallet/accounts
1924
:<- [:wallet]

Diff for: src/status_im2/subs/wallet/wallet_test.cljs

+12
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,15 @@
181181
(= (set ["0x1" "0x2"])
182182
(rf/sub [sub-name])))))
183183

184+
(h/deftest-sub :wallet/watch-address-activity-state
185+
[sub-name]
186+
(testing "watch address activity state with nil value"
187+
(is (= nil (rf/sub [sub-name]))))
188+
189+
(testing "watch address activity state with no-activity value"
190+
(swap! rf-db/app-db #(assoc-in % [:wallet :ui :watch-address-activity-state] :no-activity))
191+
(is (= :no-activity (rf/sub [sub-name]))))
192+
193+
(testing "watch address activity state with has-activity value"
194+
(swap! rf-db/app-db #(assoc-in % [:wallet :ui :watch-address-activity-state] :has-activity))
195+
(is (= :has-activity (rf/sub [sub-name])))))

Diff for: translations/en.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,8 @@
23952395
"address-copied": "Address copied",
23962396
"no-dapps-description": "We want dApps!",
23972397
"select-asset": "Select asset",
2398-
"send-limit": "Max: {{limit}}"
2398+
"send-limit": "Max: {{limit}}",
2399+
"searching-for-activity": "Searching for activity...",
2400+
"this-address-has-no-activity": "This address has no activity",
2401+
"this-address-has-activity": "This address has activity"
23992402
}
2400-

0 commit comments

Comments
 (0)