Clojurescript re-mount module.
This module automatically listens to district-ui-web3-tx events and when a transaction is processed, it calculates and saves transaction costs in chosen currencies. It uses district-ui-conversion-rates to obtain conversion rates.
Add into your project.clj
Include [district.ui.web3-tx-costs] in your CLJS file, where you use mount/start
Warning: district0x modules are still in early stages, therefore API can change in a future.
- district.ui.web3-tx-costs
- subscriptions
- district.ui.web3-tx-costs.events
- district.ui.web3-tx-costs.queries
This namespace contains web3-tx-costs mount module.
You can pass following args to initiate this module (optional):
:currenciesCurrencies you want to be calculating costs to.:ETHis always added, you don't need to pass that.:request-interval-msHow often rates should be reloaded. Default as in district-ui-conversion-rates.
(ns my-district.core
(:require [mount.core :as mount]
[district.ui.web3-tx-costs]))
(-> (mount/with-args
{:web3 {:url "https://mainnet.infura.io/"}
:web3-tx-costs {:currencies [:USD :EUR]}})
(mount/start))This module doesn't have its own subscriptions. Instead you can use district-ui-web3-tx subscriptions
and transactions will automatically contain entry :tx-costs with transaction costs.
(ns my-district.core
(:require [mount.core :as mount]
[district.ui.web3-tx :as subs]))
(defn home-page []
(let [txs (subscribe [::subs/txs])]
(fn []
[:div "Your transactions: "]
(for [[tx-hash {:keys [:tx-costs]}] @txs]
[:div
{:key tx-hash}
"Transaction hash: " tx-hash
"Transaction cost USD: " (:USD tx-costs)
"Transaction cost ETH: " (:ETH tx-costs)]))))re-frame events provided by this module:
Adds currencies, that costs will be converted to. Does effectively same thing as if you pass initial :currencies on
mount start. Use this from inside other modules, which build on top of this module.
(dispatch [::events/add-currencies [:USD :EUR]])Event fired when district-ui-web3-tx fires its event. Performs conversion.
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.
Returns currencies the module is converting into.
Sets currencies and returns and returns new re-frame db.
Adds currencies and returns and returns new re-frame db.
- Run test suite:
- Browser
npx shadow-cljs watch test-browser- open https://d0x-vm:6502
- tests refresh automatically on code change
- CI (Headless Chrome, Karma)
npx shadow-cljs compile test-ciCHROME_BIN=`which chromium-browser` npx karma start karma.conf.js --single-run
- Build
- on merging pull request to master on GitHub, CI builds & publishes new version automatically
- update version in
build.clj - to build:
clj -T:build jar - to release:
clj -T:build deploy(needsCLOJARS_USERNAMEandCLOJARS_PASSWORDenv vars to be set)