diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 44d687d7a8..379f8d17ff 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -291,6 +291,7 @@ (def ^:const wallet-connect-session-delete-event "session_delete") (def ^:const wallet-connect-user-rejected-error-key "USER_REJECTED") (def ^:const wallet-connect-user-disconnected-reason-key "USER_DISCONNECTED") +(def ^:const wallet-connect-user-rejected-chains-error-key "USER_REJECTED_CHAINS") (def ^:const transaction-pending-type-wallet-connect-transfer "WalletConnectTransfer") diff --git a/src/status_im/contexts/wallet/common/account_switcher/view.cljs b/src/status_im/contexts/wallet/common/account_switcher/view.cljs index 17ab23c194..bf7f1decab 100644 --- a/src/status_im/contexts/wallet/common/account_switcher/view.cljs +++ b/src/status_im/contexts/wallet/common/account_switcher/view.cljs @@ -41,7 +41,6 @@ (not watch-only?)) {:icon-name :i/dapps :on-press #(rf/dispatch [:navigate-to :screen/wallet.connected-dapps])}) - {:content-type :account-switcher :customization-color color :on-press #(on-dapps-press switcher-type) diff --git a/src/status_im/contexts/wallet/connected_dapps/view.cljs b/src/status_im/contexts/wallet/connected_dapps/view.cljs index 69d24e44bb..307b9df419 100644 --- a/src/status_im/contexts/wallet/connected_dapps/view.cljs +++ b/src/status_im/contexts/wallet/connected_dapps/view.cljs @@ -84,10 +84,10 @@ [] (let [{:keys [bottom]} (safe-area/get-insets) {:keys [color] :as wallet-account} (rf/sub [:wallet/current-viewing-account]) + customization-color (rf/sub [:profile/customization-color]) sessions (rf/sub - [:wallet-connect/sessions-for-current-account]) - theme (quo.theme/use-theme) - customization-color (rf/sub [:profile/customization-color])] + [:wallet-connect/sessions-for-current-account-and-networks]) + theme (quo.theme/use-theme)] [rn/view {:flex 1} [header {:title (i18n/label :t/connected-dapps) diff --git a/src/status_im/contexts/wallet/wallet_connect/core.cljs b/src/status_im/contexts/wallet/wallet_connect/core.cljs index 00c568b603..6bdc5d05af 100644 --- a/src/status_im/contexts/wallet/wallet_connect/core.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/core.cljs @@ -134,6 +134,7 @@ :iconUrl (get-in session [:peer :metadata :icons 0]) :url (get-in session [:peer :metadata :url]) :accounts (get-in session [:namespaces :eip155 :accounts]) + :chains (get-in session [:namespaces :eip155 :chains]) :disconnected false}) (defn filter-operable-accounts diff --git a/src/status_im/contexts/wallet/wallet_connect/events.cljs b/src/status_im/contexts/wallet/wallet_connect/events.cljs index a6dc8cfca5..954a96c433 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events.cljs @@ -79,7 +79,6 @@ (if (and (not-empty session-networks) required-networks-supported?) {:db (update db :wallet-connect/current-proposal assoc - :response-sent? false :request proposal :session-networks session-networks :address (or current-viewing-address @@ -89,23 +88,30 @@ :fx [[:dispatch [:open-modal :screen/wallet.wallet-connect-session-proposal]]]} {:fx [[:dispatch - [:wallet-connect/session-networks-unsupported proposal]]]})))) + [:wallet-connect/show-session-networks-unsupported-toast proposal]] + [:dispatch + [:wallet-connect/reject-session-proposal proposal]]]})))) (rf/reg-event-fx - :wallet-connect/session-networks-unsupported + :wallet-connect/show-session-networks-unsupported-toast (fn [{:keys [db]} [proposal]] - (let [{:keys [name]} (wallet-connect-core/get-session-dapp-metadata proposal)] + (let [{:keys [name url]} (wallet-connect-core/get-session-dapp-metadata proposal)] {:fx [[:dispatch [:toasts/upsert {:type :negative :theme (:theme db) - :text (i18n/label :t/wallet-connect-networks-not-supported {:dapp name})}]]]}))) + :text (i18n/label :t/wallet-connect-networks-not-supported + {:dapp (wallet-connect-core/compute-dapp-name name url)})}]]]}))) (rf/reg-event-fx :wallet-connect/on-session-request (fn [{:keys [db]} [event]] - (when (wallet-connect-core/event-should-be-handled? db event) - {:fx [[:dispatch [:wallet-connect/process-session-request event]]]}))) + (if (wallet-connect-core/event-should-be-handled? db event) + {:fx [[:dispatch [:wallet-connect/process-session-request event]]]} + {:fx [[:dispatch + [:wallet-connect/send-response + {:error (wallet-connect/get-sdk-error + constants/wallet-connect-user-rejected-chains-error-key)}]]]}))) (rf/reg-event-fx :wallet-connect/on-session-delete diff --git a/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs b/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs index a615a97a68..a74dcaafd9 100644 --- a/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs @@ -146,10 +146,25 @@ [:dispatch [:wallet-connect/dismiss-request-modal]]]})) (rf/reg-event-fx - :wallet-connect/reject-session-proposal + :wallet-connect/dismiss-request-modal (fn [{:keys [db]} _] + (let [screen (-> db + (get-in [:wallet-connect/current-request :event]) + wallet-connect-core/get-request-method + wallet-connect-core/method-to-screen)] + {:fx [[:dispatch [:dismiss-modal screen]]]}))) + +(rf/reg-event-fx + :wallet-connect/finish-session-request + (fn [_ [result]] + {:fx [[:dispatch [:wallet-connect/send-response {:result result}]] + [:dispatch [:wallet-connect/dismiss-request-modal]]]})) + +(rf/reg-event-fx + :wallet-connect/reject-session-proposal + (fn [{:keys [db]} [proposal]] (let [web3-wallet (get db :wallet-connect/web3-wallet) - {:keys [request response-sent?]} (:wallet-connect/current-proposal db)] + {:keys [request response-sent?]} (or proposal (:wallet-connect/current-proposal db))] {:fx [(when-not response-sent? [:effects.wallet-connect/reject-session-proposal {:web3-wallet web3-wallet diff --git a/src/status_im/subs/wallet/wallet_connect.cljs b/src/status_im/subs/wallet/wallet_connect.cljs index ea1eaf96ac..34abd3e866 100644 --- a/src/status_im/subs/wallet/wallet_connect.cljs +++ b/src/status_im/subs/wallet/wallet_connect.cljs @@ -1,6 +1,8 @@ (ns status-im.subs.wallet.wallet-connect - (:require [clojure.string :as string] + (:require [clojure.set :as set] + [clojure.string :as string] [re-frame.core :as rf] + [status-im.constants :as constants] [status-im.contexts.wallet.common.utils :as wallet-utils] [status-im.contexts.wallet.wallet-connect.core :as wallet-connect-core] [status-im.contexts.wallet.wallet-connect.transactions :as transactions] @@ -58,6 +60,24 @@ (some #(string/includes? % address) accounts)) sessions))) +(rf/reg-sub + :wallet-connect/sessions-for-current-account-and-networks + :<- [:wallet-connect/sessions-for-current-account] + :<- [:profile/test-networks-enabled?] + (fn [[sessions testnet-mode?]] + (filter + (fn [{:keys [chains]}] + (let [chain-ids (set (map (fn [chain] + (-> chain + (string/split ":") + second + js/parseInt)) + chains))] + (if testnet-mode? + (set/subset? chain-ids (set/union constants/sepolia-chain-ids constants/goerli-chain-ids)) + (set/subset? chain-ids constants/mainnet-chain-ids)))) + sessions))) + (rf/reg-sub :wallet-connect/chain-id :<- [:wallet-connect/current-request]