diff --git a/src/quo/components/info/info_message.cljs b/src/quo/components/info/info_message.cljs index 84fe2e9f44c..7609e49e4f0 100644 --- a/src/quo/components/info/info_message.cljs +++ b/src/quo/components/info/info_message.cljs @@ -11,6 +11,7 @@ (case k :success (colors/resolve-color :success theme) :error (colors/resolve-color :danger theme) + :warning (colors/resolve-color :warning theme) (colors/theme-colors colors/neutral-50 colors/neutral-40 theme))) (defn view-internal diff --git a/src/quo/foundations/colors.cljs b/src/quo/foundations/colors.cljs index 1dd1348736e..e0146141f21 100644 --- a/src/quo/foundations/colors.cljs +++ b/src/quo/foundations/colors.cljs @@ -203,6 +203,16 @@ (def danger-50-opa-30 (alpha danger-50 0.3)) (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 (def customization @@ -256,7 +266,9 @@ :danger {50 danger-50 60 danger-60} :success {50 success-50 - 60 success-60}} + 60 success-60} + :warning {50 warning-50 + 60 warning-60}} customization networks)) diff --git a/src/status_im2/contexts/wallet/add_address_to_watch/component_spec.cljs b/src/status_im2/contexts/wallet/add_address_to_watch/component_spec.cljs index 0411bfc4e0f..4deddd38091 100644 --- a/src/status_im2/contexts/wallet/add_address_to_watch/component_spec.cljs +++ b/src/status_im2/contexts/wallet/add_address_to_watch/component_spec.cljs @@ -13,11 +13,11 @@ (h/describe "select address for watch only account" (h/test "validation messages show for already used addressed" - (setup-subs {:wallet/scanned-address nil - :wallet/addresses (set - ["0x12E838Ae1f769147b12956485dc56e57138f3AC8" - "0x22E838Ae1f769147b12956485dc56e57138f3AC8"]) - :profile/customization-color :blue}) + (setup-subs {:wallet/scanned-address nil + :wallet/addresses #{"0x12E838Ae1f769147b12956485dc56e57138f3AC8" + "0x22E838Ae1f769147b12956485dc56e57138f3AC8"} + :wallet/watch-address-activity-state nil + :profile/customization-color :blue}) (h/render [add-address-to-watch/view]) (h/is-falsy (h/query-by-label-text :error-message)) (h/fire-event :change-text @@ -26,11 +26,11 @@ (h/is-truthy (h/get-by-translation-text :address-already-in-use)))) (h/test "validation messages show for invalid address" - (setup-subs {:wallet/scanned-address nil - :wallet/addresses (set - ["0x12E838Ae1f769147b12956485dc56e57138f3AC8" - "0x22E838Ae1f769147b12956485dc56e57138f3AC8"]) - :profile/customization-color :blue}) + (setup-subs {:wallet/scanned-address nil + :wallet/addresses #{"0x12E838Ae1f769147b12956485dc56e57138f3AC8" + "0x22E838Ae1f769147b12956485dc56e57138f3AC8"} + :wallet/watch-address-activity-state nil + :profile/customization-color :blue}) (h/render [add-address-to-watch/view]) (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") diff --git a/src/status_im2/contexts/wallet/add_address_to_watch/view.cljs b/src/status_im2/contexts/wallet/add_address_to_watch/view.cljs index 44f7a924fdb..3f7359a9457 100644 --- a/src/status_im2/contexts/wallet/add_address_to_watch/view.cljs +++ b/src/status_im2/contexts/wallet/add_address_to_watch/view.cljs @@ -27,11 +27,14 @@ (let [scanned-address (rf/sub [:wallet/scanned-address]) empty-input? (and (string/blank? @input-value) (string/blank? scanned-address)) - on-change-text (fn [new-text] (reset! validation-msg (validate 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)) + (rf/dispatch [:wallet/clear-address-activity-check]) (rf/dispatch [:wallet/clean-scanned-address]))) paste-on-input #(clipboard/get-string (fn [clipboard-text] @@ -67,6 +70,32 @@ :icon-only? true} :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 [] (let [addresses (rf/sub [:wallet/addresses]) @@ -77,9 +106,11 @@ clear-input (fn [] (reset! input-value nil) (reset! validation-msg nil) + (rf/dispatch [:wallet/clear-address-activity-check]) (rf/dispatch [:wallet/clean-scanned-address])) customization-color (rf/sub [:profile/customization-color])] (rf/dispatch [:wallet/clean-scanned-address]) + (rf/dispatch [:wallet/clear-address-activity-check]) (fn [] [rn/view {:style {:flex 1}} @@ -89,11 +120,12 @@ :icon-name :i/close :on-press (fn [] (rf/dispatch [:wallet/clean-scanned-address]) + (rf/dispatch [:wallet/clear-address-activity-check]) (rf/dispatch [:navigate-back]))}] :footer [quo/button {: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 :confirm-address-to-watch {:address @input-value}]) @@ -115,4 +147,5 @@ :icon :i/info :type :error :style style/info-message} - @validation-msg])]]))) + @validation-msg]) + [activity-indicator]]]))) diff --git a/src/status_im2/contexts/wallet/events.cljs b/src/status_im2/contexts/wallet/events.cljs index 70c545b8563..64f932c9c2b 100644 --- a/src/status_im2/contexts/wallet/events.cljs +++ b/src/status_im2/contexts/wallet/events.cljs @@ -355,3 +355,24 @@ (rf/reg-event-fx :wallet/select-send-address (fn [{:keys [db]} [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})}]]]})) diff --git a/src/status_im2/navigation/screens.cljs b/src/status_im2/navigation/screens.cljs index 0dfc8591290..fa08f335405 100644 --- a/src/status_im2/navigation/screens.cljs +++ b/src/status_im2/navigation/screens.cljs @@ -270,8 +270,7 @@ :component wallet-edit-account/view} {:name :add-address-to-watch - :options {:insets {:top? true - :bottom? true}} + :options {:insets {:top? true}} :component add-address-to-watch/view} {:name :confirm-address-to-watch diff --git a/src/status_im2/subs/wallet/wallet.cljs b/src/status_im2/subs/wallet/wallet.cljs index 302fce349ce..a219d0ffed7 100644 --- a/src/status_im2/subs/wallet/wallet.cljs +++ b/src/status_im2/subs/wallet/wallet.cljs @@ -14,6 +14,11 @@ :<- [:wallet/ui] :-> :tokens-loading?) +(rf/reg-sub + :wallet/watch-address-activity-state + :<- [:wallet/ui] + :-> :watch-address-activity-state) + (rf/reg-sub :wallet/accounts :<- [:wallet] diff --git a/src/status_im2/subs/wallet/wallet_test.cljs b/src/status_im2/subs/wallet/wallet_test.cljs index 8b2b3da0a28..5f690f8b2a1 100644 --- a/src/status_im2/subs/wallet/wallet_test.cljs +++ b/src/status_im2/subs/wallet/wallet_test.cljs @@ -181,3 +181,15 @@ (= (set ["0x1" "0x2"]) (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]))))) diff --git a/translations/en.json b/translations/en.json index 8ade8f936dc..fd94787bf72 100644 --- a/translations/en.json +++ b/translations/en.json @@ -2395,6 +2395,8 @@ "address-copied": "Address copied", "no-dapps-description": "We want dApps!", "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" } -