Enabling WalletConnect feature flag (#20906)

* feat: removed wallet connect feature flag

* fix: show pending requests when logging out and in

* fix: don't show requests across (test/main)nets

* format: added env newlines

* fix: network state reset on network type change

* fix: reject typed-data if wrong chain-id

* chore: added logs for future debugging
This commit is contained in:
Lungu Cristian 2024-07-29 19:55:54 +03:00 committed by GitHub
parent 67c83b13e3
commit 8c2d5398b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 46 additions and 32 deletions

1
.env
View File

@ -35,3 +35,4 @@ FAST_CREATE_COMMUNITY_ENABLED=1
TEST_NETWORKS_ENABLED=1 TEST_NETWORKS_ENABLED=1
SHOW_NOT_IMPLEMENTED_FEATURES=0 SHOW_NOT_IMPLEMENTED_FEATURES=0
ENABLE_ALERT_BANNER=0 ENABLE_ALERT_BANNER=0
FLAG_WALLET_CONNECT_ENABLED=1

View File

@ -38,4 +38,5 @@ SHOW_NOT_IMPLEMENTED_FEATURES=1
DELETE_MESSAGE_FOR_ME_UNDO_TIME_LIMIT=10000 DELETE_MESSAGE_FOR_ME_UNDO_TIME_LIMIT=10000
DELETE_MESSAGE_UNDO_TIME_LIMIT=10000 DELETE_MESSAGE_UNDO_TIME_LIMIT=10000
ENABLE_ALERT_BANNER=0 ENABLE_ALERT_BANNER=0
FLAG_WALLET_CONNECT_ENABLED=1
MOBILE_DATA_SYNCING_TOGGLE_ENABLE=0 MOBILE_DATA_SYNCING_TOGGLE_ENABLE=0

View File

@ -36,3 +36,4 @@ LOCAL_PAIRING_ENABLED=1
FAST_CREATE_COMMUNITY_ENABLED=1 FAST_CREATE_COMMUNITY_ENABLED=1
TEST_NETWORKS_ENABLED=1 TEST_NETWORKS_ENABLED=1
ENABLE_ALERT_BANNER=1 ENABLE_ALERT_BANNER=1
FLAG_WALLET_CONNECT_ENABLED=1

View File

@ -23,3 +23,4 @@ DELETE_MESSAGE_ENABLED=1
FAST_CREATE_COMMUNITY_ENABLED=0 FAST_CREATE_COMMUNITY_ENABLED=0
TEST_NETWORKS_ENABLED=0 TEST_NETWORKS_ENABLED=0
ENABLE_ALERT_BANNER=1 ENABLE_ALERT_BANNER=1
FLAG_WALLET_CONNECT_ENABLED=1

View File

@ -19,3 +19,4 @@ MAX_IMAGES_BATCH=1
DELETE_MESSAGE_ENABLED=1 DELETE_MESSAGE_ENABLED=1
FAST_CREATE_COMMUNITY_ENABLED=0 FAST_CREATE_COMMUNITY_ENABLED=0
TEST_NETWORKS_ENABLED=0 TEST_NETWORKS_ENABLED=0
FLAG_WALLET_CONNECT_ENABLED=1

View File

@ -14,8 +14,7 @@
(rf/defn initialize-app-db (rf/defn initialize-app-db
[{{:keys [keycard initials-avatar-font-file biometrics] [{{:keys [keycard initials-avatar-font-file biometrics]
:network/keys [type status expensive?] :network/keys [type status expensive?]}
:wallet-connect/keys [web3-wallet]}
:db}] :db}]
{:db (assoc db/app-db {:db (assoc db/app-db
:network/type type :network/type type
@ -24,8 +23,7 @@
:initials-avatar-font-file initials-avatar-font-file :initials-avatar-font-file initials-avatar-font-file
:keycard (dissoc keycard :secrets :pin :application-info) :keycard (dissoc keycard :secrets :pin :application-info)
:biometrics biometrics :biometrics biometrics
:syncing nil :syncing nil)})
:wallet-connect/web3-wallet web3-wallet)})
(rf/defn logout-method (rf/defn logout-method
{:events [::logout-method]} {:events [::logout-method]}

View File

@ -66,8 +66,7 @@
:network/on-network-type-change :network/on-network-type-change
(fn [{:keys [db]} [network-type expensive?]] (fn [{:keys [db]} [network-type expensive?]]
{:db (assoc db :network/type network-type) {:db (assoc db :network/type network-type)
:fx [[:effects.network/notify-status-go network-type expensive?] :fx [[:effects.network/notify-status-go network-type expensive?]]}))
[:dispatch [:network/on-network-status-change]]]}))
(rf/reg-event-fx (rf/reg-event-fx
:network/on-network-status-change :network/on-network-status-change

View File

@ -1,5 +1,6 @@
(ns status-im.contexts.wallet.wallet-connect.core (ns status-im.contexts.wallet.wallet-connect.core
(:require [clojure.edn :as edn] (:require [clojure.edn :as edn]
[clojure.set :as set]
[clojure.string :as string] [clojure.string :as string]
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im.constants :as constants] [status-im.constants :as constants]
@ -119,10 +120,24 @@
(networks/get-network-details) (networks/get-network-details)
(add-full-testnet-name))) (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? (defn event-should-be-handled?
[db {:keys [topic]}] [db {:keys [topic]}]
(some #(= topic %) (let [testnet-mode? (get-in db [:profile/profile :test-networks-enabled?])]
(map :topic (:wallet-connect/sessions db)))) (some #(and (= (:topic %) topic)
(session-networks-allowed? testnet-mode? %))
(:wallet-connect/sessions db))))
(defn sdk-session->db-session (defn sdk-session->db-session
[{:keys [topic expiry pairingTopic] :as session}] [{:keys [topic expiry pairingTopic] :as session}]

View File

@ -67,7 +67,7 @@
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/on-session-proposal :wallet-connect/on-session-proposal
(fn [{:keys [db]} [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]) (let [accounts (get-in db [:wallet :accounts])
current-viewing-address (get-in db [:wallet :current-viewing-account-address]) current-viewing-address (get-in db [:wallet :current-viewing-account-address])
available-accounts (wallet-connect-core/filter-operable-accounts (vals accounts)) available-accounts (wallet-connect-core/filter-operable-accounts (vals accounts))
@ -117,7 +117,7 @@
:wallet-connect/on-session-delete :wallet-connect/on-session-delete
(fn [{:keys [db]} [{:keys [topic] :as event}]] (fn [{:keys [db]} [{:keys [topic] :as event}]]
(when (wallet-connect-core/event-should-be-handled? db 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]]]}))) {:fx [[:dispatch [:wallet-connect/disconnect-session topic]]]})))
(rf/reg-event-fx (rf/reg-event-fx
@ -140,6 +140,7 @@
(fn [{:keys [db]} [{:keys [topic on-success on-fail]}]] (fn [{:keys [db]} [{:keys [topic on-success on-fail]}]]
(let [web3-wallet (get db :wallet-connect/web3-wallet) (let [web3-wallet (get db :wallet-connect/web3-wallet)
network-status (:network/status db)] network-status (:network/status db)]
(log/info "Disconnecting dApp session" topic)
(if (= network-status :online) (if (= network-status :online)
{:fx [[:effects.wallet-connect/disconnect {:fx [[:effects.wallet-connect/disconnect
{:web3-wallet web3-wallet {:web3-wallet web3-wallet
@ -262,6 +263,11 @@
(or (< expiry (/ now 1000)) (or (< expiry (/ now 1000))
(not (contains? session-topics topic)))) (not (contains? session-topics topic))))
persisted-sessions)] 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]}] {:fx (mapv (fn [{:keys [topic]}]
[:dispatch [:wallet-connect/disconnect-session topic]]) [:dispatch [:wallet-connect/disconnect-session topic]])
expired-sessions) expired-sessions)
@ -324,6 +330,7 @@
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/disconnect-session :wallet-connect/disconnect-session
(fn [{:keys [db]} [topic]] (fn [{:keys [db]} [topic]]
(log/info "Removing session from persistance and state" topic)
{:db (update db {:db (update db
:wallet-connect/sessions :wallet-connect/sessions
(fn [sessions] (fn [sessions]

View File

@ -27,6 +27,7 @@
(fn [{:keys [db]} [event]] (fn [{:keys [db]} [event]]
(let [method (wallet-connect-core/get-request-method event) (let [method (wallet-connect-core/get-request-method event)
existing-event (get-in db [:wallet-connect/current-request :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 ;; NOTE: make sure we don't show two requests at the same time
(when-not existing-event (when-not existing-event
{:db (-> db {:db (-> db
@ -181,7 +182,6 @@
{:expected-chain-id expected-chain-id {:expected-chain-id expected-chain-id
:wrong-chain-id wrong-chain-id})]]]}))) :wrong-chain-id wrong-chain-id})]]]})))
;; TODO: we should reject a request if processing fails
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/on-processing-error :wallet-connect/on-processing-error
(fn [{:keys [db]} [error]] (fn [{:keys [db]} [error]]
@ -193,4 +193,5 @@
:method method :method method
:wallet-connect-event event :wallet-connect-event event
:event :wallet-connect/on-processing-error}) :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]]]})))

View File

@ -1,8 +1,6 @@
(ns status-im.subs.wallet.wallet-connect (ns status-im.subs.wallet.wallet-connect
(:require [clojure.set :as set] (:require [clojure.string :as string]
[clojure.string :as string]
[re-frame.core :as rf] [re-frame.core :as rf]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils :as wallet-utils] [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.core :as wallet-connect-core]
[status-im.contexts.wallet.wallet-connect.transactions :as transactions] [status-im.contexts.wallet.wallet-connect.transactions :as transactions]
@ -66,16 +64,7 @@
:<- [:profile/test-networks-enabled?] :<- [:profile/test-networks-enabled?]
(fn [[sessions testnet-mode?]] (fn [[sessions testnet-mode?]]
(filter (filter
(fn [{:keys [chains]}] (partial wallet-connect-core/session-networks-allowed? testnet-mode?)
(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))) sessions)))
(rf/reg-sub (rf/reg-sub