district UI module for associating arbitrary id with web3 transactions
Clojurescript re-mount module,
that extends district-ui-web3-tx to provide easy way to associate arbitrary id with a transaction.
This is especially useful when in UI we need to display if certain transaction is pending without knowing its transaction hash.
Add into your project.clj
Include [district.ui.web3-tx-id]
in your CLJS file, where you use mount/start
Warning: district0x modules are still in early stages, therefore API can change in a future.
This namespace contains web3-tx-id mount module.
There are no configuration parameters for this module.
(ns my-district.core
(:require [mount.core :as mount]
[district.ui.web3-tx-id]))
(-> (mount/with-args
{:web3 {:url "https://mainnet.infura.io/"}})
(mount/start))
(ns my-district.events
(:require [district.ui.web3-tx.events :as tx-events]))
(dispatch [::tx-events/send-tx {:instance MyContract
:fn :my-function
:args [1]
:tx-opts {:from my-account :gas 4500000}
;; You can pass anything as :tx-id
:tx-id {:my-id 1}}])
re-frame subscriptions provided by this module:
::tx-hash [db tx-id & [opts]]
" class="reference-link">::tx-hash [db tx-id & [opts]]
Returns transaction hash of transaction with given :tx-id
. For opts
you can pass following keys:
:from
Gets tx hash only if tx sender’s address matches given address. Default is district-ui-web3-accounts#active-account.:fn
Gets tx hash only if called contract function matches given :fn
. ::tx [db tx-id & [opts]]
" class="reference-link">::tx [db tx-id & [opts]]
Returns transaction by tx-id
as stored by district-ui-web3-tx.
::tx-status [db tx-id & [opts]]
" class="reference-link">::tx-status [db tx-id & [opts]]
Returns transaction status by tx-id
as stored by district-ui-web3-tx.
::tx-pending? [db tx-id & [opts]]
" class="reference-link">::tx-pending? [db tx-id & [opts]]
Returns true if transaction status is pending.
In this example we assume transaction was sent as in send-tx extension.
(ns my-district.core
(:require [district.ui.web3-tx-id.subs :as subs]))
(defn home-page []
(let [tx-pending? (subscribe [::subs/tx-pending? {:my-id 1}])
same-tx-pending? (subscribe [::subs/tx-pending? {:my-id 1} {:fn :my-function}])]
(fn []
[:div "Transaction pending? " @tx-pending?]
[:div "Transaction pending? " @same-tx-pending?])))
::tx-success? [db tx-id & [opts]]
" class="reference-link">::tx-success? [db tx-id & [opts]]
Returns true if transaction status was successfully processed.
::tx-error? [db tx-id & [opts]]
" class="reference-link">::tx-error? [db tx-id & [opts]]
Returns true if transaction had an error.
re-frame events provided by this module:
::add-tx-hash [tx-id tx-hash opts]
" class="reference-link">::add-tx-hash [tx-id tx-hash opts]
Associates new tx-id with a tx-hash. You don’t need to use this unless doing something specific as this event is fired
automatically after district-ui-web3-tx#send-tx.
::remove-tx-id [tx-hash]
" class="reference-link">::remove-tx-id [tx-hash]
Removes tx-id association with given tx-hash. You don’t need to use this unless doing something specific as this event is fired
automatically after district-ui-web3-tx#remove-tx.
::clean-localstorage
" class="reference-link">::clean-localstorage
Cleans all tx-id associations from localstorage.
DB queries provided by this module:
You should use them in your events, instead of trying to get this module’s
data directly with get-in
into re-frame db.
tx-hash [db tx-id & [opts]]
" class="reference-link">tx-hash [db tx-id & [opts]]
Works same was as sub ::tx-hash
.
tx [db tx-id & [opts]]
" class="reference-link">tx [db tx-id & [opts]]
tx-status [db tx-id & [opts]]
" class="reference-link">tx-status [db tx-id & [opts]]
Works same was as sub ::tx-status
.
tx-pending? [db tx-id & [opts]]
" class="reference-link">tx-pending? [db tx-id & [opts]]
Works same was as sub ::tx-pending?
.
tx-success? [db tx-id & [opts]]
" class="reference-link">tx-success? [db tx-id & [opts]]
Works same was as sub ::tx-success?
.
tx-error? [db tx-id & [opts]]
" class="reference-link">tx-error? [db tx-id & [opts]]
Works same was as sub ::tx-error?
.
add-tx-hash [db tx-id tx-hash & [{:keys [:from :fn]}]]
" class="reference-link">add-tx-hash [db tx-id tx-hash & [{:keys [:from :fn]}]]
Associates new tx-id with a tx-hash and returns new re-frame db.
remove-tx-id [db tx-hash]
" class="reference-link">remove-tx-id [db tx-hash]
Removes tx-id association for tx-hash and returns new re-frame db.
npx truffle develop
npx shadow-cljs watch test-browser
npx shadow-cljs compile test-ci
CHROME_BIN=`which chromium-browser` npx karma start karma.conf.js --single-run
build.clj
clj -T:build jar
clj -T:build deploy
(needs CLOJARS_USERNAME
and CLOJARS_PASSWORD
env vars to be set)