-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (42 loc) · 1.09 KB
/
Copy pathindex.js
File metadata and controls
52 lines (42 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const render = require('react-dom').render
const h = require('react-hyperscript')
const configureStore = require('./lib/store')
const Root = require('./app/root.js')
const Eth = require('ethjs')
const metamask = require('metamascara')
let eth;
var body = document.querySelector('body')
const container = document.createElement('div')
body.appendChild(container)
let web3Found = false
window.addEventListener('load', function() {
const provider = metamask.createDefaultProvider({})
eth = new Eth(provider)
window.eth = eth
store.dispatch({ type: 'ETH_LOADED', value: eth })
store.dispatch({ type: 'WEB3_FOUND', value: true })
// Now you can start your app & access web3 freely:
startApp()
})
const store = configureStore({
nonce: 0,
web3Found: false,
loading: true,
})
function startApp(){
render(
h(Root, {
store,
className: 'root-el',
}),
container)
}
// Check for account changes:
setInterval(async function () {
const accounts = await eth.accounts()
const account = accounts[0]
store.dispatch({
type: 'ACCOUNT_CHANGED',
value: account,
})
}, 200)