A simple deposit and profit bytom dapp demo
修订版 | 6d938d56e3315bc05f484f563c0f0ec1668e0b45 (tree) |
---|---|
时间 | 2019-04-01 19:17:18 |
作者 | Zhiting Lin <zlin035@uott...> |
Commiter | Zhiting Lin |
init index.js
@@ -0,0 +1,61 @@ | ||
1 | +import 'jquery'; | |
2 | +import 'popper.js'; | |
3 | +import 'bootstrap/dist/js/bootstrap'; | |
4 | +import "bootstrap/scss/bootstrap"; | |
5 | +import React from "react"; | |
6 | +import ReactDOM from "react-dom"; | |
7 | +import App from "./components/App.js"; | |
8 | +import { BrowserRouter } from 'react-router-dom'; | |
9 | + | |
10 | +import { Provider } from "react-redux"; | |
11 | +import configureStore from "./store"; | |
12 | + | |
13 | +import Bytom from 'bytom-js-sdk' | |
14 | + | |
15 | +require("babel-core/register"); | |
16 | +require("babel-polyfill"); | |
17 | + | |
18 | +window.addEventListener('load', async function() { | |
19 | + if (typeof window.bytom !== 'undefined') { | |
20 | + let bytomPollInterval = 3 * 1000; | |
21 | + | |
22 | + let networks = { | |
23 | + solonet: 'http://app.bycoin.io:3000/', | |
24 | + testnet: 'http://app.bycoin.io:3020/', | |
25 | + mainnet: 'https://api.bycoin.im:8000/' | |
26 | + }; | |
27 | + | |
28 | + try { | |
29 | + window.bytom.defaultAccount = await window.bytom.request('currentAccount') | |
30 | + | |
31 | + const bytom = new Bytom(networks, '') | |
32 | + bytom.setNetType(window.bytom.defaultAccount.net) | |
33 | + | |
34 | + global.bytomAPI = bytom | |
35 | + | |
36 | + // Check to see if the user has signed in/out of their | |
37 | + // bytom wallet or switched accounts | |
38 | + let accountInterval = setInterval(async function() { | |
39 | + const account = await window.bytom.request('currentAccount') | |
40 | + if ( account.guid !== window.bytom.defaultAccount.guid) { | |
41 | + location.reload(true); | |
42 | + } | |
43 | + }, bytomPollInterval); | |
44 | + } catch (err) { | |
45 | + console.log(err); | |
46 | + } | |
47 | + | |
48 | + } | |
49 | + | |
50 | + ReactDOM.render(( | |
51 | + <Provider store={configureStore()}> | |
52 | + <BrowserRouter> | |
53 | + <App /> | |
54 | + </BrowserRouter> | |
55 | + </Provider> | |
56 | + ), document.getElementById('root')); | |
57 | +}); | |
58 | + | |
59 | + | |
60 | + | |
61 | + |