-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathweb3.js
60 lines (55 loc) · 1.53 KB
/
web3.js
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
52
53
54
55
56
57
58
59
60
import Web3 from 'web3'
import Vue from 'vue'
import { mapGetters } from 'vuex'
export default ({ app, store }, inject) => {
/**
* Inject standalone web3 utils (for non-web3 browsers)
*/
inject('web3utils', Web3.utils)
if (window.ethereum) {
inject('web3', new Web3(window.ethereum))
window.ethereum.on('accountsChanged', () => {
store.dispatch('updateAccounts')
})
window.ethereum.on('chainChanged', () => {
store.dispatch('updateNetworkId')
store.dispatch('updateAccounts')
})
Vue.mixin({
computed: {
...mapGetters(['config']),
octobay() {
return new app.$web3.eth.Contract(
require('./../contract-abi/Octobay.json').abi,
process.env.OCTOBAY_ADDRESS
)
},
octobayGovernor() {
return new app.$web3.eth.Contract(
require('./../contract-abi/OctobayGovernor.json').abi,
this.config.octobayGovernor
)
},
octobayGovNFT() {
return new app.$web3.eth.Contract(
require('./../contract-abi/OctobayGovNFT.json').abi,
this.config.octobayGovNFT
)
},
},
methods: {
octobayGovToken(address) {
return new app.$web3.eth.Contract(
require('./../contract-abi/OctobayGovToken.json').abi,
address
)
},
},
})
} else {
/**
* Set web3 to null for non-web3 browsers (for some in-template checks to work)
*/
inject('web3', null)
}
}