diff --git a/src/components/BallotProxyMetadata.jsx b/src/components/BallotProxyMetadata.jsx index b7b7488..8a35cee 100644 --- a/src/components/BallotProxyMetadata.jsx +++ b/src/components/BallotProxyMetadata.jsx @@ -2,11 +2,26 @@ import React from 'react'; import { inject, observer } from "mobx-react"; import Select from 'react-select'; -@inject("ballotStore") +@inject("ballotStore", "contractsStore") @observer export class BallotProxyMetadata extends React.Component { render() { - const { ballotStore } = this.props; + const { ballotStore, contractsStore } = this.props; + let options = [ + /*0*/ { value: '', label: '' }, + /*1*/ { value: '1', label: ballotStore.ProxyBallotType[1] }, // KeysManager + /*2*/ { value: '2', label: ballotStore.ProxyBallotType[2] }, // VotingToChangeKeys + /*3*/ { value: '3', label: ballotStore.ProxyBallotType[3] }, // VotingToChangeMinThreshold + /*4*/ { value: '4', label: ballotStore.ProxyBallotType[4] }, // VotingToChangeProxy + /*5*/ { value: '5', label: ballotStore.ProxyBallotType[5] }, // BallotsStorage + /*6*/ { value: '7', label: ballotStore.ProxyBallotType[7] }, // ValidatorMetadata + /*7*/ { value: '8', label: ballotStore.ProxyBallotType[8] }, // ProxyStorage + ]; + + if (!contractsStore.proxyStorage.doesMethodExist('getValidatorMetadata')) { + options.splice(6); // keep 0-5 and remove 6-... items if ProxyStorage is old + } + return (
@@ -24,20 +39,11 @@ export class BallotProxyMetadata extends React.Component {
- - ballotStore.changeBallotMetadata(e, "contractType", "ballotProxy")} - options={[ - { value: '', label: '' }, - { value: '1', label: ballotStore.ProxyBallotType[1] }, - { value: '2', label: ballotStore.ProxyBallotType[2] }, - { value: '3', label: ballotStore.ProxyBallotType[3] }, - { value: '4', label: ballotStore.ProxyBallotType[4] }, - { value: '5', label: ballotStore.ProxyBallotType[5] }, - { value: '7', label: ballotStore.ProxyBallotType[7] }, - { value: '8', label: ballotStore.ProxyBallotType[8] }, - ]} + options={options} >

diff --git a/src/constants.js b/src/constants.js index edd6858..669e50b 100644 --- a/src/constants.js +++ b/src/constants.js @@ -6,6 +6,7 @@ constants.ABIsSources = { 'KeysManager': 'KeysManager.abi.json', 'PoaNetworkConsensus': 'PoaNetworkConsensus.abi.json', 'BallotStorage': 'BallotsStorage.abi.json', + 'ProxyStorage': 'ProxyStorage.abi.json', 'ValidatorMetadata': 'ValidatorMetadata.abi.json', 'VotingToChangeKeys': 'VotingToChangeKeys.abi.json', 'VotingToChangeMinThreshold': 'VotingToChangeMinThreshold.abi.json', diff --git a/src/contracts/ProxyStorage.contract.js b/src/contracts/ProxyStorage.contract.js new file mode 100644 index 0000000..bf66955 --- /dev/null +++ b/src/contracts/ProxyStorage.contract.js @@ -0,0 +1,20 @@ +import Web3 from 'web3'; +import { networkAddresses } from './addresses'; +import helpers from "./helpers"; + +export default class ProxyStorage { + async init({web3, netId}){ + const {PROXY_ADDRESS} = networkAddresses(netId); + console.log('Proxy Storage address', PROXY_ADDRESS); + let web3_10 = new Web3(web3.currentProvider); + const branch = helpers.getBranch(netId); + + let proxyStorageAbi = await helpers.getABI(branch, 'ProxyStorage') + + this.proxyStorageInstance = new web3_10.eth.Contract(proxyStorageAbi, PROXY_ADDRESS); + } + + doesMethodExist(methodName) { + return this.proxyStorageInstance && this.proxyStorageInstance.methods[methodName]; + } +} \ No newline at end of file diff --git a/src/contracts/VotingToChangeKeys.contract.js b/src/contracts/VotingToChangeKeys.contract.js index d0ab019..80df2c2 100644 --- a/src/contracts/VotingToChangeKeys.contract.js +++ b/src/contracts/VotingToChangeKeys.contract.js @@ -18,7 +18,13 @@ export default class VotingToChangeKeys { //setters createBallot({startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, sender, memo}) { - return this.votingToChangeKeysInstance.methods.createBallot(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo).send({from: sender, gasPrice: this.gasPrice}); + let method; + if (this.votingToChangeKeysInstance.methods.createBallot) { + method = this.votingToChangeKeysInstance.methods.createBallot; + } else { + method = this.votingToChangeKeysInstance.methods.createVotingForKeys; + } + return method(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo).send({from: sender, gasPrice: this.gasPrice}); } createBallotToAddNewValidator({startTime, endTime, affectedKey, newVotingKey, newPayoutKey, sender, memo}) { diff --git a/src/contracts/VotingToChangeMinThreshold.contract.js b/src/contracts/VotingToChangeMinThreshold.contract.js index acafc97..e8198b9 100644 --- a/src/contracts/VotingToChangeMinThreshold.contract.js +++ b/src/contracts/VotingToChangeMinThreshold.contract.js @@ -18,7 +18,13 @@ export default class VotingToChangeMinThreshold { //setters createBallot({startTime, endTime, proposedValue, sender, memo}) { - return this.votingToChangeMinThresholdInstance.methods.createBallot(startTime, endTime, proposedValue, memo).send({from: sender, gasPrice: this.gasPrice}) + let method; + if (this.votingToChangeMinThresholdInstance.methods.createBallot) { + method = this.votingToChangeMinThresholdInstance.methods.createBallot; + } else { + method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold; + } + return method(startTime, endTime, proposedValue, memo).send({from: sender, gasPrice: this.gasPrice}) } vote(_id, choice, sender) { diff --git a/src/contracts/VotingToChangeProxy.contract.js b/src/contracts/VotingToChangeProxy.contract.js index e7b2ce9..c46ddd9 100644 --- a/src/contracts/VotingToChangeProxy.contract.js +++ b/src/contracts/VotingToChangeProxy.contract.js @@ -18,7 +18,13 @@ export default class VotingToChangeProxy { //setters createBallot({startTime, endTime, proposedValue, contractType, sender, memo}) { - return this.votingToChangeProxyInstance.methods.createBallot(startTime, endTime, proposedValue, contractType, memo).send({from: sender, gasPrice: this.gasPrice}) + let method; + if (this.votingToChangeProxyInstance.methods.createBallot) { + method = this.votingToChangeProxyInstance.methods.createBallot; + } else { + method = this.votingToChangeProxyInstance.methods.createBallotToChangeProxyAddress; + } + return method(startTime, endTime, proposedValue, contractType, memo).send({from: sender, gasPrice: this.gasPrice}) } vote(_id, choice, sender) { diff --git a/src/index.js b/src/index.js index 9c01c16..e770c7b 100644 --- a/src/index.js +++ b/src/index.js @@ -41,12 +41,21 @@ class AppMainRouter extends Component { let setPoaConsensus = contractsStore.setPoaConsensus(web3Config); let setBallotsStorage = contractsStore.setBallotsStorage(web3Config); + let setProxyStorage = contractsStore.setProxyStorage(web3Config); let setVotingToChangeKeys = contractsStore.setVotingToChangeKeys(web3Config); let setVotingToChangeMinThreshold = contractsStore.setVotingToChangeMinThreshold(web3Config); let setVotingToChangeProxy = contractsStore.setVotingToChangeProxy(web3Config); let setValidatorMetadata = contractsStore.setValidatorMetadata(web3Config); - await Promise.all([setPoaConsensus, setBallotsStorage, setVotingToChangeKeys, setVotingToChangeMinThreshold, setVotingToChangeProxy, setValidatorMetadata]) + await Promise.all([ + setPoaConsensus, + setBallotsStorage, + setProxyStorage, + setVotingToChangeKeys, + setVotingToChangeMinThreshold, + setVotingToChangeProxy, + setValidatorMetadata + ]); await contractsStore.setMiningKey(web3Config); await contractsStore.setVotingKey(web3Config); diff --git a/src/stores/ContractsStore.js b/src/stores/ContractsStore.js index ef76906..bb6de38 100644 --- a/src/stores/ContractsStore.js +++ b/src/stores/ContractsStore.js @@ -3,6 +3,7 @@ import React from 'react'; import PoaConsensus from '../contracts/PoaConsensus.contract' import BallotsStorage from '../contracts/BallotsStorage.contract' +import ProxyStorage from '../contracts/ProxyStorage.contract' import VotingToChangeKeys from '../contracts/VotingToChangeKeys.contract' import VotingToChangeMinThreshold from '../contracts/VotingToChangeMinThreshold.contract' import VotingToChangeProxy from '../contracts/VotingToChangeProxy.contract' @@ -20,6 +21,7 @@ import "babel-polyfill"; class ContractsStore { @observable poaConsensus; @observable ballotsStorage; + @observable proxyStorage; @observable votingToChangeKeys; @observable votingToChangeMinThreshold; @observable votingToChangeProxy; @@ -85,6 +87,15 @@ class ContractsStore { }); } + @action("Set ProxyStorage contract") + setProxyStorage = async (web3Config) => { + this.proxyStorage = new ProxyStorage(); + await this.proxyStorage.init({ + web3: web3Config.web3Instance, + netId: web3Config.netId + }); + } + @action("Set VotingToChangeKeys contract") setVotingToChangeKeys = async (web3Config) => { this.votingToChangeKeys = new VotingToChangeKeys();