diff --git a/.env b/.env index cd94c2d3ee..33618ea666 100644 --- a/.env +++ b/.env @@ -35,3 +35,4 @@ FAST_CREATE_COMMUNITY_ENABLED=1 TEST_NETWORKS_ENABLED=1 SHOW_NOT_IMPLEMENTED_FEATURES=0 ENABLE_ALERT_BANNER=0 +FLAG_WALLET_CONNECT_ENABLED=1 diff --git a/.env.e2e b/.env.e2e index 3cb33615b2..9ed1b68dff 100644 --- a/.env.e2e +++ b/.env.e2e @@ -38,4 +38,5 @@ SHOW_NOT_IMPLEMENTED_FEATURES=1 DELETE_MESSAGE_FOR_ME_UNDO_TIME_LIMIT=10000 DELETE_MESSAGE_UNDO_TIME_LIMIT=10000 ENABLE_ALERT_BANNER=0 +FLAG_WALLET_CONNECT_ENABLED=1 MOBILE_DATA_SYNCING_TOGGLE_ENABLE=0 diff --git a/.env.jenkins b/.env.jenkins index b7415f9948..33f1644366 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -36,3 +36,4 @@ LOCAL_PAIRING_ENABLED=1 FAST_CREATE_COMMUNITY_ENABLED=1 TEST_NETWORKS_ENABLED=1 ENABLE_ALERT_BANNER=1 +FLAG_WALLET_CONNECT_ENABLED=1 diff --git a/.env.nightly b/.env.nightly index 07aee35b91..82fac88963 100644 --- a/.env.nightly +++ b/.env.nightly @@ -23,3 +23,4 @@ DELETE_MESSAGE_ENABLED=1 FAST_CREATE_COMMUNITY_ENABLED=0 TEST_NETWORKS_ENABLED=0 ENABLE_ALERT_BANNER=1 +FLAG_WALLET_CONNECT_ENABLED=1 diff --git a/.env.release b/.env.release index 41b630e1b3..32210aa720 100644 --- a/.env.release +++ b/.env.release @@ -19,3 +19,4 @@ MAX_IMAGES_BATCH=1 DELETE_MESSAGE_ENABLED=1 FAST_CREATE_COMMUNITY_ENABLED=0 TEST_NETWORKS_ENABLED=0 +FLAG_WALLET_CONNECT_ENABLED=1 diff --git a/src/legacy/status_im/multiaccounts/logout/core.cljs b/src/legacy/status_im/multiaccounts/logout/core.cljs index 03cd55b7bf..59d1c9083b 100644 --- a/src/legacy/status_im/multiaccounts/logout/core.cljs +++ b/src/legacy/status_im/multiaccounts/logout/core.cljs @@ -13,19 +13,17 @@ (native-module/logout))) (rf/defn initialize-app-db - [{{:keys [keycard initials-avatar-font-file biometrics] - :network/keys [type status expensive?] - :wallet-connect/keys [web3-wallet]} + [{{:keys [keycard initials-avatar-font-file biometrics] + :network/keys [type status expensive?]} :db}] {:db (assoc db/app-db - :network/type type - :network/status status - :network/expensive? expensive? - :initials-avatar-font-file initials-avatar-font-file - :keycard (dissoc keycard :secrets :pin :application-info) - :biometrics biometrics - :syncing nil - :wallet-connect/web3-wallet web3-wallet)}) + :network/type type + :network/status status + :network/expensive? expensive? + :initials-avatar-font-file initials-avatar-font-file + :keycard (dissoc keycard :secrets :pin :application-info) + :biometrics biometrics + :syncing nil)}) (rf/defn logout-method {:events [::logout-method]} diff --git a/src/status_im/contexts/network/events.cljs b/src/status_im/contexts/network/events.cljs index d6fd8b719c..f9c03fcb0e 100644 --- a/src/status_im/contexts/network/events.cljs +++ b/src/status_im/contexts/network/events.cljs @@ -66,8 +66,7 @@ :network/on-network-type-change (fn [{:keys [db]} [network-type expensive?]] {:db (assoc db :network/type network-type) - :fx [[:effects.network/notify-status-go network-type expensive?] - [:dispatch [:network/on-network-status-change]]]})) + :fx [[:effects.network/notify-status-go network-type expensive?]]})) (rf/reg-event-fx :network/on-network-status-change diff --git a/src/status_im/contexts/wallet/wallet_connect/core.cljs b/src/status_im/contexts/wallet/wallet_connect/core.cljs index 6bdc5d05af..c4f8f21e19 100644 --- a/src/status_im/contexts/wallet/wallet_connect/core.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/core.cljs @@ -1,5 +1,6 @@ (ns status-im.contexts.wallet.wallet-connect.core (:require [clojure.edn :as edn] + [clojure.set :as set] [clojure.string :as string] [native-module.core :as native-module] [status-im.constants :as constants] @@ -119,10 +120,24 @@ (networks/get-network-details) (add-full-testnet-name))) +(defn session-networks-allowed? + [testnet-mode? {: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)))) + (defn event-should-be-handled? [db {:keys [topic]}] - (some #(= topic %) - (map :topic (:wallet-connect/sessions db)))) + (let [testnet-mode? (get-in db [:profile/profile :test-networks-enabled?])] + (some #(and (= (:topic %) topic) + (session-networks-allowed? testnet-mode? %)) + (:wallet-connect/sessions db)))) (defn sdk-session->db-session [{:keys [topic expiry pairingTopic] :as session}] diff --git a/src/status_im/contexts/wallet/wallet_connect/events.cljs b/src/status_im/contexts/wallet/wallet_connect/events.cljs index 954a96c433..7eba50495a 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events.cljs @@ -67,7 +67,7 @@ (rf/reg-event-fx :wallet-connect/on-session-proposal (fn [{:keys [db]} [proposal]] - (log/info "Received Wallet Connect session proposal: " {:id (:id proposal)}) + (log/info "Received Wallet Connect session proposal: " proposal) (let [accounts (get-in db [:wallet :accounts]) current-viewing-address (get-in db [:wallet :current-viewing-account-address]) available-accounts (wallet-connect-core/filter-operable-accounts (vals accounts)) @@ -117,7 +117,7 @@ :wallet-connect/on-session-delete (fn [{:keys [db]} [{:keys [topic] :as event}]] (when (wallet-connect-core/event-should-be-handled? db event) - (log/info "Received Wallet Connect session delete: " event) + (log/info "Received Wallet Connect session delete from the SDK: " event) {:fx [[:dispatch [:wallet-connect/disconnect-session topic]]]}))) (rf/reg-event-fx @@ -140,6 +140,7 @@ (fn [{:keys [db]} [{:keys [topic on-success on-fail]}]] (let [web3-wallet (get db :wallet-connect/web3-wallet) network-status (:network/status db)] + (log/info "Disconnecting dApp session" topic) (if (= network-status :online) {:fx [[:effects.wallet-connect/disconnect {:web3-wallet web3-wallet @@ -262,6 +263,11 @@ (or (< expiry (/ now 1000)) (not (contains? session-topics topic)))) persisted-sessions)] + (when (seq expired-sessions) + (log/info "Updating WalletConnect persisted sessions due to expired/inactive sessions" + {:expired expired-sessions + :persisted persisted-sessions + :active sessions})) {:fx (mapv (fn [{:keys [topic]}] [:dispatch [:wallet-connect/disconnect-session topic]]) expired-sessions) @@ -324,6 +330,7 @@ (rf/reg-event-fx :wallet-connect/disconnect-session (fn [{:keys [db]} [topic]] + (log/info "Removing session from persistance and state" topic) {:db (update db :wallet-connect/sessions (fn [sessions] diff --git a/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs b/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs index 32df348ceb..fa85668012 100644 --- a/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs @@ -27,6 +27,7 @@ (fn [{:keys [db]} [event]] (let [method (wallet-connect-core/get-request-method event) existing-event (get-in db [:wallet-connect/current-request :event])] + (log/info "Processing Wallet Connect session request" method) ;; NOTE: make sure we don't show two requests at the same time (when-not existing-event {:db (-> db @@ -181,7 +182,6 @@ {:expected-chain-id expected-chain-id :wrong-chain-id wrong-chain-id})]]]}))) -;; TODO: we should reject a request if processing fails (rf/reg-event-fx :wallet-connect/on-processing-error (fn [{:keys [db]} [error]] @@ -193,4 +193,5 @@ :method method :wallet-connect-event event :event :wallet-connect/on-processing-error}) - {:fx [[:dispatch [:wallet-connect/dismiss-request-modal]]]}))) + ;; FIXME(@clauxx/@alwx): rename this event eventually + {:fx [[:dispatch [:wallet-connect/on-request-modal-dismissed]]]}))) diff --git a/src/status_im/subs/wallet/wallet_connect.cljs b/src/status_im/subs/wallet/wallet_connect.cljs index 34abd3e866..6a9adede59 100644 --- a/src/status_im/subs/wallet/wallet_connect.cljs +++ b/src/status_im/subs/wallet/wallet_connect.cljs @@ -1,8 +1,6 @@ (ns status-im.subs.wallet.wallet-connect - (:require [clojure.set :as set] - [clojure.string :as string] + (:require [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] @@ -66,16 +64,7 @@ :<- [: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)))) + (partial wallet-connect-core/session-networks-allowed? testnet-mode?) sessions))) (rf/reg-sub