Skip to content

Commit 8c82a84

Browse files
feat(wallet)_: Saved addresses limit (#22069)
This commit adds limit for adding saved addresses upto 20 to prevent any unwanted behaviour. Signed-off-by: Mohamed Javid <[email protected]>
1 parent 447945f commit 8c82a84

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

src/status_im/contexts/settings/wallet/saved_addresses/add_address_to_save/view.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@
144144
on-change-text (rn/use-callback
145145
(fn [new-value]
146146
(let [trimmed-value (string/trim new-value)]
147-
(set-error (validate (string/lower-case trimmed-value)))
148147
(set-address-or-ens trimmed-value)
149148
(set-ens-address "")
149+
(set-error (validate (string/lower-case trimmed-value)))
150150
(when (validation/ens-name? trimmed-value)
151151
(debounce/debounce-and-dispatch
152152
[:wallet/resolve-ens

src/status_im/contexts/settings/wallet/saved_addresses/events.cljs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,15 @@
154154
{:db (update-in db [:wallet :ui] dissoc :saved-address)})
155155

156156
(rf/reg-event-fx :wallet/clear-address-to-save clear-address-to-save)
157+
158+
(defn check-remaining-capacity-for-saved-addresses
159+
[{:keys [db]} [{:keys [on-success on-error]}]]
160+
(let [test-networks-enabled? (boolean (get-in db [:profile/profile :test-networks-enabled?]))]
161+
{:fx [[:json-rpc/call
162+
[{:method "wakuext_remainingCapacityForSavedAddresses"
163+
:params [test-networks-enabled?]
164+
:on-success on-success
165+
:on-error on-error}]]]}))
166+
167+
(rf/reg-event-fx :wallet/check-remaining-capacity-for-saved-addresses
168+
check-remaining-capacity-for-saved-addresses)

src/status_im/contexts/settings/wallet/saved_addresses/view.cljs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@
103103

104104
(defn- add-address-to-save
105105
[]
106-
(rf/dispatch [:open-modal :screen/settings.add-address-to-save]))
106+
(rf/dispatch [:wallet/check-remaining-capacity-for-saved-addresses
107+
{:on-success #(rf/dispatch [:open-modal :screen/settings.add-address-to-save])
108+
:on-error #(rf/dispatch [:toasts/upsert
109+
{:type :negative
110+
:theme :dark
111+
:text (i18n/label
112+
:t/saved-addresses-limit-reached-toast)}])}]))
107113

108114
(defn view
109115
[]

src/status_im/contexts/wallet/data_store.cljs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[clojure.string :as string]
66
[status-im.constants :as constants]
77
[status-im.contexts.wallet.collectible.utils :as collectible-utils]
8-
[status-im.contexts.wallet.common.utils.networks :as network-utils]
98
[status-im.contexts.wallet.send.utils :as send-utils]
109
[utils.collection :as utils.collection]
1110
[utils.money :as money]
@@ -165,10 +164,7 @@
165164

166165
(defn- add-keys-to-saved-address
167166
[saved-address]
168-
(-> saved-address
169-
(assoc :network-preferences-names
170-
(network-utils/network-preference-prefix->network-names (:chain-short-names saved-address)))
171-
(assoc :ens? (not (string/blank? (:ens saved-address))))))
167+
(assoc saved-address :ens? (not (string/blank? (:ens saved-address)))))
172168

173169
(defn rpc->saved-address
174170
[saved-address]

translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,7 @@
22792279
"saved-address-network-preference-selection-description": "Only change if you know which networks the address owner is happy to to receive funds on",
22802280
"saved-address-removed": "Saved address removed",
22812281
"saved-addresses": "Saved addresses",
2282+
"saved-addresses-limit-reached-toast": "Limit of 20 saved addresses reached. Remove a saved address to add a new one.",
22822283
"saving-keys-to-device": "Saving keys to device...",
22832284
"say-hi": "Say hi",
22842285
"scan-an-account-qr-code": "Scan an account QR code",

0 commit comments

Comments
 (0)