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
SHOW_NOT_IMPLEMENTED_FEATURES=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_UNDO_TIME_LIMIT=10000
ENABLE_ALERT_BANNER=0
FLAG_WALLET_CONNECT_ENABLED=1
MOBILE_DATA_SYNCING_TOGGLE_ENABLE=0

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]}

View File

@ -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

View File

@ -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}]

View File

@ -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]

View File

@ -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]]]})))

View File

@ -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