feat: init

This commit is contained in:
Cristian Lungu 2024-10-08 11:50:34 +03:00
parent 711fd19967
commit e39fb0b318
No known key found for this signature in database
GPG Key ID: 00D675EDE1B264D9
4 changed files with 103 additions and 13 deletions

View File

@ -10,8 +10,8 @@
(defn enabled? [v] (= "1" v))
(goog-define INFURA_TOKEN "")
(goog-define POKT_TOKEN "3ef2018191814b7e1009b8d9")
(goog-define INFURA_TOKEN "1abe540f06ed4245b47d68f28549d5a4")
(goog-define POKT_TOKEN "")
(goog-define STATUS_BUILD_PROXY_USER "")
(goog-define STATUS_BUILD_PROXY_PASSWORD "")
(goog-define OPENSEA_API_KEY "")

View File

@ -85,18 +85,18 @@
(rf/reg-event-fx
:wallet-connect/prepare-transaction-success
(fn [{:keys [db]} [prepared-tx chain-id]]
(let [{:keys [tx-args]} prepared-tx
tx (bean/->clj tx-args)
address (-> tx :from string/lower-case)
display-data (transactions/beautify-transaction tx)]
(let [{:keys [tx-args tx-details]} prepared-tx
tx (-> tx-args
bean/->clj
(transactions/Transaction. tx-details))]
{:db (update-in db
[:wallet-connect/current-request]
assoc
:address address
:raw-data prepared-tx
:transaction tx
:chain-id chain-id
:display-data display-data)})))
:raw-data prepared-tx
:chain-id chain-id
:address (.sender tx)
:transaction-summary (.summary tx)
:display-data (.beautify-params tx))})))
(rf/reg-event-fx
:wallet-connect/process-eth-send-transaction

View File

@ -1,5 +1,6 @@
(ns status-im.contexts.wallet.wallet-connect.utils.rpc
(:require [oops.core :as oops]
(:require [cljs-bean.core :as bean]
[oops.core :as oops]
[promesa.core :as promesa]
[status-im.common.json-rpc.events :as rpc-events]
[status-im.constants :as constants]
@ -79,3 +80,9 @@
[chain-id max-fee-per-gas]
(-> (rpc-events/call-async "wallet_getTransactionEstimatedTime" true chain-id max-fee-per-gas)
(promesa/then transforms/js->clj)))
(defn wallet-get-transaction-details
[transaction]
(->> (transforms/js-stringify transaction 0)
(rpc-events/call-async "wallet_getTransactionMetadata" true)
(transforms/js->clj)))

View File

@ -1,5 +1,6 @@
(ns status-im.contexts.wallet.wallet-connect.utils.transactions
(:require [cljs-bean.core :as bean]
[cljs.pprint :as pprint]
[clojure.string :as string]
[native-module.core :as native-module]
[promesa.core :as promesa]
@ -128,9 +129,11 @@
(rpc/wallet-build-transaction chain-id))
estimated-time (rpc/wallet-get-transaction-estimated-time
chain-id
(:maxPriorityFeePerGas suggested-fees))]
(:maxPriorityFeePerGas suggested-fees))
details (rpc/wallet-get-transaction-details tx-args)]
{:tx-args tx-args
:tx-hash message-to-sign
:tx-details details
:suggested-fees suggested-fees
:estimated-time estimated-time}))
@ -157,3 +160,83 @@
(= k :MultiTransactionID)
(= k :Symbol)))
data))
(def tx-args
{:version 0
:from "0xb18ec1808bd8b84f244c6e34cbedee9b0cd7e1fb"
:to "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
:gas "0x21563"
:gasPrice "0xda9a06de5"
:value "0x0"
:nonce "0x19"
:maxFeePerGas "0xda9a06de5"
:maxPriorityFeePerGas "0x5d56b25c"
:input "0x"
:data
"0xa9059cbb00000000000000000000000097654628dd47c2d88fc9b3d0cc38a92e46a32cd4000000000000000000000000000000000000000000000016ca63768fcf860000"
:multiTransactionID 0})
(def tx-met
{:FunctionSelector "0xa9059cbb"
:FunctionName "transfer"
:Recipient "0x97654628dd47c2d88fc9b3d0cc38a92e46a32cd4"
:Amount "420412000000000000000"
:TokenID "<nil>"})
(defrecord Transaction [params metadata]
Object
(beautify-params [this]
(-> this :params beautify-transaction))
(type [this]
(condp = (get-in this [:metadata :FunctionName])
"" :transaction/eth-transfer
"transfer" :transaction/erc-20-transfer
"approve" :transaction/approve
:else :transaction/unknown))
(amount [this]
(let [metadata-amount (get-in this [:metadata :Amount])
params-amount (get-in this [:params :value])]
(-> (condp =
(.type this)
:transaction/erc-20-transfer
metadata-amount
:transaction/approve
metadata-amount
:else
params-amount)
money/bignumber)))
(sender [this]
(-> this :params :from string/lower-case))
(recipient [this]
(let [metadata-recipient (get-in this [:metadata :Recipient])
params-recipient (get-in this [:params :to])]
(-> (condp =
(.type this)
:transaction/erc-20-transfer
metadata-recipient
:transaction/approve
metadata-recipient
:else
params-recipient)
string/lower-case)))
(token-address [this]
(when (->> this
.type
(contains? #{:transaction/erc-20-transfer
:transaction/approve}))
(-> this :params :to string/lower-case)))
(summary [this]
{:type (.type this)
:amount (.amount this)
:recipient (.recipient this)
:sender (.sender this)
:token-address (.token-address this)}))
(def tx (->Transaction tx-args tx-met))