[#19544] Show preselected networks in QR code (#20070)

* Add subscription to get preferred networks given an address
* Fix preselected networks in receive screen
* Improve subscription
* Fix preselected networks in share screen
* Update test to include oeth
This commit is contained in:
Ulises Manuel 2024-05-21 10:08:14 -06:00 committed by GitHub
parent ed88170c5d
commit e1210e90c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 18 deletions

View File

@ -19,11 +19,12 @@
(h/before-each
(fn []
(h/setup-subs {:dimensions/window-width 500
:mediaserver/port 200
:wallet/accounts [{:address "0x707f635951193ddafbb40971a0fcaab8a6415160"
:name "Wallet One"
:emoji "😆"
:color :blue}]})))
:mediaserver/port 200
:wallet/accounts [{:address "0x707f635951193ddafbb40971a0fcaab8a6415160"
:name "Wallet One"
:emoji "😆"
:color :blue}]
:wallet/preferred-chain-names-for-address #{:eth :oeth :arb1}})))
(h/test "should display the wallet tab"
(render-wallet-view)

View File

@ -5,7 +5,6 @@
[react-native.core :as rn]
[react-native.platform :as platform]
[reagent.core :as reagent]
[status-im.constants :as constants]
[status-im.contexts.shell.share.style :as style]
[status-im.contexts.shell.share.wallet.style :as wallet-style]
[status-im.contexts.wallet.common.utils :as utils]
@ -51,9 +50,9 @@
chain-ids)))}])}]))
(defn- wallet-qr-code-item
[{:keys [account index]}]
[{:keys [account index preferred-chains]}]
(let [{window-width :width} (rn/get-window)
selected-networks (reagent/atom constants/default-network-names)
selected-networks (reagent/atom preferred-chains)
wallet-type (reagent/atom :multichain)
on-settings-press #(open-preferences selected-networks account)
on-legacy-press #(reset! wallet-type :legacy)
@ -97,10 +96,11 @@
^{:key i} [indicator (= current-index i)])])
(defn render-item
[item]
[{:keys [address] :as account}]
[wallet-qr-code-item
{:account item
:index (:position item)}])
{:account account
:index (:position account)
:preferred-chains (rf/sub [:wallet/preferred-chain-names-for-address address])}])
(defn- qr-code-visualized-index
[offset qr-code-size num-qr-codes]

View File

@ -47,13 +47,10 @@
:shell? true
:content sheet-content}])))
(defn view
[]
(let [padding-top (:top (safe-area/get-insets))
wallet-type (reagent/atom :legacy)
;; Design team is yet to confirm the default selected networks here. Should be the current
;; selected for the account or all the networks always
selected-networks (reagent/atom constants/default-network-names)
on-settings-press #(open-preferences selected-networks)
on-legacy-press #(reset! wallet-type :legacy)
@ -61,11 +58,11 @@
(fn []
(let [{:keys [address color emoji watch-only?]
:as account} (rf/sub [:wallet/current-viewing-account])
preferred-networks (rf/sub [:wallet/preferred-chain-names-for-address address])
share-title (str (:name account) " " (i18n/label :t/address))
qr-url (utils/get-wallet-qr {:wallet-type @wallet-type
:selected-networks
@selected-networks
:address address})
qr-url (utils/get-wallet-qr {:wallet-type @wallet-type
:selected-networks @selected-networks
:address address})
qr-media-server-uri (image-server/get-qr-image-uri-for-any-url
{:url qr-url
:port (rf/sub [:mediaserver/port])
@ -76,6 +73,9 @@
:share (i18n/label :t/share-address)
:receive (i18n/label :t/receive)
nil)]
(rn/use-mount #(reset! selected-networks preferred-networks))
[quo/overlay {:type :shell}
[rn/view
{:flex 1

View File

@ -408,6 +408,26 @@
(assoc account :customization-color color))
accounts)))
(rf/reg-sub
:wallet/preferred-chains-for-address
:<- [:wallet/accounts]
:<- [:wallet/network-details]
:<- [:profile/test-networks-enabled?]
(fn [[accounts network-details test-networks-enabled?] [_ address]]
(let [preferred-chains-ids (some #(when (= (:address %) address)
(if test-networks-enabled?
(:test-preferred-chain-ids %)
(:prod-preferred-chain-ids %)))
accounts)]
(filter #(preferred-chains-ids (:chain-id %)) network-details))))
(rf/reg-sub
:wallet/preferred-chain-names-for-address
(fn [[_ address]]
(rf/subscribe [:wallet/preferred-chains-for-address address]))
(fn [preferred-chains-for-address _]
(map :network-name preferred-chains-for-address)))
(rf/reg-sub
:wallet/transactions
:<- [:wallet]