update provider

This commit is contained in:
Danil Kovtonyuk 2020-11-05 20:17:59 +10:00
parent 3739a32448
commit d4f872010e
5 changed files with 25 additions and 6 deletions

View File

@ -23,7 +23,7 @@
background-color: #559774;
&:hover {
background-color: #94febf;
background-color: $primary;
}
&[disabled] {

View File

@ -63,7 +63,7 @@ export default {
},
},
methods: {
async _web3Connect(name, network = 'mainnet') {
async _web3Connect(name, network) {
this.$store.dispatch('loading/enable', {})
try {
await this.$store.dispatch(
@ -71,6 +71,7 @@ export default {
{ name, network },
{ root: true }
)
this.$store.dispatch('steps/fetchDeploymentStatus', {})
} catch (e) {
console.error(e)
}

View File

@ -1,3 +1,4 @@
import networkConfig from '@/networkConfig'
import { Provider } from '../services'
const MAIN_NET_ID = 1
@ -7,6 +8,7 @@ const options = {
config: {
id: MAIN_NET_ID,
rpcCallRetryAttempt: 15,
rpcUrl: networkConfig.netId1.rpcUrl,
blockGasLimit: MAIN_NET_BLOCK_GAS_LIMIT,
},
}

View File

@ -8,6 +8,7 @@ class Provider {
* @param options {object}
* @param {object} options.config
* @param {number} options.config.id
* @param {string} options.config.rpcUrl
* @param {number} options.config.rpcCallRetryAttempt
* @param {object} options.provider
* @param {string} options.rpcUrl - node api endpoint.
@ -18,6 +19,7 @@ class Provider {
this.version = 'new'
this.config = options.config
this.web3 = new Web3(new Web3.providers.HttpProvider(options.rpcUrl))
}
async initProvider(provider) {
@ -227,6 +229,19 @@ class Provider {
}
}
/**
* Subscribe to event in provider.
*
* @param method {string}
* @param {function} callback
* @returns {*}
*/
on(method, callback) {
if (method) {
this.provider.on(method, callback)
}
}
/**
* Send a request to the provider (old api).
*
@ -291,9 +306,12 @@ class Provider {
* @param {string} params.id.
* @returns {*}
*/
_onNetworkChanged({ id }) {
_onNetworkChanged({ id, callback }) {
if (id) {
this.network = id
if (typeof callback === 'function') {
callback()
}
window.location.reload()
}
}

View File

@ -1,5 +1,4 @@
/* eslint-disable no-console */
import Web3 from 'web3'
import { hexToNumber, numberToHex } from 'web3-utils'
import deployerABI from '../abi/deployer.abi.json'
import deploymentActions from '../static/deploymentActions.json'
@ -10,8 +9,7 @@ const state = () => {
const getters = {
deployerContract: (state, getters, rootState, rootGetters) => (isProxy) => {
const { rpcUrls } = rootGetters['provider/getNetwork']
const web3 = new Web3(rpcUrls.Infura.url)
const web3 = rootGetters['provider/getWeb3']
return new web3.eth.Contract(
deployerABI,
isProxy