From 3ace91fa86446ea06c8e3d413bf986a8a14e9cee Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Fri, 18 Oct 2024 11:41:29 +0300 Subject: [PATCH] ref: removed chain-id from tx state and added util --- .../events/session_requests.cljs | 29 ++++--------------- .../wallet_connect/utils/data_store.cljs | 7 +++++ src/status_im/subs/wallet/dapps/requests.cljs | 4 +-- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/status_im/contexts/wallet/wallet_connect/events/session_requests.cljs b/src/status_im/contexts/wallet/wallet_connect/events/session_requests.cljs index 57b0153613..630679a578 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events/session_requests.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events/session_requests.cljs @@ -84,7 +84,7 @@ (rf/reg-event-fx :wallet-connect/prepare-transaction-success - (fn [{:keys [db]} [prepared-tx chain-id]] + (fn [{:keys [db]} [prepared-tx]] (let [{:keys [tx-args tx-details]} prepared-tx tx (-> tx-args bean/->clj @@ -93,7 +93,6 @@ [:wallet-connect/current-request] assoc :raw-data prepared-tx - :chain-id chain-id :address (.sender tx) :transaction-summary (.summary tx) :display-data (.beautify-params tx))}))) @@ -103,41 +102,25 @@ (fn [{:keys [db]} [{:keys [on-success]}]] (let [event (data-store/get-db-current-request-event db) tx (-> event data-store/get-request-params first) - chain-id (-> event - (get-in [:params :chainId]) - networks/eip155->chain-id)] + chain-id (data-store/get-chain-id event)] (when tx {:fx [[:effects.wallet-connect/prepare-transaction {:tx tx :chain-id chain-id :on-success (fn [data] - (rf/dispatch [:wallet-connect/prepare-transaction-success data chain-id]) + (rf/dispatch [:wallet-connect/prepare-transaction-success data]) (when on-success (rf/call-continuation on-success))) :on-error #(rf/dispatch [:wallet-connect/on-processing-error %])}]]})))) -(rf/reg-event-fx - :wallet-connect/process-eth-sign-transaction - (fn [{:keys [db]}] - (let [event (data-store/get-db-current-request-event db) - tx (-> event data-store/get-request-params first) - chain-id (-> event - (get-in [:params :chainId]) - networks/eip155->chain-id)] - {:fx [[:effects.wallet-connect/prepare-transaction - {:tx tx - :chain-id chain-id - :on-success #(rf/dispatch [:wallet-connect/prepare-transaction-success % chain-id]) - :on-error #(rf/dispatch [:wallet-connect/on-processing-error %])}]]}))) - (rf/reg-event-fx :wallet-connect/process-sign-typed (fn [{:keys [db]}] (try (let [[address raw-data] (data-store/get-db-current-request-params db) - session-chain-id (-> (data-store/get-db-current-request-event db) - (get-in [:params :chainId]) - networks/eip155->chain-id) + session-chain-id (-> db + (data-store/get-db-current-request-event) + (data-store/get-chain-id)) typed-data (-> raw-data transforms/js-parse transforms/js->clj) diff --git a/src/status_im/contexts/wallet/wallet_connect/utils/data_store.cljs b/src/status_im/contexts/wallet/wallet_connect/utils/data_store.cljs index e51d751c53..64036a1909 100644 --- a/src/status_im/contexts/wallet/wallet_connect/utils/data_store.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/utils/data_store.cljs @@ -2,6 +2,7 @@ (:require [clojure.string :as string] [status-im.constants :as constants] + [status-im.contexts.wallet.wallet-connect.utils.networks :as networks] utils.string [utils.transforms :as transforms])) @@ -80,3 +81,9 @@ :wallet-connect/sessions count inc)) + +(defn get-chain-id + [event] + (-> event + (get-in [:params :chainId]) + networks/eip155->chain-id)) diff --git a/src/status_im/subs/wallet/dapps/requests.cljs b/src/status_im/subs/wallet/dapps/requests.cljs index 12f8272cc3..106ad32ea1 100644 --- a/src/status_im/subs/wallet/dapps/requests.cljs +++ b/src/status_im/subs/wallet/dapps/requests.cljs @@ -46,9 +46,7 @@ :wallet-connect/chain-id :<- [:wallet-connect/current-request] (fn [request] - (-> request - (get-in [:event :params :chainId]) - (networks/eip155->chain-id)))) + (-> request :event data-store/get-chain-id))) (rf/reg-sub :wallet-connect/current-request-network