Skip to content

Commit

Permalink
πŸ–‡οΈ Connect getSavedAddresses RPC to show or hide save address button (#…
Browse files Browse the repository at this point in the history
…19508)

* πŸ–‡οΈ Connect getSavedAddresses

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

* βš’οΈ Fix PR reviews

* πŸ—‘οΈ Remove code from wallet events ns
  • Loading branch information
shivekkhurana authored Apr 4, 2024
1 parent f0026b4 commit d0374d9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 37 deletions.
32 changes: 0 additions & 32 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[clojure.string :as string]
[react-native.background-timer :as background-timer]
[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.common.utils :as utils]
[status-im.contexts.wallet.data-store :as data-store]
Expand Down Expand Up @@ -444,34 +443,3 @@
:type :negative
:text (i18n/label :t/provider-is-down {:chains chain-names})
: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}]}))
45 changes: 45 additions & 0 deletions src/status_im/contexts/wallet/events/saved_addresses.cljs
Original file line number Diff line number Diff line change
@@ -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]}]}))
7 changes: 4 additions & 3 deletions src/status_im/contexts/wallet/send/save_address/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
[utils.re-frame :as rf]))

(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}
[quo/data-item
{:status :default
Expand Down Expand Up @@ -86,4 +87,4 @@
:on-change set-address-color
:container-style style/color-picker}]
[quo/divider-line {:container-style style/color-picker-bottom-divider}]
[address-view "0xshivek"]]))
[address-view]]))
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@

(defn- footer
[{: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
{: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-props {:type :grey
:icon-left :i/contact-book
Expand All @@ -47,6 +48,9 @@
(let [leave-page #(rf/dispatch [:wallet/close-transaction-progress-page])
{:keys [color]} (rf/sub [:wallet/current-viewing-account])]
(fn []
(rn/use-effect
(fn []
(rf/dispatch [:wallet/get-saved-addresses])))
(let [transaction-details (rf/sub [:wallet/send-transaction-progress])]
[floating-button-page/view
{:footer-container-padding 0
Expand Down
1 change: 1 addition & 0 deletions src/status_im/subs/root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
status-im.subs.shell
status-im.subs.wallet.collectibles
status-im.subs.wallet.networks
status-im.subs.wallet.saved-addresses
status-im.subs.wallet.send
status-im.subs.wallet.wallet))

Expand Down
15 changes: 15 additions & 0 deletions src/status_im/subs/wallet/saved_addresses.cljs
Original file line number Diff line number Diff line change
@@ -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))))

0 comments on commit d0374d9

Please sign in to comment.