Skip to content

Commit

Permalink
🥅 Filter connected dapps based on testnet mode
Browse files Browse the repository at this point in the history
- Fixes #20794
  • Loading branch information
shivekkhurana committed Jul 18, 2024
1 parent 9f84a7b commit b8a2a49
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 37 deletions.
11 changes: 10 additions & 1 deletion src/status_im/contexts/wallet/common/account_switcher/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@
:right-side [(when (and (ff/enabled? ::ff/wallet.wallet-connect)
(not watch-only?))
{:icon-name :i/dapps
:on-press #(rf/dispatch [:navigate-to :screen/wallet.connected-dapps])})
:on-press #(do
;; Pairings from WC don't have chain info. But we need
;; to filter pairings in UI on the basis of testnet
;; mode. So we `fetch-persisted-sessions` and inject
;; chain info in pairings received from WC. That's why
;; we fetch it here, before redirecting to connected
;; dapps screen.
(rf/dispatch [:wallet-connect/fetch-persisted-sessions])
(rf/dispatch [:navigate-to
:screen/wallet.connected-dapps]))})

{:content-type :account-switcher
:customization-color color
Expand Down
23 changes: 12 additions & 11 deletions src/status_im/contexts/wallet/connected_dapps/view.cljs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
(ns status-im.contexts.wallet.connected-dapps.view
(:require
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.common.plus-button.view :as plus-button]
[status-im.common.resources :as resources]
[status-im.contexts.wallet.connected-dapps.disconnect-dapp.view :as disconnect-dapp]
[status-im.contexts.wallet.connected-dapps.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[status-im.common.plus-button.view :as plus-button]
[status-im.common.resources :as resources]
[status-im.contexts.wallet.connected-dapps.disconnect-dapp.view :as disconnect-dapp]
[status-im.contexts.wallet.connected-dapps.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn- on-disconnect
[wallet-account {:keys [name topic pairing-topic]}]
Expand Down Expand Up @@ -85,6 +85,7 @@
{:keys [color] :as wallet-account} (rf/sub [:wallet/current-viewing-account])
sessions (rf/sub
[:wallet-connect/sessions-for-current-account])
filtered-pairings (rf/sub [:wallet-connect/network-filtered-pairings])
theme (quo.theme/use-theme)]
[rn/view {:flex 1}
[header
Expand Down
51 changes: 26 additions & 25 deletions src/status_im/subs/root.cljs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
(ns status-im.subs.root
(:require
[re-frame.core :as re-frame]
status-im.subs.activity-center
status-im.subs.alert-banner
status-im.subs.biometrics
status-im.subs.chats
status-im.subs.communities
status-im.subs.community.account-selection
status-im.subs.contact
status-im.subs.general
status-im.subs.keycard
status-im.subs.messages
status-im.subs.onboarding
status-im.subs.pairing
status-im.subs.profile
status-im.subs.settings
status-im.subs.shell
status-im.subs.wallet.activities
status-im.subs.wallet.buy
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.swap
status-im.subs.wallet.wallet
status-im.subs.wallet.wallet-connect))
[re-frame.core :as re-frame]
status-im.subs.activity-center
status-im.subs.alert-banner
status-im.subs.biometrics
status-im.subs.chats
status-im.subs.communities
status-im.subs.community.account-selection
status-im.subs.contact
status-im.subs.general
status-im.subs.keycard
status-im.subs.messages
status-im.subs.onboarding
status-im.subs.pairing
status-im.subs.profile
status-im.subs.settings
status-im.subs.shell
status-im.subs.wallet.activities
status-im.subs.wallet.buy
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.swap
status-im.subs.wallet.wallet
status-im.subs.wallet.wallet-connect))

(defn reg-root-key-sub
[sub-name db-key]
Expand Down Expand Up @@ -170,6 +170,7 @@
(reg-root-key-sub :wallet-connect/current-proposal :wallet-connect/current-proposal)
(reg-root-key-sub :wallet-connect/current-request :wallet-connect/current-request)
(reg-root-key-sub :wallet-connect/sessions :wallet-connect/sessions)
(reg-root-key-sub :wallet-connect/pairings :wallet-connect/pairings)

;;biometrics
(reg-root-key-sub :biometrics :biometrics)
Expand Down
23 changes: 23 additions & 0 deletions src/status_im/subs/wallet/wallet_connect.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,26 @@
:wallet-connect/current-proposal-address
(fn [db]
(get-in db [:wallet-connect/current-proposal :address])))

;; Return pairings that are only related to the selected networks:
;; Testnet or Otherwise
(rf/reg-sub
:wallet-connect/network-filtered-pairings
:<- [:wallet-connect/pairings]
:<- [:profile/test-networks-enabled?]
:<- [:wallet-connect/persisted-sessions]
(fn [[pairings testnet-mode? persisted-sessions]]
(if persisted-sessions
(->> pairings
;; Map and inject testChains boolean
(map
(fn [pairing]
(let [persisted (some #(when (= (:pairingTopic %) (:topic pairing)) %)
persisted-sessions)]
(assoc pairing
:testChains
(:testChains persisted)))))
(filter
(fn [pairing]
(= (:testChains pairing) (boolean testnet-mode?)))))
pairings)))

0 comments on commit b8a2a49

Please sign in to comment.