Skip to content

Instantly share code, notes, and snippets.

@kyriediculous
Last active April 11, 2019 19:42
Show Gist options
  • Save kyriediculous/68dd0da2781519a1e1f37923a4fb9f94 to your computer and use it in GitHub Desktop.
Save kyriediculous/68dd0da2781519a1e1f37923a4fb9f94 to your computer and use it in GitHub Desktop.
import Web3 from 'web3'
import {store} from '../store/'
let pollWeb3 = function (state) {
let web3 = window.web3
web3 = new Web3(web3.currentProvider)
setInterval(() => {
if (web3 && store.state.web3.web3Instance) {
if (web3.eth.coinbase !== store.state.web3.coinbase) {
let newCoinbase = web3.eth.coinbase
web3.eth.getBalance(web3.eth.coinbase, function (err, newBalance) {
if (err) {
console.log(err)
} else {
store.dispatch('pollWeb3', {
coinbase: newCoinbase,
balance: parseInt(newBalance, 10)
})
}
})
} else {
web3.eth.getBalance(store.state.web3.coinbase, (err, polledBalance) => {
if (err) {
console.log(err)
} else if (parseInt(polledBalance, 10) !== store.state.web3.balance) {
store.dispatch('pollWeb3', {
coinbase: store.state.web3.coinbase,
balance: polledBalance
})
}
})
}
}
}, 500)
}
export default pollWeb3
@stadja
Copy link

stadja commented Apr 11, 2019

Hello, I don't understand the line 6 ?
I think that now, we don't have to do the web3 = new Web3(web3.currentProvider) anymore...
am i right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment