A set of UI tools, including the Interbit middleware for connecting chains to a GUI and using them with React and Redux.
Redux middleware to connect configured interbit blockchains to redux store state.
This middleware creates a connected interface and a hypervisor, then loads and connects to chains and peers that have been specified in the index.html file.
The middleware is included in the interbit-ui-tools package.
npm i --save interbit-ui-tools redux redux-sagaBecause the interbit middleware contains a saga that must be run there are several steps to including it in your redux store.
-
Creating the Interbit middleware
-
Creating the Redux Saga middleware
-
Including the reducer
-
Including the middlewares with your store on
createStore -
Running the saga
{% include "code/README-saga.js" %}
The middleware automatically connects to any chains that are specified
on the first DOM element in index.html with an id of interbit.
Specify chain IDs using a data tag starting with
data-chain-id-chain-name. The chain-name will be in camelCase when
it is used as a chain alias to mount state on in the middleware’s redux
store.
{% include "code/README-index-div.html" %}The above data tag results in a chain named myChain being mounted in
the middleware state as follows:
{% include "code/README-chains-html.js" %}The chains property contains chain state for each of the connected
chains and the chainData section contains metadata about the chains
including their status (LOADING, BLOCKING, etc.) as well as their
chainId.
|
Caution
|
Incomplete content. These statuses need to be documented in an API reference and linked to from here. |
You can specify peers for your browser node to connect to in index.html as well. There are specified the same was as chains using the data-peer-hints attribute.
If no port is specified the middleware will attempt to connect on port
80 for http connections and 443 for https connections.
To specify multiple peers, separate them using a comma.
If no peers are specified the middleware attempts to connect to
localhost:5000, which is the default set by interbit when it runs a
node.
<div id="interbit" data-peer-hints="your-blockchain-node.com,localhost:1234" />Interbit config can be used to automatically update chain IDs as you generate new chains and adjust your network configuration.
To configure an application which has the index.html file in
<cwd>/public/index.html add the following to the Interbit
configuration.
{% include "code/README-chains-config.js" %}Getting interbit state once the middleware is attached works through the redux store.
const state = store.getState()
console.log(state.interbit)The middleware comes with an action creator that wraps your blockchain action in a redux action with the chain alias of the chain you wish to dispatch your action to.
The middleware intercepts the blockchain action and returns the promise from the blockchain to the user after dispatch. This promise will resolve when the action is blocked or reject on failure.
{% include "code/README-dispatch.js" %}