🖇️ Connect getSavedAddresses RPC to show or hide save address button (#19508)

* 🖇️ Connect getSavedAddresses

- The save button will not show if the address is already saved

* ⚒️ Fix PR reviews

* 🗑️ Remove code from wallet events ns
This commit is contained in:
Shivek Khurana 2024-04-04 13:51:29 +01:00 committed by GitHub
parent f0026b4d10
commit d0374d9fd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 71 additions and 37 deletions

View File

@ -3,7 +3,6 @@
[clojure.string :as string] [clojure.string :as string]
[react-native.background-timer :as background-timer] [react-native.background-timer :as background-timer]
[react-native.platform :as platform] [react-native.platform :as platform]
[status-im.constants :as constants]
[status-im.contexts.wallet.accounts.add-account.address-to-watch.events] [status-im.contexts.wallet.accounts.add-account.address-to-watch.events]
[status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.data-store :as data-store] [status-im.contexts.wallet.data-store :as data-store]
@ -444,34 +443,3 @@
:type :negative :type :negative
:text (i18n/label :t/provider-is-down {:chains chain-names}) :text (i18n/label :t/provider-is-down {:chains chain-names})
:duration 10000}]]])}))) :duration 10000}]]])})))
(rf/reg-event-fx
:wallet/save-address
(fn [_
[{:keys [address name customization-color on-success on-error chain-short-names ens test?]
:or {on-success (fn [])
on-error (fn [])
name ""
ens ""
test? false
;; the chain short names should be a string like eth: or eth:arb:opt:
chain-short-names (str constants/mainnet-short-name ":")}}]]
(let [address-to-save {:address address
:name name
:color-id customization-color
:ens ens
:is-test test?
:chain-short-names chain-short-names}]
{:json-rpc/call
[{:method "wakuext_upsertSavedAddress"
:params [address-to-save]
:on-success on-success
:on-error on-error}]})))
(rf/reg-event-fx
:wallet/get-saved-addresses
(fn [_ [{:keys [on-success on-error]}]]
{:json-rpc/call
[{:method "wakuext_getSavedAddresses"
:on-success on-success
:on-error on-error}]}))

View File

@ -0,0 +1,45 @@
(ns status-im.contexts.wallet.events.saved-addresses
(:require
[status-im.constants :as constants]
[utils.re-frame :as rf]))
(rf/reg-event-fx
:wallet/save-address
(fn [_
[{:keys [address name customization-color on-success on-error chain-short-names ens test?]
:or {on-success (fn [])
on-error (fn [])
name ""
ens ""
test? false
;; the chain short names should be a string like eth: or eth:arb:opt:
chain-short-names (str constants/mainnet-short-name ":")}}]]
(let [address-to-save {:address address
:name name
:color-id customization-color
:ens ens
:is-test test?
:chain-short-names chain-short-names}]
{:json-rpc/call
[{:method "wakuext_upsertSavedAddress"
:params [address-to-save]
:on-success on-success
:on-error on-error}]})))
(rf/reg-event-fx
:wallet/get-saved-addresses-success
(fn [{:keys [db]} [saved-addresses]]
{:db (assoc-in db [:wallet :saved-addresses] saved-addresses)}))
(rf/reg-event-fx
:wallet/get-saved-addresses-error
(fn [{:keys [db]} [err]]
{:db (assoc db [:wallet :get-saved-addresses-error] err)}))
(rf/reg-event-fx
:wallet/get-saved-addresses
(fn [_ _]
{:json-rpc/call
[{:method "wakuext_getSavedAddresses"
:on-success [:wallet/get-saved-addresses-success]
:on-error [:wallet/get-saved-addresses-error]}]}))

View File

@ -12,8 +12,9 @@
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn- address-view (defn- address-view
[address] []
(let [network-details (rf/sub [:wallet/network-preference-details])] (let [network-details (rf/sub [:wallet/network-preference-details])
address (rf/sub [:wallet/wallet-send-to-address])]
[rn/view {:style style/address-container} [rn/view {:style style/address-container}
[quo/data-item [quo/data-item
{:status :default {:status :default
@ -86,4 +87,4 @@
:on-change set-address-color :on-change set-address-color
:container-style style/color-picker}] :container-style style/color-picker}]
[quo/divider-line {:container-style style/color-picker-bottom-divider}] [quo/divider-line {:container-style style/color-picker-bottom-divider}]
[address-view "0xshivek"]])) [address-view]]))

View File

@ -27,9 +27,10 @@
(defn- footer (defn- footer
[{:keys [color leave-page]}] [{:keys [color leave-page]}]
(let [save-address-visible? false] (let [send-to-address (rf/sub [:wallet/wallet-send-to-address])
save-address-hidden? (rf/sub [:wallet/address-saved? send-to-address])]
[quo/bottom-actions [quo/bottom-actions
{:actions (if save-address-visible? :two-actions :one-action) {:actions (if save-address-hidden? :one-action :two-actions)
:button-two-label (i18n/label :t/save-address) :button-two-label (i18n/label :t/save-address)
:button-two-props {:type :grey :button-two-props {:type :grey
:icon-left :i/contact-book :icon-left :i/contact-book
@ -47,6 +48,9 @@
(let [leave-page #(rf/dispatch [:wallet/close-transaction-progress-page]) (let [leave-page #(rf/dispatch [:wallet/close-transaction-progress-page])
{:keys [color]} (rf/sub [:wallet/current-viewing-account])] {:keys [color]} (rf/sub [:wallet/current-viewing-account])]
(fn [] (fn []
(rn/use-effect
(fn []
(rf/dispatch [:wallet/get-saved-addresses])))
(let [transaction-details (rf/sub [:wallet/send-transaction-progress])] (let [transaction-details (rf/sub [:wallet/send-transaction-progress])]
[floating-button-page/view [floating-button-page/view
{:footer-container-padding 0 {:footer-container-padding 0

View File

@ -16,6 +16,7 @@
status-im.subs.shell status-im.subs.shell
status-im.subs.wallet.collectibles status-im.subs.wallet.collectibles
status-im.subs.wallet.networks status-im.subs.wallet.networks
status-im.subs.wallet.saved-addresses
status-im.subs.wallet.send status-im.subs.wallet.send
status-im.subs.wallet.wallet)) status-im.subs.wallet.wallet))

View File

@ -0,0 +1,15 @@
(ns status-im.subs.wallet.saved-addresses
(:require
[re-frame.core :as rf]))
(rf/reg-sub
:wallet/saved-addresses
:<- [:wallet]
:-> :saved-addresses)
(rf/reg-sub
:wallet/address-saved?
:<- [:wallet]
(fn [wallet [address]]
(some #(= address (:address %))
(:saved-addresses wallet))))