feat(wallet): Add network preferences selection for saved address (#20364)

This commit:
- adds a feature to add network preferences for saved addresses while saving
- updates the network preferences in "Share save address" to show the address and color of the saved address
- fixes the screen qualifier for the settings screen when navigating to wallet settings

Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2024-06-06 23:01:12 +05:30 committed by GitHub
parent f1310c7e6c
commit 75c8437cc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 116 additions and 64 deletions

View File

@ -35,7 +35,7 @@
:blur? true
:action :arrow}
{:title (i18n/label :t/wallet)
:on-press #(rf/dispatch [:navigate-to-within-stack [:screen/settings.wallet :screen/settings]])
:on-press #(rf/dispatch [:navigate-to-within-stack [:screen/settings.wallet :settings]])
:image-props :i/wallet
:image :icon
:blur? true

View File

@ -56,9 +56,7 @@
:mixedcase-address "0x2"
:chain-short-names "eth:arb1:oeth:"
:has-ens? false
:network-preferences-names #{:arbitrum
:optimism
:mainnet}
:network-preferences-names `(:mainnet :arbitrum :optimism)
:name "Bob"
:created-at 1716826714
:ens ""
@ -76,9 +74,7 @@
:address "0x2"
:mixedcase-address "0x2"
:chain-short-names "eth:arb1:oeth:"
:network-preferences-names #{:arbitrum
:optimism
:mainnet}
:network-preferences-names `(:mainnet :arbitrum :optimism)
:has-ens? false
:name "Bob"
:created-at 1716826714
@ -89,9 +85,7 @@
:address "0x1"
:mixedcase-address "0x1"
:chain-short-names "eth:arb1:oeth:"
:network-preferences-names #{:arbitrum
:optimism
:mainnet}
:network-preferences-names `(:mainnet :arbitrum :optimism)
:has-ens? false
:name "Amy"
:created-at 1716826806

View File

@ -7,9 +7,10 @@
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.not-implemented :as not-implemented]
[status-im.constants :as constants]
[status-im.contexts.settings.wallet.saved-addresses.save-address.style :as style]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
@ -17,29 +18,61 @@
[]
(rf/dispatch [:navigate-back]))
(defn- extract-address
[address]
(re-find constants/regx-address-contains address))
(defn- network-preferences-sheet
[{:keys [address color selected-networks set-selected-networks]}]
(fn []
[network-preferences/view
{:title (i18n/label :t/add-network-preferences)
:description (i18n/label :t/saved-address-network-preference-selection-description)
:button-label (i18n/label :t/add-preferences)
:blur? true
:selected-networks (set selected-networks)
:account {:address address
:color color}
:on-save (fn [chain-ids]
(set-selected-networks (map network-utils/id->network chain-ids))
(rf/dispatch [:hide-bottom-sheet]))}]))
(defn view
[]
(let [{:keys [address]} (rf/sub [:wallet/saved-address])
(let [{:keys [address]} (rf/sub [:wallet/saved-address])
[network-prefixes address-without-prefix] (utils/split-prefix-and-address address)
[address-label set-address-label] (rn/use-state "")
[address-color set-address-color] (rn/use-state (rand-nth colors/account-colors))
placeholder (i18n/label :t/address-name)
on-press-save (rn/use-callback
(fn []
(let [address-without-prefix (extract-address address)]
(rf/dispatch [:wallet/save-address
{:on-success
[:wallet/add-saved-address-success
(i18n/label :t/address-saved)]
:on-error
[:wallet/add-saved-address-failed]
:name address-label
:address address-without-prefix
:customization-color address-color}])))
[address address-label address-color])]
[selected-networks set-selected-networks]
(rn/use-state (network-utils/network-preference-prefix->network-names network-prefixes))
chain-short-names (rn/use-memo
#(network-utils/network-names->network-preference-prefix
selected-networks)
[selected-networks])
placeholder (i18n/label :t/address-name)
open-network-preferences (rn/use-callback
(fn []
(rf/dispatch
[:show-bottom-sheet
{:theme :dark
:shell? true
:content (network-preferences-sheet
{:address address-without-prefix
:color address-color
:selected-networks selected-networks
:set-selected-networks
set-selected-networks})}]))
[address selected-networks address-color])
on-press-save (rn/use-callback
(fn []
(rf/dispatch [:wallet/save-address
{:on-success
[:wallet/add-saved-address-success
(i18n/label :t/address-saved)]
:on-error
[:wallet/add-saved-address-failed]
:name address-label
:address address-without-prefix
:customization-color address-color
:chain-short-names chain-short-names}]))
[address-without-prefix chain-short-names address-label
address-color])]
[quo/overlay {:type :shell}
[floating-button-page/view
{:footer-container-padding 0
@ -106,8 +139,8 @@
(fn []
[quo/address-text
{:full-address? true
:address address
:address (str chain-short-names address-without-prefix)
:format :long}])
[address])
:on-press not-implemented/alert
[selected-networks address])
:on-press open-network-preferences
:container-style style/data-item}]]]))

View File

@ -1,4 +1,4 @@
(ns status-im.contexts.settings.wallet.saved-addresses.sheets.share-address.style)
(ns status-im.contexts.settings.wallet.saved-addresses.share-address.style)
(def screen-container
{:flex 1})

View File

@ -1,9 +1,9 @@
(ns status-im.contexts.settings.wallet.saved-addresses.sheets.share-address.view
(ns status-im.contexts.settings.wallet.saved-addresses.share-address.view
(:require
[quo.core :as quo]
[react-native.core :as rn]
[react-native.platform :as platform]
[status-im.contexts.settings.wallet.saved-addresses.sheets.share-address.style :as style]
[status-im.contexts.settings.wallet.saved-addresses.share-address.style :as style]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
@ -33,16 +33,20 @@
:isNewTask true})}]))
(defn- open-preferences
[selected-networks set-selected-networks]
[{:keys [address color selected-networks set-selected-networks]}]
(let [on-save (fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(set-selected-networks (map network-utils/id->network chain-ids)))
sheet-content (fn []
[network-preferences/view
{:blur? true
{:description (i18n/label
:t/saved-address-network-preference-selection-description)
:button-label (i18n/label :t/display)
:blur? true
:selected-networks (set selected-networks)
:on-save on-save
:button-label (i18n/label :t/display)}])]
:account {:address address
:color color}
:on-save on-save}])]
(rf/dispatch [:show-bottom-sheet
{:theme :dark
:shell? true
@ -54,10 +58,13 @@
network-preferences-names]} (rf/sub [:get-screen-params])
[wallet-type set-wallet-type] (rn/use-state :legacy)
[selected-networks set-selected-networks] (rn/use-state network-preferences-names)
on-settings-press (rn/use-callback #(open-preferences
selected-networks
set-selected-networks)
[selected-networks])
on-settings-press (rn/use-callback
#(open-preferences
{:selected-networks selected-networks
:set-selected-networks set-selected-networks
:address address
:color customization-color})
[address customization-color selected-networks])
on-legacy-press (rn/use-callback #(set-wallet-type :legacy))
on-multichain-press (rn/use-callback #(set-wallet-type :multichain))
share-title (str name " " (i18n/label :t/address))

View File

@ -8,11 +8,11 @@
(defn open-saved-addresses-settings-modal
[]
(rf/dispatch [:navigate-to-within-stack [:screen/settings.saved-addresses :screen/settings]]))
(rf/dispatch [:navigate-to-within-stack [:screen/settings.saved-addresses :settings]]))
(defn open-keypairs-and-accounts-settings-modal
[]
(rf/dispatch [:navigate-to-within-stack [:screen/settings.keypairs-and-accounts :screen/settings]]))
(rf/dispatch [:navigate-to-within-stack [:screen/settings.keypairs-and-accounts :settings]]))
(defn basic-settings-options
[]
@ -38,7 +38,7 @@
(defn open-network-settings-modal
[]
(rf/dispatch [:navigate-to-within-stack [:screen/settings.network-settings :screen/settings]]))
(rf/dispatch [:navigate-to-within-stack [:screen/settings.network-settings :settings]]))
(defn advanced-settings-options
[]

View File

@ -114,7 +114,17 @@
[prefix]
(as-> prefix $
(string/split $ ":")
(map short-name->network $)))
(map short-name->network $)
(remove nil? $)))
(defn network-names->network-preference-prefix
[network-names]
(if (empty? network-names)
""
(->> network-names
(map network->short-name)
(remove nil?)
short-names->network-preference-prefix)))
(defn network-ids->formatted-text
[network-ids]

View File

@ -33,7 +33,18 @@
(= expected (utils/network-preference-prefix->network-names short-names))
(seq [:mainnet]) "eth"
(seq [:mainnet :optimism]) "eth:oeth"
(seq [:mainnet :optimism :arbitrum]) "eth:oeth:arb1"))
(seq [:mainnet :optimism :arbitrum]) "eth:oeth:arb1"
(seq [:mainnet :arbitrum]) "eth:sol:arb1"))
(deftest network-names->network-preference-prefix-test
(are [expected network-names]
(= expected (utils/network-names->network-preference-prefix network-names))
"eth:" [:mainnet]
"eth:oeth:" [:mainnet :optimism]
"eth:oeth:arb1:" [:mainnet :optimism :arbitrum]
"eth:arb1:" [:mainnet :polygon :arbitrum]
"" []
"" nil))
(deftest network-ids->formatted-text-test
(testing "Empty network-ids should return an empty string"

View File

@ -138,18 +138,11 @@
(let [renamed-data (sort-and-rename-keypairs keypairs)]
(cske/transform-keys csk/->kebab-case-keyword renamed-data)))
(defn- network-short-names->full-names
[short-names-string]
(->> (string/split short-names-string constants/chain-id-separator)
(map network-utils/short-name->network)
(remove nil?)
set))
(defn- add-keys-to-saved-address
[saved-address]
(-> saved-address
(assoc :network-preferences-names
(network-short-names->full-names (:chain-short-names saved-address)))
(network-utils/network-preference-prefix->network-names (:chain-short-names saved-address)))
(assoc :has-ens? (not (string/blank? (:ens saved-address))))))
(defn rpc->saved-address

View File

@ -12,7 +12,7 @@
[utils.re-frame :as rf]))
(defn view
[{:keys [title first-section-label second-section-label selected-networks
[{:keys [first-section-label second-section-label selected-networks
receiver-preferred-networks account watch-only?]}]
(let [state (reagent/atom :default)
{:keys [color address
@ -38,7 +38,7 @@
initial-network-preferences-names
@network-preferences-names-state))]
(fn [{:keys [on-save on-change blur? button-label first-section-warning-label
second-section-warning-label]}]
second-section-warning-label title description]}]
(let [theme (quo.theme/use-theme)
network-details (rf/sub [:wallet/network-details])
first-section-networks (filter (fn [network]
@ -71,9 +71,10 @@
[quo/drawer-top
{:title (or title (i18n/label :t/network-preferences))
:description (when-not receiver?
(if watch-only?
(i18n/label :t/network-preferences-desc-1)
(i18n/label :t/network-preferences-desc-2)))
(or description
(if watch-only?
(i18n/label :t/network-preferences-desc-1)
(i18n/label :t/network-preferences-desc-2))))
:blur? blur?}]
(when-not receiver?
[quo/data-item

View File

@ -68,7 +68,7 @@
[status-im.contexts.settings.wallet.saved-addresses.add-address-to-save.view :as
wallet-add-address-to-save]
[status-im.contexts.settings.wallet.saved-addresses.save-address.view :as wallet-save-address]
[status-im.contexts.settings.wallet.saved-addresses.sheets.share-address.view :as
[status-im.contexts.settings.wallet.saved-addresses.share-address.view :as
share-saved-address]
[status-im.contexts.settings.wallet.saved-addresses.view :as saved-addresses-settings]
[status-im.contexts.settings.wallet.wallet-options.view :as wallet-options]

View File

@ -2692,5 +2692,8 @@
"check-your-account-balance-and-activity": "Check your account balance and activity",
"request-txns-and-message-signing": "Request transactions and message signing",
"wallet-connect-qr-expired": "WalletConnect QR has expired",
"wallet-connect-version-not-supported": "WalletConnect version {{version}} is not supported"
"wallet-connect-version-not-supported": "WalletConnect version {{version}} is not supported",
"add-network-preferences": "Add network preferences",
"saved-address-network-preference-selection-description": "Only change if you know which networks the address owner is happy to to receive funds on",
"add-preferences": "Add preferences"
}