(Fix) Use web3 1.0 by default

This commit is contained in:
Vadim Arasev 2018-10-11 12:02:47 +03:00
parent 3564270dcb
commit b088f0a26f
16 changed files with 108 additions and 145 deletions

View File

@ -7,7 +7,7 @@ import { BallotCard } from './BallotCard.jsx'
export class BallotEmissionFundsCard extends React.Component {
render() {
const { id, votingState, pos, contractsStore } = this.props
const amount = contractsStore.web3Instance.fromWei(votingState.amount, 'ether')
const amount = contractsStore.web3Instance.utils.fromWei(votingState.amount, 'ether')
return (
<BallotCard votingType="votingToManageEmissionFunds" votingState={votingState} id={id} pos={pos}>
<div className="ballots-about-i ballots-about-i_proposed_receiver">

View File

@ -16,7 +16,7 @@ export class BallotEmissionFundsMetadata extends React.Component {
getEmissionFundsBalance = async () => {
const { contractsStore } = this.props
this.emissionFundsBalance =
contractsStore.web3Instance.fromWei(await contractsStore.emissionFunds.balance(), 'ether') + ' POA'
contractsStore.web3Instance.utils.fromWei(await contractsStore.emissionFunds.balance(), 'ether') + ' POA'
}
@action('Get VotingToManageEmissionFunds.noActiveBallotExists')

View File

@ -100,7 +100,7 @@ export class NewBallot extends React.Component {
}
}
let isAffectedKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.affectedKey)
let isAffectedKeyAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotKeys.affectedKey)
if (!isAffectedKeyAddress) {
swal('Warning!', messages.AFFECTED_KEY_IS_NOT_ADDRESS_MSG, 'warning')
@ -108,7 +108,7 @@ export class NewBallot extends React.Component {
return false
}
let isMiningKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.miningKey.value)
let isMiningKeyAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotKeys.miningKey.value)
if (!isMiningKeyAddress) {
swal('Warning!', messages.MINING_KEY_IS_NOT_ADDRESS_MSG, 'warning')
commonStore.hideLoading()
@ -135,7 +135,7 @@ export class NewBallot extends React.Component {
}
}
const isAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotProxy.proposedAddress)
const isAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotProxy.proposedAddress)
if (!isAddress) {
swal('Warning!', messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, 'warning')
@ -151,7 +151,7 @@ export class NewBallot extends React.Component {
return false
}
const isAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotEmissionFunds.receiver)
const isAddress = contractsStore.web3Instance.utils.isAddress(ballotStore.ballotEmissionFunds.receiver)
if (!isAddress) {
swal('Warning!', messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, 'warning')
@ -320,17 +320,17 @@ export class NewBallot extends React.Component {
case ballotStore.BallotType.keys:
methodToCreateBallot = this.createBallotForKeys
contractType = 'votingToChangeKeys'
contractInstance = contractsStore.votingToChangeKeys.votingToChangeKeysInstance
contractInstance = contractsStore.votingToChangeKeys.instance
break
case ballotStore.BallotType.minThreshold:
methodToCreateBallot = this.createBallotForMinThreshold
contractType = 'votingToChangeMinThreshold'
contractInstance = contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance
contractInstance = contractsStore.votingToChangeMinThreshold.instance
break
case ballotStore.BallotType.proxy:
methodToCreateBallot = this.createBallotForProxy
contractType = 'votingToChangeProxy'
contractInstance = contractsStore.votingToChangeProxy.votingToChangeProxyInstance
contractInstance = contractsStore.votingToChangeProxy.instance
break
case ballotStore.BallotType.emissionFunds:
methodToCreateBallot = this.createBallotForEmissionFunds

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,19 +6,16 @@ export default class BallotsStorage {
async init({ web3, netId }) {
const { BALLOTS_STORAGE_ADDRESS } = networkAddresses()
console.log('Ballots Storage address', BALLOTS_STORAGE_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const ballotsStorageAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'BallotStorage')
this.ballotsStorageInstance = new web3_10.eth.Contract(ballotsStorageAbi, BALLOTS_STORAGE_ADDRESS)
this.instance = new web3.eth.Contract(ballotsStorageAbi, BALLOTS_STORAGE_ADDRESS)
}
areKeysBallotParamsValid({ ballotType, affectedKeyType, affectedKey, miningKey }) {
if (!this.ballotsStorageInstance.methods.areKeysBallotParamsValid) {
if (!this.instance.methods.areKeysBallotParamsValid) {
return null
}
return this.ballotsStorageInstance.methods
.areKeysBallotParamsValid(ballotType, affectedKeyType, affectedKey, miningKey)
.call()
return this.instance.methods.areKeysBallotParamsValid(ballotType, affectedKeyType, affectedKey, miningKey).call()
}
}

View File

@ -1,15 +1,14 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
export default class EmissionFunds {
async init({ web3, netId }) {
const { EMISSION_FUNDS_ADDRESS } = networkAddresses()
console.log('EmissionFunds address', EMISSION_FUNDS_ADDRESS)
this.web3_10 = new Web3(web3.currentProvider)
this.web3 = web3
this.address = EMISSION_FUNDS_ADDRESS
}
balance() {
return this.web3_10.eth.getBalance(this.address)
return this.web3.eth.getBalance(this.address)
}
}

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,11 +6,10 @@ export default class KeysManager {
async init({ web3, netId }) {
const { KEYS_MANAGER_ADDRESS } = networkAddresses()
console.log('KeysManager address', KEYS_MANAGER_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const keysManagerABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'KeysManager')
this.instance = new web3_10.eth.Contract(keysManagerABI, KEYS_MANAGER_ADDRESS)
this.instance = new web3.eth.Contract(keysManagerABI, KEYS_MANAGER_ADDRESS)
this.address = KEYS_MANAGER_ADDRESS
}
}

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,14 +6,13 @@ export default class PoaConsensus {
async init({ web3, netId }) {
const { POA_ADDRESS } = networkAddresses()
console.log('POA address', POA_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const poaConsensusAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'PoaNetworkConsensus')
this.poaInstance = new web3_10.eth.Contract(poaConsensusAbi, POA_ADDRESS)
this.instance = new web3.eth.Contract(poaConsensusAbi, POA_ADDRESS)
}
async getValidators() {
return await this.poaInstance.methods.getValidators().call()
return await this.instance.methods.getValidators().call()
}
}

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,14 +6,13 @@ export default class ProxyStorage {
async init({ web3, netId }) {
const { PROXY_ADDRESS } = networkAddresses()
console.log('Proxy Storage address', PROXY_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const proxyStorageAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'ProxyStorage')
this.proxyStorageInstance = new web3_10.eth.Contract(proxyStorageAbi, PROXY_ADDRESS)
this.instance = new web3.eth.Contract(proxyStorageAbi, PROXY_ADDRESS)
}
doesMethodExist(methodName) {
return this.proxyStorageInstance && this.proxyStorageInstance.methods[methodName]
return this.instance && this.instance.methods[methodName]
}
}

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { toAscii } from '../helpers'
@ -8,19 +7,18 @@ export default class ValidatorMetadata {
async init({ web3, netId }) {
const { METADATA_ADDRESS } = networkAddresses()
console.log('Metadata address', METADATA_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const MetadataAbi = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'ValidatorMetadata')
this.metadataInstance = new web3_10.eth.Contract(MetadataAbi, METADATA_ADDRESS)
this.instance = new web3.eth.Contract(MetadataAbi, METADATA_ADDRESS)
}
async getValidatorFullName(miningKey) {
let validator
if (this.metadataInstance.methods.getValidatorName) {
validator = await this.metadataInstance.methods.getValidatorName(miningKey).call()
if (this.instance.methods.getValidatorName) {
validator = await this.instance.methods.getValidatorName(miningKey).call()
} else {
validator = await this.metadataInstance.methods.validators(miningKey).call()
validator = await this.instance.methods.validators(miningKey).call()
}
return {
firstName: toAscii(validator.firstName),

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,40 +6,37 @@ export default class VotingToChangeKeys {
async init({ web3, netId }) {
const { VOTING_TO_CHANGE_KEYS_ADDRESS } = networkAddresses()
console.log('VotingToChangeKeys address', VOTING_TO_CHANGE_KEYS_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToChangeKeysABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'VotingToChangeKeys')
this.votingToChangeKeysInstance = new web3_10.eth.Contract(votingToChangeKeysABI, VOTING_TO_CHANGE_KEYS_ADDRESS)
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
this.instance = new web3.eth.Contract(votingToChangeKeysABI, VOTING_TO_CHANGE_KEYS_ADDRESS)
this.address = VOTING_TO_CHANGE_KEYS_ADDRESS
this.instance = this.votingToChangeKeysInstance
}
//setters
createBallot({ startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo }) {
if (this.votingToChangeKeysInstance.methods.createBallot) {
return this.votingToChangeKeysInstance.methods
if (this.instance.methods.createBallot) {
return this.instance.methods
.createBallot(startTime, endTime, ballotType, affectedKeyType, memo, affectedKey, miningKey)
.encodeABI()
}
return this.votingToChangeKeysInstance.methods
return this.instance.methods
.createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo)
.encodeABI()
}
createBallotToAddNewValidator({ startTime, endTime, memo, affectedKey, newVotingKey, newPayoutKey }) {
return this.votingToChangeKeysInstance.methods
return this.instance.methods
.createBallotToAddNewValidator(startTime, endTime, memo, affectedKey, newVotingKey, newPayoutKey)
.encodeABI()
}
vote(_id, choice) {
return this.votingToChangeKeysInstance.methods.vote(_id, choice).encodeABI()
return this.instance.methods.vote(_id, choice).encodeABI()
}
finalize(_id) {
return this.votingToChangeKeysInstance.methods.finalize(_id).encodeABI()
return this.instance.methods.finalize(_id).encodeABI()
}
//getters
@ -48,47 +44,45 @@ export default class VotingToChangeKeys {
if (!this.doesMethodExist('areBallotParamsValid')) {
return null
}
return this.votingToChangeKeysInstance.methods
.areBallotParamsValid(ballotType, affectedKey, affectedKeyType, miningKey)
.call()
return this.instance.methods.areBallotParamsValid(ballotType, affectedKey, affectedKeyType, miningKey).call()
}
doesMethodExist(methodName) {
return this.votingToChangeKeysInstance && this.votingToChangeKeysInstance.methods[methodName]
return this.instance && this.instance.methods[methodName]
}
nextBallotId() {
return this.votingToChangeKeysInstance.methods.nextBallotId().call()
return this.instance.methods.nextBallotId().call()
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeKeysInstance.methods.getBallotInfo(_id).call()
return this.instance.methods.getBallotInfo(_id).call()
}
return this.votingToChangeKeysInstance.methods.votingState(_id).call()
return this.instance.methods.votingState(_id).call()
}
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeKeysInstance.methods.hasAlreadyVoted(_id, votingKey).call()
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
}
isValidVote(_id, votingKey) {
return this.votingToChangeKeysInstance.methods.isValidVote(_id, votingKey).call()
return this.instance.methods.isValidVote(_id, votingKey).call()
}
isActive(_id) {
return this.votingToChangeKeysInstance.methods.isActive(_id).call()
return this.instance.methods.isActive(_id).call()
}
canBeFinalizedNow(_id) {
if (this.doesMethodExist('canBeFinalizedNow')) {
return this.votingToChangeKeysInstance.methods.canBeFinalizedNow(_id).call()
return this.instance.methods.canBeFinalizedNow(_id).call()
}
return null
}
async getBallotLimit(_miningKey, _limitPerValidator) {
const _activeBallots = await this.votingToChangeKeysInstance.methods.validatorActiveBallots(_miningKey).call()
const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
return _limitPerValidator - _activeBallots
}
}

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,83 +6,75 @@ export default class VotingToChangeMinThreshold {
async init({ web3, netId }) {
const { VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS } = networkAddresses()
console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToChangeMinThresholdABI = await helpers.getABI(
constants.NETWORKS[netId].BRANCH,
'VotingToChangeMinThreshold'
)
this.votingToChangeMinThresholdInstance = new web3_10.eth.Contract(
votingToChangeMinThresholdABI,
VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
)
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
this.instance = new web3.eth.Contract(votingToChangeMinThresholdABI, VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS)
this.address = VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
this.instance = this.votingToChangeMinThresholdInstance
}
//setters
createBallot({ startTime, endTime, proposedValue, memo }) {
let method
if (this.votingToChangeMinThresholdInstance.methods.createBallot) {
method = this.votingToChangeMinThresholdInstance.methods.createBallot
if (this.instance.methods.createBallot) {
method = this.instance.methods.createBallot
} else {
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold
method = this.instance.methods.createBallotToChangeThreshold
}
return method(startTime, endTime, proposedValue, memo).encodeABI()
}
vote(_id, choice) {
return this.votingToChangeMinThresholdInstance.methods.vote(_id, choice).encodeABI()
return this.instance.methods.vote(_id, choice).encodeABI()
}
finalize(_id) {
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).encodeABI()
return this.instance.methods.finalize(_id).encodeABI()
}
//getters
doesMethodExist(methodName) {
if (this.votingToChangeMinThresholdInstance.methods[methodName]) {
if (this.instance.methods[methodName]) {
return true
}
return false
}
nextBallotId() {
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call()
return this.instance.methods.nextBallotId().call()
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call()
return this.instance.methods.getBallotInfo(_id, _votingKey).call()
}
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call()
return this.instance.methods.votingState(_id).call()
}
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.hasAlreadyVoted(_id, votingKey).call()
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
}
isValidVote(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call()
return this.instance.methods.isValidVote(_id, votingKey).call()
}
isActive(_id) {
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call()
return this.instance.methods.isActive(_id).call()
}
canBeFinalizedNow(_id) {
if (this.doesMethodExist('canBeFinalizedNow')) {
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call()
return this.instance.methods.canBeFinalizedNow(_id).call()
}
return null
}
async getBallotLimit(_miningKey, _limitPerValidator) {
const _activeBallots = await this.votingToChangeMinThresholdInstance.methods
.validatorActiveBallots(_miningKey)
.call()
const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
return _limitPerValidator - _activeBallots
}
}

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,76 +6,71 @@ export default class VotingToChangeProxy {
async init({ web3, netId }) {
const { VOTING_TO_CHANGE_PROXY_ADDRESS } = networkAddresses()
console.log('VotingToChangeProxy address', VOTING_TO_CHANGE_PROXY_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToChangeProxyABI = await helpers.getABI(constants.NETWORKS[netId].BRANCH, 'VotingToChangeProxyAddress')
this.votingToChangeProxyInstance = new web3_10.eth.Contract(votingToChangeProxyABI, VOTING_TO_CHANGE_PROXY_ADDRESS)
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
this.instance = new web3.eth.Contract(votingToChangeProxyABI, VOTING_TO_CHANGE_PROXY_ADDRESS)
this.address = VOTING_TO_CHANGE_PROXY_ADDRESS
this.instance = this.votingToChangeProxyInstance
}
//setters
createBallot({ startTime, endTime, proposedValue, contractType, memo }) {
if (!this.votingToChangeProxyInstance.methods.createBallot) {
return this.votingToChangeProxyInstance.methods
if (!this.instance.methods.createBallot) {
return this.instance.methods
.createBallotToChangeProxyAddress(startTime, endTime, proposedValue, contractType, memo)
.encodeABI()
}
return this.votingToChangeProxyInstance.methods
.createBallot(startTime, endTime, contractType, memo, proposedValue)
.encodeABI()
return this.instance.methods.createBallot(startTime, endTime, contractType, memo, proposedValue).encodeABI()
}
vote(_id, choice) {
return this.votingToChangeProxyInstance.methods.vote(_id, choice).encodeABI()
return this.instance.methods.vote(_id, choice).encodeABI()
}
finalize(_id) {
return this.votingToChangeProxyInstance.methods.finalize(_id).encodeABI()
return this.instance.methods.finalize(_id).encodeABI()
}
//getters
doesMethodExist(methodName) {
if (this.votingToChangeProxyInstance.methods[methodName]) {
if (this.instance.methods[methodName]) {
return true
}
return false
}
nextBallotId() {
return this.votingToChangeProxyInstance.methods.nextBallotId().call()
return this.instance.methods.nextBallotId().call()
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeProxyInstance.methods.getBallotInfo(_id, _votingKey).call()
return this.instance.methods.getBallotInfo(_id, _votingKey).call()
}
return this.votingToChangeProxyInstance.methods.votingState(_id).call()
return this.instance.methods.votingState(_id).call()
}
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeProxyInstance.methods.hasAlreadyVoted(_id, votingKey).call()
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
}
isValidVote(_id, votingKey) {
return this.votingToChangeProxyInstance.methods.isValidVote(_id, votingKey).call()
return this.instance.methods.isValidVote(_id, votingKey).call()
}
isActive(_id) {
return this.votingToChangeProxyInstance.methods.isActive(_id).call()
return this.instance.methods.isActive(_id).call()
}
canBeFinalizedNow(_id) {
if (this.doesMethodExist('canBeFinalizedNow')) {
return this.votingToChangeProxyInstance.methods.canBeFinalizedNow(_id).call()
return this.instance.methods.canBeFinalizedNow(_id).call()
}
return null
}
async getBallotLimit(_miningKey, _limitPerValidator) {
const _activeBallots = await this.votingToChangeProxyInstance.methods.validatorActiveBallots(_miningKey).call()
const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
return _limitPerValidator - _activeBallots
}
}

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { constants } from '../constants'
@ -7,14 +6,13 @@ export default class VotingToManageEmissionFunds {
async init({ web3, netId }) {
const { VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS } = networkAddresses()
console.log('VotingToManageEmissionFunds address', VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS)
const web3_10 = new Web3(web3.currentProvider)
const votingToManageEmissionFundsABI = await helpers.getABI(
constants.NETWORKS[netId].BRANCH,
'VotingToManageEmissionFunds'
)
this.instance = new web3_10.eth.Contract(votingToManageEmissionFundsABI, VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS)
this.instance = new web3.eth.Contract(votingToManageEmissionFundsABI, VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS)
this.address = VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS
}

View File

@ -1,3 +1,4 @@
import Web3 from 'web3'
import { messages } from './messages'
import { constants } from './constants'
@ -9,7 +10,7 @@ let getWeb3 = () => {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (window.ethereum) {
web3 = new window.Web3(window.ethereum)
web3 = new Web3(window.ethereum)
console.log('Injected web3 detected.')
try {
await window.ethereum.enable()
@ -19,7 +20,7 @@ let getWeb3 = () => {
return
}
} else if (typeof window.web3 !== 'undefined') {
web3 = new window.Web3(window.web3.currentProvider)
web3 = new Web3(window.web3.currentProvider)
console.log('Injected web3 detected.')
} else {
console.error('Metamask not found')
@ -27,40 +28,41 @@ let getWeb3 = () => {
return
}
web3.version.getNetwork((err, netId) => {
let netIdName
let errorMsg = null
const netId = await web3.eth.net.getId()
console.log('netId', netId)
console.log('netId', netId)
let netIdName
let errorMsg = null
if (netId in constants.NETWORKS) {
netIdName = constants.NETWORKS[netId].NAME
console.log(`This is ${netIdName}`)
} else {
netIdName = 'ERROR'
errorMsg = messages.WRONG_NETWORK_MSG
console.log('This is an unknown network.')
}
if (netId in constants.NETWORKS) {
netIdName = constants.NETWORKS[netId].NAME
console.log(`This is ${netIdName}`)
} else {
netIdName = 'ERROR'
errorMsg = messages.WRONG_NETWORK_MSG
console.log('This is an unknown network.')
}
document.title = `${netIdName} - POA Network Governance DApp`
document.title = `${netIdName} - POA Network Governance DApp`
if (errorMsg !== null) {
reject({ message: errorMsg })
return
}
if (errorMsg !== null) {
reject({ message: errorMsg })
return
}
var defaultAccount = web3.eth.defaultAccount || null
if (defaultAccount === null) {
reject({ message: messages.NO_METAMASK_MSG })
return
}
const accounts = await web3.eth.getAccounts()
resolve({
web3Instance: web3,
netIdName,
netId,
defaultAccount
})
var defaultAccount = accounts[0] || null
if (defaultAccount === null) {
reject({ message: messages.NO_METAMASK_MSG })
return
}
resolve({
web3Instance: web3,
netIdName,
netId,
defaultAccount
})
})
})

View File

@ -1,4 +1,3 @@
import Web3 from 'web3'
import swal from 'sweetalert2'
import { constants } from './constants'
@ -23,7 +22,7 @@ function sleep(ms) {
function sendTransactionByVotingKey(props, to, data, cb, warning) {
const { commonStore, contractsStore } = props
const web3 = new Web3(contractsStore.web3Instance.currentProvider)
const web3 = contractsStore.web3Instance
web3.eth.sendTransaction(
{

View File

@ -61,13 +61,13 @@ class ContractsStore {
@action('Get keys ballot threshold')
getKeysBallotThreshold = async () => {
this.keysBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getBallotThreshold(1).call()
this.keysBallotThreshold = await this.ballotsStorage.instance.methods.getBallotThreshold(1).call()
this.minThresholdBallotThreshold = this.keysBallotThreshold
}
@action('Get proxy ballot threshold')
getProxyBallotThreshold = async () => {
this.proxyBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getProxyThreshold().call()
this.proxyBallotThreshold = await this.ballotsStorage.instance.methods.getProxyThreshold().call()
this.emissionFundsBallotThreshold = this.proxyBallotThreshold
}
@ -176,7 +176,7 @@ class ContractsStore {
@action('Get validators length')
getValidatorsLength = async () => {
this.validatorsLength = await this.poaConsensus.poaInstance.methods.getCurrentValidatorsLength().call()
this.validatorsLength = await this.poaConsensus.instance.methods.getCurrentValidatorsLength().call()
}
@action('Set voting key')
@ -389,9 +389,7 @@ class ContractsStore {
@action
async getBallotsLimits() {
if (this.web3Instance && this.netId) {
const limitPerValidator = await this.ballotsStorage.ballotsStorageInstance.methods
.getBallotLimitPerValidator()
.call()
const limitPerValidator = await this.ballotsStorage.instance.methods.getBallotLimitPerValidator().call()
let getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.miningKey, limitPerValidator)
let getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(this.miningKey, limitPerValidator)