项目作者: district0x

项目描述 :
district UI module for associating arbitrary id with web3 transactions
高级语言: Clojure
项目地址: git://github.com/district0x/district-ui-web3-tx-id.git
创建时间: 2018-01-28T16:17:17Z
项目社区:https://github.com/district0x/district-ui-web3-tx-id

开源协议:Eclipse Public License 1.0

下载


district-ui-web3-tx-id

CircleCI

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.

Installation

Add Clojars Project into your project.clj
Include [district.ui.web3-tx-id] 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-id

This namespace contains web3-tx-id mount module.
There are no configuration parameters for this module.

  1. (ns my-district.core
  2. (:require [mount.core :as mount]
  3. [district.ui.web3-tx-id]))
  4. (-> (mount/with-args
  5. {:web3 {:url "https://mainnet.infura.io/"}})
  6. (mount/start))

send-tx extension

  1. (ns my-district.events
  2. (:require [district.ui.web3-tx.events :as tx-events]))
  3. (dispatch [::tx-events/send-tx {:instance MyContract
  4. :fn :my-function
  5. :args [1]
  6. :tx-opts {:from my-account :gas 4500000}
  7. ;; You can pass anything as :tx-id
  8. :tx-id {:my-id 1}}])

district.ui.web3-tx-id.subs

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:

::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.

  1. (ns my-district.core
  2. (:require [district.ui.web3-tx-id.subs :as subs]))
  3. (defn home-page []
  4. (let [tx-pending? (subscribe [::subs/tx-pending? {:my-id 1}])
  5. same-tx-pending? (subscribe [::subs/tx-pending? {:my-id 1} {:fn :my-function}])]
  6. (fn []
  7. [:div "Transaction pending? " @tx-pending?]
  8. [: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.

district.ui.web3-tx-id.events

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.

district.ui.web3-tx-id.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.

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

Works same was as sub ::tx.

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.

Dependency on other district UI modules

Development

  1. Setup local testnet
  • spin up a testnet instance in a separate shell
    • npx truffle develop
  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)