ref: removed chain-id from tx state and added util

This commit is contained in:
Cristian Lungu 2024-10-18 11:41:29 +03:00
parent e39fb0b318
commit 3ace91fa86
No known key found for this signature in database
GPG Key ID: 00D675EDE1B264D9
3 changed files with 14 additions and 26 deletions

View File

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

View File

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

View File

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