[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 <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2023-12-01 00:28:09 +05:30 committed by GitHub
parent 210cf64ce0
commit b5202b4d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 103 additions and 18 deletions

View File

@ -11,6 +11,7 @@
(case k (case k
:success (colors/resolve-color :success theme) :success (colors/resolve-color :success theme)
:error (colors/resolve-color :danger theme) :error (colors/resolve-color :danger theme)
:warning (colors/resolve-color :warning theme)
(colors/theme-colors colors/neutral-50 colors/neutral-40 theme))) (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)))
(defn view-internal (defn view-internal

View File

@ -203,6 +203,16 @@
(def danger-50-opa-30 (alpha danger-50 0.3)) (def danger-50-opa-30 (alpha danger-50 0.3))
(def danger-50-opa-40 (alpha danger-50 0.4)) (def danger-50-opa-40 (alpha danger-50 0.4))
;;;;Warning
(def warning-50 "#FF7D46")
(def warning-60 "#CC6438")
;;50 with transparency
(def warning-50-opa-5 (alpha warning-50 0.05))
(def warning-50-opa-10 (alpha warning-50 0.1))
(def warning-50-opa-20 (alpha warning-50 0.2))
(def warning-50-opa-30 (alpha warning-50 0.3))
(def warning-50-opa-40 (alpha warning-50 0.4))
;; Colors for customizing users account ;; Colors for customizing users account
(def customization (def customization
@ -256,7 +266,9 @@
:danger {50 danger-50 :danger {50 danger-50
60 danger-60} 60 danger-60}
:success {50 success-50 :success {50 success-50
60 success-60}} 60 success-60}
:warning {50 warning-50
60 warning-60}}
customization customization
networks)) networks))

View File

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

View File

@ -27,11 +27,14 @@
(let [scanned-address (rf/sub [:wallet/scanned-address]) (let [scanned-address (rf/sub [:wallet/scanned-address])
empty-input? (and (string/blank? @input-value) empty-input? (and (string/blank? @input-value)
(string/blank? scanned-address)) (string/blank? scanned-address))
on-change-text (fn [new-text] on-change-text (fn [new-text]
(reset! validation-msg (validate new-text)) (reset! validation-msg (validate new-text))
(reset! input-value new-text) (reset! input-value new-text)
(if (and (not-empty new-text) (nil? (validate new-text)))
(rf/dispatch [:wallet/get-address-details new-text])
(rf/dispatch [:wallet/clear-address-activity-check]))
(when (and scanned-address (not= scanned-address new-text)) (when (and scanned-address (not= scanned-address new-text))
(rf/dispatch [:wallet/clear-address-activity-check])
(rf/dispatch [:wallet/clean-scanned-address]))) (rf/dispatch [:wallet/clean-scanned-address])))
paste-on-input #(clipboard/get-string paste-on-input #(clipboard/get-string
(fn [clipboard-text] (fn [clipboard-text]
@ -67,6 +70,32 @@
:icon-only? true} :icon-only? true}
:i/scan]])) :i/scan]]))
(defn activity-indicator
[]
(let [activity-state (rf/sub [:wallet/watch-address-activity-state])
{:keys [accessibility-label icon type message]}
(case activity-state
:has-activity {:accessibility-label :account-has-activity
:icon :i/done
:type :success
:message :t/this-address-has-activity}
:no-activity {:accessibility-label :account-has-no-activity
:icon :i/info
:type :warning
:message :t/this-address-has-no-activity}
{:accessibility-label :searching-for-activity
:icon :i/pending-state
:type :default
:message :t/searching-for-activity})]
(when activity-state
[quo/info-message
{:accessibility-label accessibility-label
:size :default
:icon icon
:type type
:style style/info-message}
(i18n/label message)])))
(defn view (defn view
[] []
(let [addresses (rf/sub [:wallet/addresses]) (let [addresses (rf/sub [:wallet/addresses])
@ -77,9 +106,11 @@
clear-input (fn [] clear-input (fn []
(reset! input-value nil) (reset! input-value nil)
(reset! validation-msg nil) (reset! validation-msg nil)
(rf/dispatch [:wallet/clear-address-activity-check])
(rf/dispatch [:wallet/clean-scanned-address])) (rf/dispatch [:wallet/clean-scanned-address]))
customization-color (rf/sub [:profile/customization-color])] customization-color (rf/sub [:profile/customization-color])]
(rf/dispatch [:wallet/clean-scanned-address]) (rf/dispatch [:wallet/clean-scanned-address])
(rf/dispatch [:wallet/clear-address-activity-check])
(fn [] (fn []
[rn/view [rn/view
{:style {:flex 1}} {:style {:flex 1}}
@ -89,11 +120,12 @@
:icon-name :i/close :icon-name :i/close
:on-press (fn [] :on-press (fn []
(rf/dispatch [:wallet/clean-scanned-address]) (rf/dispatch [:wallet/clean-scanned-address])
(rf/dispatch [:wallet/clear-address-activity-check])
(rf/dispatch [:navigate-back]))}] (rf/dispatch [:navigate-back]))}]
:footer :footer
[quo/button [quo/button
{:customization-color customization-color {:customization-color customization-color
:disabled? (string/blank? @input-value) :disabled? (or (string/blank? @input-value) (some? (validate @input-value)))
:on-press #(rf/dispatch [:navigate-to :on-press #(rf/dispatch [:navigate-to
:confirm-address-to-watch :confirm-address-to-watch
{:address @input-value}]) {:address @input-value}])
@ -115,4 +147,5 @@
:icon :i/info :icon :i/info
:type :error :type :error
:style style/info-message} :style style/info-message}
@validation-msg])]]))) @validation-msg])
[activity-indicator]]])))

