Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Repository files navigation

district-ui-web3-tx-costs

CircleCI

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.

Installation

Add Clojars Project into your project.clj
Include [district.ui.web3-tx-costs] in your CLJS file, where you use mount/start

API Overview

Warning: district0x modules are still in early stages, therefore API can change in a future.

district.ui.web3-tx-costs

This namespace contains web3-tx-costs mount module.

You can pass following args to initiate this module (optional):

  • :currencies Currencies you want to be calculating costs to. :ETH is always added, you don't need to pass that.
  • :request-interval-ms How 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))

subscriptions

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

district.ui.web3-tx-costs.events

re-frame events provided by this module:

::add-currencies [currencies opts]

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

::tx-loaded

Event fired when district-ui-web3-tx fires its event. Performs conversion.

district.ui.web3-tx-costs.queries

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.

currencies [db]

Returns currencies the module is converting into.

set-currencies [db currencies]

Sets currencies and returns and returns new re-frame db.

add-currencies [db currencies]

Adds currencies and returns and returns new re-frame db.

Dependency on other district UI modules

Development

  1. 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-ci
    • CHROME_BIN=`which chromium-browser` npx karma start karma.conf.js --single-run
  1. 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 (needs CLOJARS_USERNAME and CLOJARS_PASSWORD env vars to be set)

About

⚠️ This code now resides at d0x monorepo

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages