diff --git a/src/react_native/wallet_connect.cljs b/src/react_native/wallet_connect.cljs new file mode 100644 index 00000000000..66e05dbd081 --- /dev/null +++ b/src/react_native/wallet_connect.cljs @@ -0,0 +1,24 @@ +(ns react-native.wallet-connect + ;; NOTE: Not sorting namespaces since @walletconnect/react-native-compat should be the first + #_{:clj-kondo/ignore [:unsorted-required-namespaces]} + (:require ["@walletconnect/react-native-compat"] + ["@walletconnect/core" :refer [Core]] + ["@walletconnect/web3wallet" :refer [Web3Wallet]] + ["@walletconnect/utils" :refer [buildApprovedNamespaces]])) + +(defn- wallet-connect-core + [project-id] + (Core. #js {:projectId project-id})) + +(defn init + [project-id metadata] + (let [core (wallet-connect-core project-id)] + (Web3Wallet.init + (clj->js {:core core + :metadata metadata})))) + +(defn build-approved-namespaces + [proposal supported-namespaces] + (buildApprovedNamespaces + (clj->js {:proposal proposal + :supportedNamespaces supported-namespaces}))) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index dab409eace8..59679b5ed9c 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -258,6 +258,9 @@ (def regx-full-or-partial-address #"^0x[a-fA-F0-9]{1,40}$") ;; Wallet Connect +(def ^:const wallet-connect-metadata-icon + "https://res.cloudinary.com/dhgck7ebz/image/upload/f_auto,c_limit,w_1080,q_auto/Brand/Logo%20Section/Mark/Mark_01") +(def ^:const wallet-connect-metadata-url "https://status.app") (def ^:const optimism-crosschain-id "eip155:10") (def ^:const wallet-connect-supported-methods ["eth_sendTransaction" "personal_sign"]) (def ^:const wallet-connect-supported-events ["accountsChanged" "chainChanged"]) diff --git a/src/status_im/contexts/wallet/wallet_connect/effects.cljs b/src/status_im/contexts/wallet/wallet_connect/effects.cljs index 7d2f27089fb..cb1ad13d541 100644 --- a/src/status_im/contexts/wallet/wallet_connect/effects.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/effects.cljs @@ -1,18 +1,27 @@ (ns status-im.contexts.wallet.wallet-connect.effects (:require [promesa.core :as promesa] [re-frame.core :as rf] - [status-im.contexts.wallet.wallet-connect.utils :as wallet-connect.utils])) + [react-native.wallet-connect :as wallet-connect] + [status-im.config :as config] + [status-im.constants :as constants] + [utils.i18n :as i18n])) (rf/reg-fx :effects.wallet-connect/init (fn [{:keys [on-success on-fail]}] - (-> (wallet-connect.utils/init) - (promesa/then on-success) - (promesa/catch on-fail)))) + (let + [project-id config/WALLET_CONNECT_PROJECT_ID + metadata {:name (i18n/label :t/status) + :description (i18n/label :t/status-is-a-secure-messaging-app) + :url constants/wallet-connect-metadata-url + :icons [constants/wallet-connect-metadata-icon]}] + (-> (wallet-connect/init project-id metadata) + (promesa/then on-success) + (promesa/catch on-fail))))) (rf/reg-fx :effects.wallet-connect/register-event-listener - (fn [web3-wallet wc-event handler] + (fn [[web3-wallet wc-event handler]] (.on web3-wallet wc-event (fn [js-proposal] @@ -32,8 +41,8 @@ :effects.wallet-connect/approve-session (fn [{:keys [web3-wallet proposal supported-namespaces on-success on-fail]}] (let [{:keys [params id]} proposal - approved-namespaces (wallet-connect.utils/build-approved-namespaces params - supported-namespaces)] + approved-namespaces (wallet-connect/build-approved-namespaces params + supported-namespaces)] (-> (.approveSession web3-wallet (clj->js {:id id :namespaces approved-namespaces})) diff --git a/src/status_im/contexts/wallet/wallet_connect/events.cljs b/src/status_im/contexts/wallet/wallet_connect/events.cljs index f133fed86d6..55f93292b8b 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events.cljs @@ -2,7 +2,6 @@ (:require [re-frame.core :as rf] [status-im.constants :as constants] status-im.contexts.wallet.wallet-connect.effects - [status-im.contexts.wallet.wallet-connect.utils :as wallet-connect.utils] [taoensso.timbre :as log])) (rf/reg-event-fx @@ -23,13 +22,13 @@ (fn [{:keys [db]}] (let [web3-wallet (get db :wallet-connect/web3-wallet)] {:fx [[:effects.wallet-connect/register-event-listener - web3-wallet - constants/wallet-connect-session-proposal-event - #(rf/dispatch [:wallet-connect/on-session-proposal %])]]}))) + [web3-wallet + constants/wallet-connect-session-proposal-event + #(rf/dispatch [:wallet-connect/on-session-proposal %])]]]}))) (rf/reg-event-fx :wallet-connect/on-init-fail - (fn [error] + (fn [_ [error]] (log/error "Failed to initialize Wallet Connect" {:error error :event :wallet-connect/on-init-fail}))) @@ -51,7 +50,7 @@ {:fx [[:effects.wallet-connect/pair {:web3-wallet web3-wallet :url url - :on-fail #(log/error "Failed to pair with dApp") + :on-fail #(log/error "Failed to pair with dApp" {:error %}) :on-success #(log/info "dApp paired successfully")}]]}))) (rf/reg-event-fx @@ -68,8 +67,7 @@ ;; - global scanner -> first account in list ;; - wallet account dapps -> account that is selected address (-> accounts keys first) - formatted-address (wallet-connect.utils/format-address (first crosschain-ids) - address) + formatted-address (str (first crosschain-ids) ":" address) supported-namespaces (clj->js {:eip155 {:chains crosschain-ids :methods constants/wallet-connect-supported-methods @@ -80,7 +78,7 @@ :proposal current-proposal :supported-namespaces supported-namespaces :on-success (fn [] - (log/debug "Wallet Connect session approved") + (log/info "Wallet Connect session approved") (rf/dispatch [:wallet-connect/reset-current-session])) :on-fail (fn [error] (log/error "Wallet Connect session approval failed" diff --git a/src/status_im/contexts/wallet/wallet_connect/utils.cljs b/src/status_im/contexts/wallet/wallet_connect/utils.cljs deleted file mode 100644 index 8cf5952d67f..00000000000 --- a/src/status_im/contexts/wallet/wallet_connect/utils.cljs +++ /dev/null @@ -1,39 +0,0 @@ -(ns status-im.contexts.wallet.wallet-connect.utils - ;; NOTE: Not sorting namespaces since @walletconnect/react-native-compat should be the first - #_{:clj-kondo/ignore [:unsorted-required-namespaces]} - (:require ["@walletconnect/react-native-compat"] - ["@walletconnect/core" :refer [Core]] - ["@walletconnect/web3wallet" :refer [Web3Wallet]] - ["@walletconnect/utils" :refer [buildApprovedNamespaces]] - [status-im.config :as config] - [utils.i18n :as i18n])) - -(defn- wallet-connect-metadata - [] - #js - {:name (i18n/label :t/status) - :description (i18n/label :t/status-is-a-secure-messaging-app) - :url "https://status.app" - :icons - ["https://res.cloudinary.com/dhgck7ebz/image/upload/f_auto,c_limit,w_1080,q_auto/Brand/Logo%20Section/Mark/Mark_01"]}) - -(defn- wallet-connect-core - [] - (Core. #js {:projectId config/WALLET_CONNECT_PROJECT_ID})) - -(defn init - [] - (let [core (wallet-connect-core)] - (Web3Wallet.init - (clj->js {:core core - :metadata wallet-connect-metadata})))) - -(defn build-approved-namespaces - [proposal supported-namespaces] - (buildApprovedNamespaces - (clj->js {:proposal proposal - :supportedNamespaces supported-namespaces}))) - -(defn format-address - [chain-id address] - (str chain-id ":" address))