View File

@ -355,3 +355,24 @@
(rf/reg-event-fx :wallet/select-send-address (rf/reg-event-fx :wallet/select-send-address
(fn [{:keys [db]} [address]] (fn [{:keys [db]} [address]]
{:db (assoc db :wallet/send-address address)})) {:db (assoc db :wallet/send-address address)}))
(rf/reg-event-fx :wallet/get-address-details-success
(fn [{:keys [db]} [{:keys [hasActivity]}]]
{:db (assoc-in db
[:wallet :ui :watch-address-activity-state]
(if hasActivity :has-activity :no-activity))}))
(rf/reg-event-fx :wallet/clear-address-activity-check
(fn [{:keys [db]}]
{:db (update-in db [:wallet :ui] dissoc :watch-address-activity-state)}))
(rf/reg-event-fx :wallet/get-address-details
(fn [{:keys [db]} [address]]
{:db (assoc-in db [:wallet :ui :watch-address-activity-state] :scanning)
:fx [[:json-rpc/call
[{:method "wallet_getAddressDetails"
:params [(chain/chain-id db) address]
:on-success [:wallet/get-address-details-success]
:on-error #(log/info "failed to get address details"
{:error %
:event :wallet/get-address-details})}]]]}))

View File

@ -270,8 +270,7 @@
:component wallet-edit-account/view} :component wallet-edit-account/view}
{:name :add-address-to-watch {:name :add-address-to-watch
:options {:insets {:top? true :options {:insets {:top? true}}
:bottom? true}}
:component add-address-to-watch/view} :component add-address-to-watch/view}
{:name :confirm-address-to-watch {:name :confirm-address-to-watch

View File

@ -14,6 +14,11 @@
:<- [:wallet/ui] :<- [:wallet/ui]
:-> :tokens-loading?) :-> :tokens-loading?)
(rf/reg-sub
:wallet/watch-address-activity-state
:<- [:wallet/ui]
:-> :watch-address-activity-state)
(rf/reg-sub (rf/reg-sub
:wallet/accounts :wallet/accounts
:<- [:wallet] :<- [:wallet]

View File

@ -181,3 +181,15 @@
(= (set ["0x1" "0x2"]) (= (set ["0x1" "0x2"])
(rf/sub [sub-name]))))) (rf/sub [sub-name])))))
(h/deftest-sub :wallet/watch-address-activity-state
[sub-name]
(testing "watch address activity state with nil value"
(is (= nil (rf/sub [sub-name]))))
(testing "watch address activity state with no-activity value"
(swap! rf-db/app-db #(assoc-in % [:wallet :ui :watch-address-activity-state] :no-activity))
(is (= :no-activity (rf/sub [sub-name]))))
(testing "watch address activity state with has-activity value"
(swap! rf-db/app-db #(assoc-in % [:wallet :ui :watch-address-activity-state] :has-activity))
(is (= :has-activity (rf/sub [sub-name])))))

View File

@ -2395,6 +2395,8 @@
"address-copied": "Address copied", "address-copied": "Address copied",
"no-dapps-description": "We want dApps!", "no-dapps-description": "We want dApps!",
"select-asset": "Select asset", "select-asset": "Select asset",
"send-limit": "Max: {{limit}}" "send-limit": "Max: {{limit}}",
"searching-for-activity": "Searching for activity...",
"this-address-has-no-activity": "This address has no activity",
"this-address-has-activity": "This address has activity"
} }