(Fix) Replace on('receipt') with web3.eth.sendTransaction
This commit is contained in:
parent
11be1a8944
commit
5ce6716cf3
|
@ -1,452 +1,530 @@
|
|||
import React from "react";
|
||||
import moment from "moment";
|
||||
import { observable, action, computed } from "mobx";
|
||||
import { inject, observer } from "mobx-react";
|
||||
import { messages } from "../messages";
|
||||
import swal from "sweetalert2";
|
||||
import Web3 from 'web3'
|
||||
import React from 'react'
|
||||
import moment from 'moment'
|
||||
import { observable, action, computed } from 'mobx'
|
||||
import { inject, observer } from 'mobx-react'
|
||||
import { messages } from '../messages'
|
||||
import { constants } from '../constants'
|
||||
import { sleep } from '../helpers'
|
||||
import swal from 'sweetalert2'
|
||||
|
||||
const ACCEPT = 1;
|
||||
const REJECT = 2;
|
||||
const USDateTimeFormat = "MM/DD/YYYY h:mm:ss A";
|
||||
const ACCEPT = 1
|
||||
const REJECT = 2
|
||||
const USDateTimeFormat = 'MM/DD/YYYY h:mm:ss A'
|
||||
|
||||
const zeroTimeTo = "00:00";
|
||||
const zeroTimeTo = '00:00'
|
||||
|
||||
@inject("commonStore", "contractsStore", "routing", "ballotsStore")
|
||||
@inject('commonStore', 'contractsStore', 'routing', 'ballotsStore')
|
||||
@observer
|
||||
export class BallotCard extends React.Component {
|
||||
@observable startTime;
|
||||
@observable endTime;
|
||||
@observable timeTo = {};
|
||||
@observable timeToStart = {
|
||||
val: 0,
|
||||
displayValue: zeroTimeTo,
|
||||
title: "To start"
|
||||
};
|
||||
@observable timeToFinish = {
|
||||
val: 0,
|
||||
displayValue: zeroTimeTo,
|
||||
title: "To close"
|
||||
};
|
||||
@observable creatorMiningKey;
|
||||
@observable creator;
|
||||
@observable progress;
|
||||
@observable totalVoters;
|
||||
@observable isFinalized;
|
||||
@observable canBeFinalized;
|
||||
@observable hasAlreadyVoted;
|
||||
@observable memo;
|
||||
@observable startTime
|
||||
@observable endTime
|
||||
@observable timeTo = {}
|
||||
@observable
|
||||
timeToStart = {
|
||||
val: 0,
|
||||
displayValue: zeroTimeTo,
|
||||
title: 'To start'
|
||||
}
|
||||
@observable
|
||||
timeToFinish = {
|
||||
val: 0,
|
||||
displayValue: zeroTimeTo,
|
||||
title: 'To close'
|
||||
}
|
||||
@observable creatorMiningKey
|
||||
@observable creator
|
||||
@observable progress
|
||||
@observable totalVoters
|
||||
@observable isFinalized
|
||||
@observable canBeFinalized
|
||||
@observable hasAlreadyVoted
|
||||
@observable memo
|
||||
|
||||
@computed get finalizeButtonDisplayName() {
|
||||
const displayName = this.isFinalized ? "Finalized" : "Finalize ballot";
|
||||
return displayName;
|
||||
@computed
|
||||
get finalizeButtonDisplayName() {
|
||||
const displayName = this.isFinalized ? 'Finalized' : 'Finalize ballot'
|
||||
return displayName
|
||||
}
|
||||
|
||||
@computed
|
||||
get finalizeButtonClass() {
|
||||
const cls = this.isFinalized
|
||||
? 'ballots-footer-finalize ballots-footer-finalize-finalized'
|
||||
: 'ballots-footer-finalize'
|
||||
return cls
|
||||
}
|
||||
|
||||
@computed
|
||||
get finalizeDescription() {
|
||||
if (this.isFinalized) {
|
||||
return ''
|
||||
}
|
||||
let description = 'Finalization is available after ballot time is finished'
|
||||
if (this.canBeFinalized !== null) {
|
||||
description += ' or all validators are voted'
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
@computed
|
||||
get votesForNumber() {
|
||||
let votes = (this.totalVoters + this.progress) / 2
|
||||
if (isNaN(votes)) votes = 0
|
||||
return votes
|
||||
}
|
||||
|
||||
@computed
|
||||
get votesForPercents() {
|
||||
if (this.totalVoters <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
@computed get finalizeButtonClass () {
|
||||
const cls = this.isFinalized ? "ballots-footer-finalize ballots-footer-finalize-finalized" : "ballots-footer-finalize";
|
||||
return cls;
|
||||
let votesPercents = Math.round((this.votesForNumber / this.totalVoters) * 100)
|
||||
if (isNaN(votesPercents)) votesPercents = 0
|
||||
return votesPercents
|
||||
}
|
||||
|
||||
@computed
|
||||
get votesAgainstNumber() {
|
||||
let votes = (this.totalVoters - this.progress) / 2
|
||||
if (isNaN(votes)) votes = 0
|
||||
return votes
|
||||
}
|
||||
|
||||
@computed
|
||||
get votesAgainstPercents() {
|
||||
if (this.totalVoters <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
@computed get finalizeDescription () {
|
||||
if (this.isFinalized) {
|
||||
return '';
|
||||
}
|
||||
let description = 'Finalization is available after ballot time is finished';
|
||||
if (this.canBeFinalized !== null) {
|
||||
description += ' or all validators are voted';
|
||||
}
|
||||
return description;
|
||||
let votesPercents = Math.round((this.votesAgainstNumber / this.totalVoters) * 100)
|
||||
if (isNaN(votesPercents)) votesPercents = 0
|
||||
return votesPercents
|
||||
}
|
||||
|
||||
@action('Calculate time to start/finish')
|
||||
calcTimeTo = () => {
|
||||
const _now = moment()
|
||||
const start = moment.utc(this.startTime, USDateTimeFormat)
|
||||
const finish = moment.utc(this.endTime, USDateTimeFormat)
|
||||
let msStart = start.diff(_now)
|
||||
let msFinish = finish.diff(_now)
|
||||
|
||||
if (msStart > 0) {
|
||||
this.timeToStart.val = msStart + 5000
|
||||
this.timeToStart.displayValue = this.formatMs(msStart, ':mm:ss')
|
||||
return (this.timeTo = this.timeToStart)
|
||||
}
|
||||
|
||||
@computed get votesForNumber() {
|
||||
let votes = (this.totalVoters + this.progress) / 2;
|
||||
if (isNaN(votes))
|
||||
votes = 0;
|
||||
return votes;
|
||||
if (msFinish > 0) {
|
||||
this.timeToStart.val = 0
|
||||
this.timeToFinish.val = msFinish
|
||||
this.timeToFinish.displayValue = this.formatMs(msFinish, ':mm:ss')
|
||||
return (this.timeTo = this.timeToFinish)
|
||||
}
|
||||
|
||||
@computed get votesForPercents() {
|
||||
if (this.totalVoters <= 0) {
|
||||
return 0;
|
||||
}
|
||||
this.timeToFinish.val = 0
|
||||
this.timeToFinish.displayValue = zeroTimeTo
|
||||
return (this.timeTo = this.timeToFinish)
|
||||
}
|
||||
|
||||
let votesPercents = Math.round(this.votesForNumber / this.totalVoters * 100);
|
||||
if (isNaN(votesPercents))
|
||||
votesPercents = 0;
|
||||
return votesPercents;
|
||||
formatMs(ms, format) {
|
||||
let dur = moment.duration(ms)
|
||||
let hours = Math.floor(dur.asHours())
|
||||
hours = hours < 10 ? '0' + hours : hours
|
||||
let formattedMs = hours + moment.utc(ms).format(':mm:ss')
|
||||
return formattedMs
|
||||
}
|
||||
|
||||
@action('validator has already voted')
|
||||
getHasAlreadyVoted = async () => {
|
||||
const { contractsStore, id, votingType } = this.props
|
||||
let _hasAlreadyVoted = false
|
||||
try {
|
||||
_hasAlreadyVoted = await this.getContract(contractsStore, votingType).hasAlreadyVoted(
|
||||
id,
|
||||
contractsStore.votingKey
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(e.message)
|
||||
}
|
||||
this.hasAlreadyVoted = _hasAlreadyVoted
|
||||
}
|
||||
|
||||
isValidVote = async () => {
|
||||
const { contractsStore, id, votingType } = this.props
|
||||
let _isValidVote
|
||||
try {
|
||||
_isValidVote = await this.getContract(contractsStore, votingType).isValidVote(id, contractsStore.votingKey)
|
||||
} catch (e) {
|
||||
console.log(e.message)
|
||||
}
|
||||
return _isValidVote
|
||||
}
|
||||
|
||||
isActive = async () => {
|
||||
const { contractsStore, id, votingType } = this.props
|
||||
let _isActive = await this.repeatGetProperty(contractsStore, votingType, id, 'isActive', 0)
|
||||
return _isActive
|
||||
}
|
||||
|
||||
canBeFinalizedNow = async () => {
|
||||
const { contractsStore, id, votingType } = this.props
|
||||
let _canBeFinalizedNow = await this.repeatGetProperty(contractsStore, votingType, id, 'canBeFinalizedNow', 0)
|
||||
this.canBeFinalized = _canBeFinalizedNow
|
||||
}
|
||||
|
||||
vote = async ({ choice }) => {
|
||||
if (this.timeToStart.val > 0) {
|
||||
swal('Warning!', messages.ballotIsNotActiveMsg(this.timeTo.displayValue), 'warning')
|
||||
return
|
||||
}
|
||||
const { commonStore, contractsStore, id, votingType, ballotsStore, pos } = this.props
|
||||
const { push } = this.props.routing
|
||||
if (!contractsStore.isValidVotingKey) {
|
||||
swal('Warning!', messages.invalidVotingKeyMsg(contractsStore.votingKey), 'warning')
|
||||
return
|
||||
}
|
||||
commonStore.showLoading()
|
||||
let isValidVote = await this.isValidVote()
|
||||
if (!isValidVote) {
|
||||
commonStore.hideLoading()
|
||||
swal('Warning!', messages.INVALID_VOTE_MSG, 'warning')
|
||||
return
|
||||
}
|
||||
|
||||
@computed get votesAgainstNumber() {
|
||||
let votes = (this.totalVoters - this.progress) / 2;
|
||||
if (isNaN(votes))
|
||||
votes = 0;
|
||||
return votes;
|
||||
}
|
||||
const web3 = new Web3(contractsStore.web3Instance.currentProvider)
|
||||
const contract = this.getContract(contractsStore, votingType)
|
||||
|
||||
@computed get votesAgainstPercents() {
|
||||
if (this.totalVoters <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let votesPercents = Math.round(this.votesAgainstNumber / this.totalVoters * 100);
|
||||
if (isNaN(votesPercents))
|
||||
votesPercents = 0;
|
||||
return votesPercents;
|
||||
}
|
||||
|
||||
@action("Calculate time to start/finish")
|
||||
calcTimeTo = () => {
|
||||
const _now = moment();
|
||||
const start = moment.utc(this.startTime, USDateTimeFormat);
|
||||
const finish = moment.utc(this.endTime, USDateTimeFormat);
|
||||
let msStart = start.diff(_now);
|
||||
let msFinish = finish.diff(_now);
|
||||
|
||||
if (msStart > 0) {
|
||||
this.timeToStart.val = msStart + 5000;
|
||||
this.timeToStart.displayValue = this.formatMs(msStart, ":mm:ss");
|
||||
return this.timeTo = this.timeToStart;
|
||||
}
|
||||
|
||||
if (msFinish > 0) {
|
||||
this.timeToStart.val = 0;
|
||||
this.timeToFinish.val = msFinish;
|
||||
this.timeToFinish.displayValue = this.formatMs(msFinish, ":mm:ss");
|
||||
return this.timeTo = this.timeToFinish;
|
||||
}
|
||||
|
||||
this.timeToFinish.val = 0;
|
||||
this.timeToFinish.displayValue = zeroTimeTo;
|
||||
return this.timeTo = this.timeToFinish;
|
||||
}
|
||||
|
||||
formatMs (ms, format) {
|
||||
let dur = moment.duration(ms);
|
||||
let hours = Math.floor(dur.asHours());
|
||||
hours = hours < 10 ? "0" + hours : hours;
|
||||
let formattedMs = hours + moment.utc(ms).format(":mm:ss");
|
||||
return formattedMs;
|
||||
}
|
||||
|
||||
@action("validator has already voted")
|
||||
getHasAlreadyVoted = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let _hasAlreadyVoted = false;
|
||||
web3.eth.sendTransaction({
|
||||
from: contractsStore.votingKey,
|
||||
to: contract.address,
|
||||
gasPrice: web3.utils.toWei('1', 'gwei'),
|
||||
data: contract.vote(id, choice)
|
||||
}, async (error, hash) => {
|
||||
if (error) {
|
||||
commonStore.hideLoading()
|
||||
swal('Error!', error.message, 'error')
|
||||
} else {
|
||||
try {
|
||||
_hasAlreadyVoted = await this.getContract(contractsStore, votingType).hasAlreadyVoted(id, contractsStore.votingKey);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
let tx
|
||||
do {
|
||||
await sleep(constants.getTransactionReceiptInterval)
|
||||
tx = await web3.eth.getTransactionReceipt(hash)
|
||||
} while (tx === null)
|
||||
|
||||
commonStore.hideLoading()
|
||||
if (tx.status === true || tx.status === '0x1') {
|
||||
const ballotInfo = await contract.getBallotInfo(id, contractsStore.votingKey)
|
||||
|
||||
this.totalVoters = Number(ballotInfo.totalVoters)
|
||||
this.progress = Number(ballotInfo.progress)
|
||||
this.isFinalized = Boolean(ballotInfo.isFinalized)
|
||||
if (ballotInfo.hasOwnProperty('canBeFinalizedNow')) {
|
||||
this.canBeFinalized = Boolean(ballotInfo.canBeFinalizedNow)
|
||||
} else {
|
||||
await this.canBeFinalizedNow()
|
||||
}
|
||||
this.hasAlreadyVoted = true
|
||||
|
||||
ballotsStore.ballotCards[pos].props.votingState.totalVoters = this.totalVoters
|
||||
ballotsStore.ballotCards[pos].props.votingState.progress = this.progress
|
||||
ballotsStore.ballotCards[pos].props.votingState.isFinalized = this.isFinalized
|
||||
ballotsStore.ballotCards[pos].props.votingState.canBeFinalized = this.canBeFinalized
|
||||
ballotsStore.ballotCards[pos].props.votingState.hasAlreadyVoted = this.hasAlreadyVoted
|
||||
|
||||
swal('Congratulations!', messages.VOTED_SUCCESS_MSG, 'success').then(result => {
|
||||
push(`${commonStore.rootPath}`)
|
||||
})
|
||||
} else {
|
||||
swal('Warning!', messages.VOTE_FAILED_TX, 'warning')
|
||||
}
|
||||
} catch (e) {
|
||||
commonStore.hideLoading()
|
||||
swal('Error!', e.message, 'error')
|
||||
}
|
||||
this.hasAlreadyVoted = _hasAlreadyVoted;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
finalize = async e => {
|
||||
if (this.isFinalized) {
|
||||
return
|
||||
}
|
||||
|
||||
isValidVote = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let _isValidVote;
|
||||
if (this.timeToStart.val > 0) {
|
||||
swal('Warning!', messages.ballotIsNotActiveMsg(this.timeTo.displayValue), 'warning')
|
||||
return
|
||||
}
|
||||
const { commonStore, contractsStore, id, votingType, ballotsStore, pos } = this.props
|
||||
const { push } = this.props.routing
|
||||
if (!contractsStore.isValidVotingKey) {
|
||||
swal('Warning!', messages.invalidVotingKeyMsg(contractsStore.votingKey), 'warning')
|
||||
return
|
||||
}
|
||||
if (this.isFinalized) {
|
||||
swal('Warning!', messages.ALREADY_FINALIZED_MSG, 'warning')
|
||||
return
|
||||
}
|
||||
commonStore.showLoading()
|
||||
await this.canBeFinalizedNow()
|
||||
let _canBeFinalized = this.canBeFinalized
|
||||
if (_canBeFinalized === null) {
|
||||
console.log('canBeFinalizedNow is not existed')
|
||||
_canBeFinalized = !(await this.isActive())
|
||||
}
|
||||
if (!_canBeFinalized) {
|
||||
commonStore.hideLoading()
|
||||
swal('Warning!', messages.INVALID_FINALIZE_MSG, 'warning')
|
||||
return
|
||||
}
|
||||
|
||||
const web3 = new Web3(contractsStore.web3Instance.currentProvider)
|
||||
const contract = this.getContract(contractsStore, votingType)
|
||||
|
||||
web3.eth.sendTransaction({
|
||||
from: contractsStore.votingKey,
|
||||
to: contract.address,
|
||||
gasPrice: web3.utils.toWei('1', 'gwei'),
|
||||
data: contract.finalize(id)
|
||||
}, async (error, hash) => {
|
||||
if (error) {
|
||||
commonStore.hideLoading()
|
||||
swal('Error!', error.message, 'error')
|
||||
} else {
|
||||
try {
|
||||
_isValidVote = await this.getContract(contractsStore, votingType).isValidVote(id, contractsStore.votingKey);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
return _isValidVote;
|
||||
}
|
||||
let tx
|
||||
do {
|
||||
await sleep(constants.getTransactionReceiptInterval)
|
||||
tx = await web3.eth.getTransactionReceipt(hash)
|
||||
} while (tx === null)
|
||||
|
||||
isActive = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let _isActive = await this.repeatGetProperty(contractsStore, votingType, id, "isActive", 0);
|
||||
return _isActive;
|
||||
}
|
||||
|
||||
canBeFinalizedNow = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let _canBeFinalizedNow = await this.repeatGetProperty(contractsStore, votingType, id, "canBeFinalizedNow", 0);
|
||||
this.canBeFinalized = _canBeFinalizedNow;
|
||||
}
|
||||
|
||||
vote = async ({choice}) => {
|
||||
if (this.timeToStart.val > 0) {
|
||||
swal("Warning!", messages.ballotIsNotActiveMsg(this.timeTo.displayValue), "warning");
|
||||
return;
|
||||
}
|
||||
const { commonStore, contractsStore, id, votingType, ballotsStore } = this.props;
|
||||
const { push } = this.props.routing;
|
||||
if (!contractsStore.isValidVotingKey) {
|
||||
swal("Warning!", messages.invalidVotingKeyMsg(contractsStore.votingKey), "warning");
|
||||
return;
|
||||
}
|
||||
commonStore.showLoading();
|
||||
let isValidVote = await this.isValidVote();
|
||||
if (!isValidVote) {
|
||||
commonStore.hideLoading();
|
||||
swal("Warning!", messages.INVALID_VOTE_MSG, "warning");
|
||||
return;
|
||||
}
|
||||
|
||||
const contract = this.getContract(contractsStore, votingType);
|
||||
contract.vote(id, choice, contractsStore.votingKey)
|
||||
.on("receipt", async (tx) => {
|
||||
commonStore.hideLoading();
|
||||
if (tx.status === true || tx.status === '0x1') {
|
||||
const ballotInfo = await contract.getBallotInfo(id, contractsStore.votingKey);
|
||||
|
||||
this.totalVoters = Number(ballotInfo.totalVoters);
|
||||
this.progress = Number(ballotInfo.progress);
|
||||
this.isFinalized = Boolean(ballotInfo.isFinalized);
|
||||
if (ballotInfo.hasOwnProperty('canBeFinalizedNow')) {
|
||||
this.canBeFinalized = Boolean(ballotInfo.canBeFinalizedNow);
|
||||
} else {
|
||||
await this.canBeFinalizedNow();
|
||||
}
|
||||
this.hasAlreadyVoted = true;
|
||||
|
||||
ballotsStore.ballotCards[this.props.pos].props.votingState.totalVoters = this.totalVoters;
|
||||
ballotsStore.ballotCards[this.props.pos].props.votingState.progress = this.progress;
|
||||
ballotsStore.ballotCards[this.props.pos].props.votingState.isFinalized = this.isFinalized;
|
||||
ballotsStore.ballotCards[this.props.pos].props.votingState.canBeFinalized = this.canBeFinalized;
|
||||
ballotsStore.ballotCards[this.props.pos].props.votingState.hasAlreadyVoted = this.hasAlreadyVoted;
|
||||
|
||||
swal("Congratulations!", messages.VOTED_SUCCESS_MSG, "success").then((result) => {
|
||||
push(`${commonStore.rootPath}`);
|
||||
});
|
||||
} else {
|
||||
swal("Warning!", messages.VOTE_FAILED_TX, "warning");
|
||||
commonStore.hideLoading()
|
||||
if (tx.status === true || tx.status === '0x1') {
|
||||
this.isFinalized = true
|
||||
ballotsStore.ballotCards[pos].props.votingState.isFinalized = this.isFinalized
|
||||
if (this.canBeFinalized !== null) {
|
||||
this.canBeFinalized = false
|
||||
ballotsStore.ballotCards[pos].props.votingState.canBeFinalized = this.canBeFinalized
|
||||
}
|
||||
})
|
||||
.on("error", (e) => {
|
||||
commonStore.hideLoading();
|
||||
swal("Error!", e.message, "error");
|
||||
});
|
||||
swal('Congratulations!', messages.FINALIZED_SUCCESS_MSG, 'success').then(result => {
|
||||
push(`${commonStore.rootPath}`)
|
||||
})
|
||||
} else {
|
||||
swal('Warning!', messages.FINALIZE_FAILED_TX, 'warning')
|
||||
}
|
||||
} catch (e) {
|
||||
commonStore.hideLoading()
|
||||
swal('Error!', e.message, 'error')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
repeatGetProperty = async (contractsStore, contractType, id, methodID, tryID) => {
|
||||
try {
|
||||
let val = await this.getContract(contractsStore, contractType)[methodID](id)
|
||||
if (tryID > 0) {
|
||||
console.log(`success from Try ${tryID + 1}`)
|
||||
}
|
||||
return val
|
||||
} catch (e) {
|
||||
if (tryID < 10) {
|
||||
console.log(`trying to repeat get value again... Try ${tryID + 1}`)
|
||||
tryID++
|
||||
await setTimeout(async () => {
|
||||
this.repeatGetProperty(contractsStore, contractType, id, methodID, tryID)
|
||||
}, 1000)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finalize = async (e) => {
|
||||
if (this.isFinalized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.timeToStart.val > 0) {
|
||||
swal("Warning!", messages.ballotIsNotActiveMsg(this.timeTo.displayValue), "warning");
|
||||
return;
|
||||
}
|
||||
const { commonStore, contractsStore, id, votingType, ballotsStore } = this.props;
|
||||
const { push } = this.props.routing;
|
||||
if (!contractsStore.isValidVotingKey) {
|
||||
swal("Warning!", messages.invalidVotingKeyMsg(contractsStore.votingKey), "warning");
|
||||
return;
|
||||
}
|
||||
if (this.isFinalized) {
|
||||
swal("Warning!", messages.ALREADY_FINALIZED_MSG, "warning");
|
||||
return;
|
||||
}
|
||||
commonStore.showLoading();
|
||||
await this.canBeFinalizedNow();
|
||||
let _canBeFinalized = this.canBeFinalized;
|
||||
if (_canBeFinalized === null) {
|
||||
console.log('canBeFinalizedNow is not existed');
|
||||
_canBeFinalized = !(await this.isActive());
|
||||
}
|
||||
if (!_canBeFinalized) {
|
||||
commonStore.hideLoading();
|
||||
swal("Warning!", messages.INVALID_FINALIZE_MSG, "warning");
|
||||
return;
|
||||
}
|
||||
this.getContract(contractsStore, votingType).finalize(id, contractsStore.votingKey)
|
||||
.on("receipt", (tx) => {
|
||||
commonStore.hideLoading();
|
||||
if (tx.status === true || tx.status === '0x1') {
|
||||
this.isFinalized = true;
|
||||
ballotsStore.ballotCards[this.props.pos].props.votingState.isFinalized = this.isFinalized;
|
||||
if (this.canBeFinalized !== null) {
|
||||
this.canBeFinalized = false;
|
||||
ballotsStore.ballotCards[this.props.pos].props.votingState.canBeFinalized = this.canBeFinalized;
|
||||
}
|
||||
swal("Congratulations!", messages.FINALIZED_SUCCESS_MSG, "success").then((result) => {
|
||||
push(`${commonStore.rootPath}`);
|
||||
});
|
||||
} else {
|
||||
swal("Warning!", messages.FINALIZE_FAILED_TX, "warning");
|
||||
}
|
||||
})
|
||||
.on("error", (e) => {
|
||||
commonStore.hideLoading();
|
||||
swal("Error!", e.message, "error");
|
||||
});
|
||||
getContract(contractsStore, contractType) {
|
||||
switch (contractType) {
|
||||
case 'votingToChangeKeys':
|
||||
return contractsStore.votingToChangeKeys
|
||||
case 'votingToChangeMinThreshold':
|
||||
return contractsStore.votingToChangeMinThreshold
|
||||
case 'votingToChangeProxy':
|
||||
return contractsStore.votingToChangeProxy
|
||||
case 'validatorMetadata':
|
||||
return contractsStore.validatorMetadata
|
||||
default:
|
||||
return contractsStore.votingToChangeKeys
|
||||
}
|
||||
}
|
||||
|
||||
repeatGetProperty = async (contractsStore, contractType, id, methodID, tryID) => {
|
||||
try {
|
||||
let val = await this.getContract(contractsStore, contractType)[methodID](id);
|
||||
if (tryID > 0) {
|
||||
console.log(`success from Try ${tryID + 1}`);
|
||||
}
|
||||
return val;
|
||||
} catch(e) {
|
||||
if (tryID < 10) {
|
||||
console.log(`trying to repeat get value again... Try ${tryID + 1}`);
|
||||
tryID++;
|
||||
await setTimeout(async () => {
|
||||
this.repeatGetProperty(contractsStore, contractType, id, methodID, tryID);
|
||||
}, 1000)
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
getThreshold(contractsStore, votingType) {
|
||||
switch (votingType) {
|
||||
case 'votingToChangeKeys':
|
||||
return contractsStore.keysBallotThreshold
|
||||
case 'votingToChangeMinThreshold':
|
||||
return contractsStore.minThresholdBallotThreshold
|
||||
case 'votingToChangeProxy':
|
||||
return contractsStore.proxyBallotThreshold
|
||||
default:
|
||||
return contractsStore.keysBallotThreshold
|
||||
}
|
||||
}
|
||||
|
||||
getContract(contractsStore, contractType) {
|
||||
switch(contractType) {
|
||||
case "votingToChangeKeys":
|
||||
return contractsStore.votingToChangeKeys;
|
||||
case "votingToChangeMinThreshold":
|
||||
return contractsStore.votingToChangeMinThreshold;
|
||||
case "votingToChangeProxy":
|
||||
return contractsStore.votingToChangeProxy;
|
||||
case "validatorMetadata":
|
||||
return contractsStore.validatorMetadata;
|
||||
default:
|
||||
return contractsStore.votingToChangeKeys;
|
||||
}
|
||||
constructor(props) {
|
||||
super(props)
|
||||
const { votingState } = this.props
|
||||
// getTimes
|
||||
this.startTime = moment.utc(votingState.startTime * 1000).format(USDateTimeFormat)
|
||||
this.endTime = moment.utc(votingState.endTime * 1000).format(USDateTimeFormat)
|
||||
this.calcTimeTo()
|
||||
// getCreator
|
||||
this.creator = votingState.creator
|
||||
this.creatorMiningKey = votingState.creatorMiningKey
|
||||
// getTotalVoters
|
||||
this.totalVoters = Number(votingState.totalVoters)
|
||||
// getProgress
|
||||
this.progress = Number(votingState.progress)
|
||||
// getIsFinalized
|
||||
this.isFinalized = votingState.isFinalized
|
||||
// canBeFinalizedNow
|
||||
this.canBeFinalized = votingState.hasOwnProperty('canBeFinalizedNow') ? votingState.canBeFinalizedNow : null
|
||||
// getMemo
|
||||
this.memo = votingState.memo
|
||||
// hasAlreadyVoted
|
||||
if (votingState.hasOwnProperty('hasAlreadyVoted')) {
|
||||
this.hasAlreadyVoted = votingState.hasAlreadyVoted
|
||||
} else {
|
||||
this.getHasAlreadyVoted()
|
||||
}
|
||||
}
|
||||
|
||||
getThreshold(contractsStore, votingType) {
|
||||
switch(votingType) {
|
||||
case "votingToChangeKeys":
|
||||
return contractsStore.keysBallotThreshold;
|
||||
case "votingToChangeMinThreshold":
|
||||
return contractsStore.minThresholdBallotThreshold;
|
||||
case "votingToChangeProxy":
|
||||
return contractsStore.proxyBallotThreshold;
|
||||
default:
|
||||
return contractsStore.keysBallotThreshold;
|
||||
}
|
||||
componentDidMount() {
|
||||
this.interval = setInterval(() => {
|
||||
this.calcTimeTo()
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.clearInterval(this.interval)
|
||||
}
|
||||
|
||||
showCard = () => {
|
||||
let { commonStore } = this.props
|
||||
let checkToFinalizeFilter = commonStore.isToFinalizeFilter
|
||||
? !this.isFinalized && (this.timeToFinish.val === 0 || this.canBeFinalized) && this.timeToStart.val === 0
|
||||
: true
|
||||
let show = commonStore.isActiveFilter ? !this.isFinalized : checkToFinalizeFilter
|
||||
return show
|
||||
}
|
||||
|
||||
typeName(type) {
|
||||
switch (type) {
|
||||
case 'votingToChangeMinThreshold':
|
||||
return 'Consensus'
|
||||
case 'votingToChangeKeys':
|
||||
return 'Keys'
|
||||
case 'votingToChangeProxy':
|
||||
return 'Proxy'
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const { votingState } = this.props;
|
||||
// getTimes
|
||||
this.startTime = moment.utc(votingState.startTime * 1000).format(USDateTimeFormat);
|
||||
this.endTime = moment.utc(votingState.endTime * 1000).format(USDateTimeFormat);
|
||||
this.calcTimeTo();
|
||||
// getCreator
|
||||
this.creator = votingState.creator;
|
||||
this.creatorMiningKey = votingState.creatorMiningKey;
|
||||
// getTotalVoters
|
||||
this.totalVoters = Number(votingState.totalVoters);
|
||||
// getProgress
|
||||
this.progress = Number(votingState.progress);
|
||||
// getIsFinalized
|
||||
this.isFinalized = votingState.isFinalized;
|
||||
// canBeFinalizedNow
|
||||
this.canBeFinalized = votingState.hasOwnProperty('canBeFinalizedNow') ? votingState.canBeFinalizedNow : null;
|
||||
// getMemo
|
||||
this.memo = votingState.memo;
|
||||
// hasAlreadyVoted
|
||||
if (votingState.hasOwnProperty('hasAlreadyVoted')) {
|
||||
this.hasAlreadyVoted = votingState.hasAlreadyVoted;
|
||||
} else {
|
||||
this.getHasAlreadyVoted();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.interval = setInterval(() => {
|
||||
this.calcTimeTo();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.clearInterval(this.interval);
|
||||
}
|
||||
|
||||
showCard = () => {
|
||||
let { commonStore } = this.props;
|
||||
let checkToFinalizeFilter = commonStore.isToFinalizeFilter ? !this.isFinalized && (this.timeToFinish.val === 0 || this.canBeFinalized) && this.timeToStart.val === 0 : true;
|
||||
let show = commonStore.isActiveFilter ? !this.isFinalized : checkToFinalizeFilter;
|
||||
return show;
|
||||
}
|
||||
|
||||
typeName(type){
|
||||
switch(type) {
|
||||
case "votingToChangeMinThreshold":
|
||||
return "Consensus";
|
||||
case "votingToChangeKeys":
|
||||
return "Keys";
|
||||
case "votingToChangeProxy":
|
||||
return "Proxy";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
let { contractsStore, votingType, children } = this.props;
|
||||
let ballotClass = this.showCard() ? this.isFinalized ? "ballots-i" : "ballots-i ballots-i-not-finalized" : "ballots-i display-none";
|
||||
let voteScaleClass = this.isFinalized ? "vote-scale" : "vote-scale vote-scale-not-finalized";
|
||||
let hasAlreadyVotedLabel = <div className="ballots-i--vote ballots-i--vote-label ballots-i--vote-label-right ballots-i--vote_no">You already voted</div>;
|
||||
let showHasAlreadyVotedLabel = this.hasAlreadyVoted ? hasAlreadyVotedLabel : "";
|
||||
const threshold = this.getThreshold(contractsStore, votingType);
|
||||
return (
|
||||
<div className={ballotClass}>
|
||||
<div className="ballots-about">
|
||||
<div className="ballots-about-i ballots-about-i_name">
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-about-i--title">Proposer</p>
|
||||
</div>
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-i--name">{this.creator}</p>
|
||||
<p className="ballots-i--created">{this.startTime}</p>
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
<div className="ballots-about-i ballots-about-i_time">
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-about-i--title">Ballot Time</p>
|
||||
</div>
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-i--time">{this.timeTo.displayValue}</p>
|
||||
<p className="ballots-i--to-close">{this.timeTo.title}</p>
|
||||
</div>
|
||||
</div>
|
||||
render() {
|
||||
let { contractsStore, votingType, children } = this.props
|
||||
let ballotClass = this.showCard()
|
||||
? this.isFinalized
|
||||
? 'ballots-i'
|
||||
: 'ballots-i ballots-i-not-finalized'
|
||||
: 'ballots-i display-none'
|
||||
let voteScaleClass = this.isFinalized ? 'vote-scale' : 'vote-scale vote-scale-not-finalized'
|
||||
let hasAlreadyVotedLabel = (
|
||||
<div className="ballots-i--vote ballots-i--vote-label ballots-i--vote-label-right ballots-i--vote_no">
|
||||
You already voted
|
||||
</div>
|
||||
)
|
||||
let showHasAlreadyVotedLabel = this.hasAlreadyVoted ? hasAlreadyVotedLabel : ''
|
||||
const threshold = this.getThreshold(contractsStore, votingType)
|
||||
return (
|
||||
<div className={ballotClass}>
|
||||
<div className="ballots-about">
|
||||
<div className="ballots-about-i ballots-about-i_name">
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-about-i--title">Proposer</p>
|
||||
</div>
|
||||
<div className="ballots-i-scale">
|
||||
<div className="ballots-i-scale-column">
|
||||
<button type="button" onClick={(e) => this.vote({choice: REJECT})} className="ballots-i--vote ballots-i--vote_no">No</button>
|
||||
<div className="vote-scale--container">
|
||||
<p className="vote-scale--value">No</p>
|
||||
<p className="vote-scale--votes">Votes: {this.votesAgainstNumber}</p>
|
||||
<p className="vote-scale--percentage">{this.votesAgainstPercents}%</p>
|
||||
<div className={voteScaleClass}>
|
||||
<div className="vote-scale--fill vote-scale--fill_yes" style={{width: `${this.votesAgainstPercents}%`}}></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="ballots-i-scale-column">
|
||||
<div className="vote-scale--container">
|
||||
<p className="vote-scale--value">Yes</p>
|
||||
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
||||
<p className="vote-scale--percentage">{this.votesForPercents}%</p>
|
||||
<div className={voteScaleClass}>
|
||||
<div className="vote-scale--fill vote-scale--fill_no" style={{width: `${this.votesForPercents}%`}}></div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onClick={(e) => this.vote({choice: ACCEPT})} className="ballots-i--vote ballots-i--vote_yes">Yes</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="info">
|
||||
Minimum {threshold} from {contractsStore.validatorsLength} validators are required to pass the proposal
|
||||
</div>
|
||||
<div className="info">
|
||||
{this.memo}
|
||||
</div>
|
||||
<hr />
|
||||
<div className="ballots-footer">
|
||||
<div className="ballots-footer-left">
|
||||
<button type="button" onClick={(e) => this.finalize(e)} className={this.finalizeButtonClass}>{this.finalizeButtonDisplayName}</button>
|
||||
<p>{this.finalizeDescription}</p>
|
||||
</div>
|
||||
{showHasAlreadyVotedLabel}
|
||||
<div className="ballots-i--vote ballots-i--vote-label ballots-i--vote_no">{this.typeName(votingType)} Ballot ID: {this.props.id}</div>
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-i--name">{this.creator}</p>
|
||||
<p className="ballots-i--created">{this.startTime}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
{children}
|
||||
<div className="ballots-about-i ballots-about-i_time">
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-about-i--title">Ballot Time</p>
|
||||
</div>
|
||||
<div className="ballots-about-td">
|
||||
<p className="ballots-i--time">{this.timeTo.displayValue}</p>
|
||||
<p className="ballots-i--to-close">{this.timeTo.title}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="ballots-i-scale">
|
||||
<div className="ballots-i-scale-column">
|
||||
<button
|
||||
type="button"
|
||||
onClick={e => this.vote({ choice: REJECT })}
|
||||
className="ballots-i--vote ballots-i--vote_no"
|
||||
>
|
||||
No
|
||||
</button>
|
||||
<div className="vote-scale--container">
|
||||
<p className="vote-scale--value">No</p>
|
||||
<p className="vote-scale--votes">Votes: {this.votesAgainstNumber}</p>
|
||||
<p className="vote-scale--percentage">{this.votesAgainstPercents}%</p>
|
||||
<div className={voteScaleClass}>
|
||||
<div
|
||||
className="vote-scale--fill vote-scale--fill_yes"
|
||||
style={{ width: `${this.votesAgainstPercents}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="ballots-i-scale-column">
|
||||
<div className="vote-scale--container">
|
||||
<p className="vote-scale--value">Yes</p>
|
||||
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
||||
<p className="vote-scale--percentage">{this.votesForPercents}%</p>
|
||||
<div className={voteScaleClass}>
|
||||
<div className="vote-scale--fill vote-scale--fill_no" style={{ width: `${this.votesForPercents}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={e => this.vote({ choice: ACCEPT })}
|
||||
className="ballots-i--vote ballots-i--vote_yes"
|
||||
>
|
||||
Yes
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="info">
|
||||
Minimum {threshold} from {contractsStore.validatorsLength} validators are required to pass the proposal
|
||||
</div>
|
||||
<div className="info">{this.memo}</div>
|
||||
<hr />
|
||||
<div className="ballots-footer">
|
||||
<div className="ballots-footer-left">
|
||||
<button type="button" onClick={e => this.finalize(e)} className={this.finalizeButtonClass}>
|
||||
{this.finalizeButtonDisplayName}
|
||||
</button>
|
||||
<p>{this.finalizeDescription}</p>
|
||||
</div>
|
||||
{showHasAlreadyVotedLabel}
|
||||
<div className="ballots-i--vote ballots-i--vote-label ballots-i--vote_no">
|
||||
{this.typeName(votingType)} Ballot ID: {this.props.id}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,101 +1,113 @@
|
|||
import React from 'react';
|
||||
import { inject, observer } from "mobx-react";
|
||||
import moment from 'moment';
|
||||
import swal from 'sweetalert2';
|
||||
import { Validator } from './Validator';
|
||||
import { KeysTypes } from './KeysTypes';
|
||||
import { BallotKeysMetadata } from './BallotKeysMetadata';
|
||||
import { BallotMinThresholdMetadata } from './BallotMinThresholdMetadata';
|
||||
import { BallotProxyMetadata } from './BallotProxyMetadata';
|
||||
import { messages } from "../messages";
|
||||
import { constants } from "../constants";
|
||||
@inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing", "ballotsStore")
|
||||
import Web3 from 'web3'
|
||||
import React from 'react'
|
||||
import { inject, observer } from 'mobx-react'
|
||||
import moment from 'moment'
|
||||
import swal from 'sweetalert2'
|
||||
import { Validator } from './Validator.jsx'
|
||||
import { KeysTypes } from './KeysTypes.jsx'
|
||||
import { BallotKeysMetadata } from './BallotKeysMetadata.jsx'
|
||||
import { BallotMinThresholdMetadata } from './BallotMinThresholdMetadata.jsx'
|
||||
import { BallotProxyMetadata } from './BallotProxyMetadata.jsx'
|
||||
import { messages } from '../messages'
|
||||
import { constants } from '../constants'
|
||||
import { sleep } from '../helpers'
|
||||
@inject('commonStore', 'ballotStore', 'validatorStore', 'contractsStore', 'routing', 'ballotsStore')
|
||||
@observer
|
||||
export class NewBallot extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.onClick = this.onClick.bind(this);
|
||||
super(props)
|
||||
this.onClick = this.onClick.bind(this)
|
||||
}
|
||||
|
||||
checkValidation() {
|
||||
const { commonStore, contractsStore, ballotStore, validatorStore } = this.props;
|
||||
const { commonStore, contractsStore, ballotStore, validatorStore } = this.props
|
||||
|
||||
if (ballotStore.isNewValidatorPersonalData) {
|
||||
for (let validatorProp in validatorStore) {
|
||||
if (validatorStore[validatorProp].length === 0) {
|
||||
swal("Warning!", `Validator ${validatorProp} is empty`, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', `Validator ${validatorProp} is empty`, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!ballotStore.memo) {
|
||||
swal("Warning!", messages.DESCRIPTION_IS_EMPTY, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
if (!ballotStore.memo) {
|
||||
swal('Warning!', messages.DESCRIPTION_IS_EMPTY, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
|
||||
const minBallotDurationInHours = constants.minBallotDurationInDays * 24;
|
||||
const minEndTime = moment.utc().add(minBallotDurationInHours, 'hours').format();
|
||||
let neededMinutes = moment(minEndTime).diff(moment(ballotStore.endTime), 'minutes');
|
||||
let neededHours = Math.round(neededMinutes / 60);
|
||||
let duration = minBallotDurationInHours - neededHours;
|
||||
const minBallotDurationInHours = constants.minBallotDurationInDays * 24
|
||||
const minEndTime = moment
|
||||
.utc()
|
||||
.add(minBallotDurationInHours, 'hours')
|
||||
.format()
|
||||
let neededMinutes = moment(minEndTime).diff(moment(ballotStore.endTime), 'minutes')
|
||||
let neededHours = Math.round(neededMinutes / 60)
|
||||
let duration = minBallotDurationInHours - neededHours
|
||||
|
||||
if (neededMinutes > 0) {
|
||||
neededMinutes = neededHours * 60 - neededMinutes;
|
||||
swal("Warning!", messages.SHOULD_BE_MORE_THAN_MIN_DURATION(minBallotDurationInHours, duration, neededHours, neededMinutes), "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
neededMinutes = neededHours * 60 - neededMinutes
|
||||
swal(
|
||||
'Warning!',
|
||||
messages.SHOULD_BE_MORE_THAN_MIN_DURATION(minBallotDurationInHours, duration, neededHours, neededMinutes),
|
||||
'warning'
|
||||
)
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
|
||||
const twoWeeks = moment.utc().add(14, 'days').format();
|
||||
let exceededMinutes = moment(ballotStore.endTime).diff(moment(twoWeeks), 'minutes');
|
||||
const twoWeeks = moment
|
||||
.utc()
|
||||
.add(14, 'days')
|
||||
.format()
|
||||
let exceededMinutes = moment(ballotStore.endTime).diff(moment(twoWeeks), 'minutes')
|
||||
if (exceededMinutes > 0) {
|
||||
swal("Warning!", messages.SHOULD_BE_LESS_OR_EQUAL_14_DAYS(duration), "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', messages.SHOULD_BE_LESS_OR_EQUAL_14_DAYS(duration), 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
|
||||
if (ballotStore.isBallotForKey) {
|
||||
for (let ballotKeysProp in ballotStore.ballotKeys) {
|
||||
if (ballotKeysProp === 'newVotingKey' || ballotKeysProp === 'newPayoutKey') {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
if (!ballotStore.ballotKeys[ballotKeysProp]) {
|
||||
swal("Warning!", `Ballot ${ballotKeysProp} is empty`, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', `Ballot ${ballotKeysProp} is empty`, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
if (ballotStore.ballotKeys[ballotKeysProp].length === 0) {
|
||||
swal("Warning!", `Ballot ${ballotKeysProp} is empty`, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', `Ballot ${ballotKeysProp} is empty`, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
let isAffectedKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.affectedKey);
|
||||
let isAffectedKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.affectedKey)
|
||||
|
||||
if (!isAffectedKeyAddress) {
|
||||
swal("Warning!", messages.AFFECTED_KEY_IS_NOT_ADDRESS_MSG, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', messages.AFFECTED_KEY_IS_NOT_ADDRESS_MSG, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
|
||||
let isMiningKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.miningKey.value);
|
||||
let isMiningKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.miningKey.value)
|
||||
if (!isMiningKeyAddress) {
|
||||
swal("Warning!", messages.MINING_KEY_IS_NOT_ADDRESS_MSG, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', messages.MINING_KEY_IS_NOT_ADDRESS_MSG, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (ballotStore.isBallotForMinThreshold) {
|
||||
for (let ballotMinThresholdProp in ballotStore.ballotMinThreshold) {
|
||||
if (ballotStore.ballotMinThreshold[ballotMinThresholdProp].length === 0) {
|
||||
swal("Warning!", `Ballot ${ballotMinThresholdProp} is empty`, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', `Ballot ${ballotMinThresholdProp} is empty`, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,32 +115,32 @@ export class NewBallot extends React.Component {
|
|||
if (ballotStore.isBallotForProxy) {
|
||||
for (let ballotProxyProp in ballotStore.ballotProxy) {
|
||||
if (ballotStore.ballotProxy[ballotProxyProp].length === 0) {
|
||||
swal("Warning!", `Ballot ${ballotProxyProp} is empty`, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', `Ballot ${ballotProxyProp} is empty`, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
let isAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotProxy.proposedAddress);
|
||||
let isAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotProxy.proposedAddress)
|
||||
|
||||
if (!isAddress) {
|
||||
swal("Warning!", messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (!ballotStore.isBallotForKey && !ballotStore.isBallotForMinThreshold && !ballotStore.isBallotForProxy) {
|
||||
swal("Warning!", messages.BALLOT_TYPE_IS_EMPTY_MSG, "warning");
|
||||
commonStore.hideLoading();
|
||||
return false;
|
||||
swal('Warning!', messages.BALLOT_TYPE_IS_EMPTY_MSG, 'warning')
|
||||
commonStore.hideLoading()
|
||||
return false
|
||||
}
|
||||
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
createBallotForKeys = (startTime) => {
|
||||
const { ballotStore, contractsStore } = this.props;
|
||||
createBallotForKeys = startTime => {
|
||||
const { ballotStore, contractsStore } = this.props
|
||||
const inputToMethod = {
|
||||
startTime: startTime,
|
||||
endTime: ballotStore.endTimeUnix,
|
||||
|
@ -138,60 +150,55 @@ export class NewBallot extends React.Component {
|
|||
newPayoutKey: ballotStore.ballotKeys.newPayoutKey,
|
||||
miningKey: ballotStore.ballotKeys.miningKey.value,
|
||||
ballotType: ballotStore.ballotKeys.keysBallotType,
|
||||
sender: contractsStore.votingKey,
|
||||
memo: ballotStore.memo
|
||||
};
|
||||
let method;
|
||||
}
|
||||
let data
|
||||
if (
|
||||
inputToMethod.ballotType === ballotStore.KeysBallotType.add &&
|
||||
inputToMethod.affectedKeyType === ballotStore.KeyType.mining &&
|
||||
(inputToMethod.newVotingKey || inputToMethod.newPayoutKey)
|
||||
) {
|
||||
method = contractsStore.votingToChangeKeys.createBallotToAddNewValidator(inputToMethod);
|
||||
data = contractsStore.votingToChangeKeys.createBallotToAddNewValidator(inputToMethod)
|
||||
} else {
|
||||
method = contractsStore.votingToChangeKeys.createBallot(inputToMethod);
|
||||
data = contractsStore.votingToChangeKeys.createBallot(inputToMethod)
|
||||
}
|
||||
return method;
|
||||
return data
|
||||
}
|
||||
|
||||
createBallotForMinThreshold = (startTime) => {
|
||||
const { ballotStore, contractsStore } = this.props;
|
||||
createBallotForMinThreshold = startTime => {
|
||||
const { ballotStore, contractsStore } = this.props
|
||||
const inputToMethod = {
|
||||
startTime: startTime,
|
||||
endTime: ballotStore.endTimeUnix,
|
||||
proposedValue: ballotStore.ballotMinThreshold.proposedValue,
|
||||
sender: contractsStore.votingKey,
|
||||
memo: ballotStore.memo
|
||||
};
|
||||
let method = contractsStore.votingToChangeMinThreshold.createBallot(inputToMethod);
|
||||
return method;
|
||||
}
|
||||
return contractsStore.votingToChangeMinThreshold.createBallot(inputToMethod)
|
||||
}
|
||||
|
||||
createBallotForProxy = (startTime) => {
|
||||
const { ballotStore, contractsStore } = this.props;
|
||||
createBallotForProxy = startTime => {
|
||||
const { ballotStore, contractsStore } = this.props
|
||||
const inputToMethod = {
|
||||
startTime: startTime,
|
||||
endTime: ballotStore.endTimeUnix,
|
||||
proposedValue: ballotStore.ballotProxy.proposedAddress,
|
||||
contractType: ballotStore.ballotProxy.contractType,
|
||||
sender: contractsStore.votingKey,
|
||||
memo: ballotStore.memo
|
||||
};
|
||||
let method = contractsStore.votingToChangeProxy.createBallot(inputToMethod);
|
||||
return method;
|
||||
}
|
||||
return contractsStore.votingToChangeProxy.createBallot(inputToMethod)
|
||||
}
|
||||
|
||||
onClick = async () => {
|
||||
const { commonStore, contractsStore, ballotStore, ballotsStore } = this.props;
|
||||
const { push } = this.props.routing;
|
||||
commonStore.showLoading();
|
||||
const isValidVotingKey = contractsStore.isValidVotingKey;
|
||||
const { commonStore, contractsStore, ballotStore, ballotsStore } = this.props
|
||||
const { push } = this.props.routing
|
||||
commonStore.showLoading()
|
||||
const isValidVotingKey = contractsStore.isValidVotingKey
|
||||
if (!isValidVotingKey) {
|
||||
commonStore.hideLoading();
|
||||
swal("Warning!", messages.invalidVotingKeyMsg(contractsStore.votingKey), "warning");
|
||||
return;
|
||||
commonStore.hideLoading()
|
||||
swal('Warning!', messages.invalidVotingKeyMsg(contractsStore.votingKey), 'warning')
|
||||
return
|
||||
}
|
||||
const isFormValid = this.checkValidation();
|
||||
const isFormValid = this.checkValidation()
|
||||
if (isFormValid) {
|
||||
if (ballotStore.ballotType === ballotStore.BallotType.keys) {
|
||||
const inputToAreBallotParamsValid = {
|
||||
|
@ -199,87 +206,115 @@ export class NewBallot extends React.Component {
|
|||
affectedKeyType: ballotStore.ballotKeys.keyType,
|
||||
miningKey: ballotStore.ballotKeys.miningKey.value,
|
||||
ballotType: ballotStore.ballotKeys.keysBallotType
|
||||
};
|
||||
let areBallotParamsValid = await contractsStore.votingToChangeKeys.areBallotParamsValid(inputToAreBallotParamsValid);
|
||||
}
|
||||
let areBallotParamsValid = await contractsStore.votingToChangeKeys.areBallotParamsValid(
|
||||
inputToAreBallotParamsValid
|
||||
)
|
||||
if (!areBallotParamsValid) {
|
||||
commonStore.hideLoading();
|
||||
return swal("Warning!", "The ballot input params are invalid", "warning");
|
||||
commonStore.hideLoading()
|
||||
return swal('Warning!', 'The ballot input params are invalid', 'warning')
|
||||
}
|
||||
}
|
||||
|
||||
let methodToCreateBallot;
|
||||
let contractType;
|
||||
let methodToCreateBallot
|
||||
let contractType
|
||||
let contractInstance
|
||||
let web3 = new Web3(contractsStore.web3Instance.currentProvider)
|
||||
switch (ballotStore.ballotType) {
|
||||
case ballotStore.BallotType.keys:
|
||||
methodToCreateBallot = this.createBallotForKeys;
|
||||
contractType = "votingToChangeKeys";
|
||||
break;
|
||||
methodToCreateBallot = this.createBallotForKeys
|
||||
contractType = 'votingToChangeKeys'
|
||||
contractInstance = contractsStore.votingToChangeKeys.votingToChangeKeysInstance
|
||||
break
|
||||
case ballotStore.BallotType.minThreshold:
|
||||
methodToCreateBallot = this.createBallotForMinThreshold;
|
||||
contractType = "votingToChangeMinThreshold";
|
||||
break;
|
||||
methodToCreateBallot = this.createBallotForMinThreshold
|
||||
contractType = 'votingToChangeMinThreshold'
|
||||
contractInstance = contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance
|
||||
break
|
||||
case ballotStore.BallotType.proxy:
|
||||
methodToCreateBallot = this.createBallotForProxy;
|
||||
contractType = "votingToChangeProxy";
|
||||
break;
|
||||
methodToCreateBallot = this.createBallotForProxy
|
||||
contractType = 'votingToChangeProxy'
|
||||
contractInstance = contractsStore.votingToChangeProxy.votingToChangeProxyInstance
|
||||
break
|
||||
default:
|
||||
break;
|
||||
break
|
||||
}
|
||||
|
||||
const startTime = moment.utc().add(constants.startTimeOffsetInMinutes, 'minutes').unix();
|
||||
methodToCreateBallot(startTime)
|
||||
.on("receipt", async (tx) => {
|
||||
commonStore.hideLoading();
|
||||
if (tx.status === true || tx.status === '0x1') {
|
||||
const newId = Number(tx.events.BallotCreated.returnValues.id);
|
||||
const card = await contractsStore.getCard(newId, contractType);
|
||||
ballotsStore.ballotCards.push(card);
|
||||
const startTime = moment
|
||||
.utc()
|
||||
.add(constants.startTimeOffsetInMinutes, 'minutes')
|
||||
.unix()
|
||||
|
||||
swal("Congratulations!", messages.BALLOT_CREATED_SUCCESS_MSG, "success").then((result) => {
|
||||
push(`${commonStore.rootPath}`);
|
||||
window.scrollTo(0, 0);
|
||||
});
|
||||
web3.eth.sendTransaction({
|
||||
from: contractsStore.votingKey,
|
||||
to: contractInstance.options.address,
|
||||
gasPrice: web3.utils.toWei('1', 'gwei'),
|
||||
data: methodToCreateBallot(startTime)
|
||||
}, async (error, hash) => {
|
||||
if (error) {
|
||||
commonStore.hideLoading()
|
||||
swal('Error!', error.message, 'error')
|
||||
} else {
|
||||
swal("Warning!", messages.BALLOT_CREATE_FAILED_TX, "warning");
|
||||
try {
|
||||
let tx
|
||||
do {
|
||||
await sleep(constants.getTransactionReceiptInterval)
|
||||
tx = await web3.eth.getTransactionReceipt(hash)
|
||||
} while (tx === null)
|
||||
|
||||
commonStore.hideLoading()
|
||||
if (tx.status === true || tx.status === '0x1') {
|
||||
const events = await contractInstance.getPastEvents('BallotCreated', {fromBlock: tx.blockNumber, toBlock: tx.blockNumber})
|
||||
const newId = Number(events[0].returnValues.id)
|
||||
const card = await contractsStore.getCard(newId, contractType)
|
||||
ballotsStore.ballotCards.push(card)
|
||||
|
||||
swal('Congratulations!', messages.BALLOT_CREATED_SUCCESS_MSG, 'success').then(result => {
|
||||
push(`${commonStore.rootPath}`)
|
||||
window.scrollTo(0, 0)
|
||||
})
|
||||
} else {
|
||||
swal('Warning!', messages.BALLOT_CREATE_FAILED_TX, 'warning')
|
||||
}
|
||||
} catch (e) {
|
||||
commonStore.hideLoading()
|
||||
swal('Error!', e.message, 'error')
|
||||
}
|
||||
}
|
||||
})
|
||||
.on("error", (e) => {
|
||||
commonStore.hideLoading();
|
||||
swal("Error!", e.message, "error");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
menuItemActive = (ballotType) => {
|
||||
const { ballotStore } = this.props;
|
||||
menuItemActive = ballotType => {
|
||||
const { ballotStore } = this.props
|
||||
if (ballotType == ballotStore.ballotType) {
|
||||
return 'ballot-types-i ballot-types-i_active';
|
||||
return 'ballot-types-i ballot-types-i_active'
|
||||
} else {
|
||||
return 'ballot-types-i';
|
||||
return 'ballot-types-i'
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { contractsStore, ballotStore } = this.props;
|
||||
let validator = ballotStore.isNewValidatorPersonalData ? <Validator />: "";
|
||||
let keysTypes = ballotStore.isBallotForKey ? <KeysTypes />: "";
|
||||
const { contractsStore, ballotStore } = this.props
|
||||
let validator = ballotStore.isNewValidatorPersonalData ? <Validator /> : ''
|
||||
let keysTypes = ballotStore.isBallotForKey ? <KeysTypes /> : ''
|
||||
let metadata
|
||||
let minThreshold = 0;
|
||||
let minThreshold = 0
|
||||
switch (ballotStore.ballotType) {
|
||||
case ballotStore.BallotType.keys:
|
||||
metadata = <BallotKeysMetadata />;
|
||||
minThreshold = contractsStore.keysBallotThreshold;
|
||||
break;
|
||||
metadata = <BallotKeysMetadata />
|
||||
minThreshold = contractsStore.keysBallotThreshold
|
||||
break
|
||||
case ballotStore.BallotType.minThreshold:
|
||||
metadata = <BallotMinThresholdMetadata />;
|
||||
minThreshold = contractsStore.minThresholdBallotThreshold;
|
||||
break;
|
||||
metadata = <BallotMinThresholdMetadata />
|
||||
minThreshold = contractsStore.minThresholdBallotThreshold
|
||||
break
|
||||
case ballotStore.BallotType.proxy:
|
||||
metadata = <BallotProxyMetadata />;
|
||||
minThreshold = contractsStore.proxyBallotThreshold;
|
||||
break;
|
||||
metadata = <BallotProxyMetadata />
|
||||
minThreshold = contractsStore.proxyBallotThreshold
|
||||
break
|
||||
default:
|
||||
break;
|
||||
break
|
||||
}
|
||||
return (
|
||||
<section className="container new">
|
||||
|
@ -289,19 +324,19 @@ export class NewBallot extends React.Component {
|
|||
<div className="ballot-types">
|
||||
<div
|
||||
className={this.menuItemActive(ballotStore.BallotType.keys)}
|
||||
onClick={(e) => ballotStore.changeBallotType(e, ballotStore.BallotType.keys)}
|
||||
onClick={e => ballotStore.changeBallotType(e, ballotStore.BallotType.keys)}
|
||||
>
|
||||
Validator Management Ballot
|
||||
</div>
|
||||
<div
|
||||
className={this.menuItemActive(ballotStore.BallotType.minThreshold)}
|
||||
onClick={(e) => ballotStore.changeBallotType(e, ballotStore.BallotType.minThreshold)}
|
||||
onClick={e => ballotStore.changeBallotType(e, ballotStore.BallotType.minThreshold)}
|
||||
>
|
||||
Consenus Threshold Ballot
|
||||
</div>
|
||||
<div
|
||||
className={this.menuItemActive(ballotStore.BallotType.proxy)}
|
||||
onClick={(e) => ballotStore.changeBallotType(e, ballotStore.BallotType.proxy)}
|
||||
onClick={e => ballotStore.changeBallotType(e, ballotStore.BallotType.proxy)}
|
||||
>
|
||||
Modify Proxy Contract Ballot
|
||||
</div>
|
||||
|
@ -309,7 +344,7 @@ export class NewBallot extends React.Component {
|
|||
<div className="info">
|
||||
<p className="info-title">Information of the ballot</p>
|
||||
<div className="info-i">
|
||||
Minimum {minThreshold} from {contractsStore.validatorsLength} validators required to pass the proposal<br />
|
||||
Minimum {minThreshold} from {contractsStore.validatorsLength} validators required to pass the proposal<br />
|
||||
</div>
|
||||
<div className="info-i">
|
||||
You can create {contractsStore.validatorLimits.keys} ballot for keys<br />
|
||||
|
@ -326,51 +361,57 @@ export class NewBallot extends React.Component {
|
|||
<div className="form-el">
|
||||
<label>Description of the ballot</label>
|
||||
<div>
|
||||
<textarea rows="4"
|
||||
value={ballotStore.memo}
|
||||
onChange={(e) => ballotStore.setMemo(e)}
|
||||
></textarea>
|
||||
<textarea rows="4" value={ballotStore.memo} onChange={e => ballotStore.setMemo(e)} />
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div className="hidden">
|
||||
<div className="left">
|
||||
<div className="radio-container">
|
||||
<input type="radio" name="ballot-type" id="ballot-for-validators"
|
||||
<input
|
||||
type="radio"
|
||||
name="ballot-type"
|
||||
id="ballot-for-validators"
|
||||
value={ballotStore.BallotType.keys}
|
||||
checked={ballotStore.isBallotForKey}
|
||||
onChange={e => ballotStore.changeBallotType(e, ballotStore.BallotType.keys)}
|
||||
/>
|
||||
<label htmlFor="ballot-for-validators" className="radio">Validator Management Ballot</label>
|
||||
<p className="hint">
|
||||
Ballot to add, remove or swap any type of key for existing or new validators.
|
||||
</p>
|
||||
/>
|
||||
<label htmlFor="ballot-for-validators" className="radio">
|
||||
Validator Management Ballot
|
||||
</label>
|
||||
<p className="hint">Ballot to add, remove or swap any type of key for existing or new validators.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="right">
|
||||
<div className="radio-container">
|
||||
<input type="radio" name="ballot-type" id="ballot-for-consensus"
|
||||
<input
|
||||
type="radio"
|
||||
name="ballot-type"
|
||||
id="ballot-for-consensus"
|
||||
value={ballotStore.BallotType.minThreshold}
|
||||
checked={ballotStore.isBallotForMinThreshold}
|
||||
onChange={e => ballotStore.changeBallotType(e, ballotStore.BallotType.minThreshold)}
|
||||
/>
|
||||
<label htmlFor="ballot-for-consensus" className="radio">Consenus Threshold Ballot</label>
|
||||
<p className="hint">
|
||||
Ballot to change the minimum threshold for consensus to vote for keys.
|
||||
</p>
|
||||
/>
|
||||
<label htmlFor="ballot-for-consensus" className="radio">
|
||||
Consenus Threshold Ballot
|
||||
</label>
|
||||
<p className="hint">Ballot to change the minimum threshold for consensus to vote for keys.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="left">
|
||||
<div className="radio-container">
|
||||
<input type="radio" name="ballot-type" id="ballot-for-proxy"
|
||||
<input
|
||||
type="radio"
|
||||
name="ballot-type"
|
||||
id="ballot-for-proxy"
|
||||
value={ballotStore.BallotType.proxy}
|
||||
checked={ballotStore.isBallotForProxy}
|
||||
onChange={e => ballotStore.changeBallotType(e, ballotStore.BallotType.proxy)}
|
||||
/>
|
||||
<label htmlFor="ballot-for-proxy" className="radio">Modify Proxy Contract Ballot</label>
|
||||
<p className="hint">
|
||||
Ballot to change one of the proxy contracts.
|
||||
</p>
|
||||
/>
|
||||
<label htmlFor="ballot-for-proxy" className="radio">
|
||||
Modify Proxy Contract Ballot
|
||||
</label>
|
||||
<p className="hint">Ballot to change one of the proxy contracts.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -378,10 +419,12 @@ export class NewBallot extends React.Component {
|
|||
{validator}
|
||||
{keysTypes}
|
||||
{metadata}
|
||||
<button type="button" className="add-ballot" onClick={e => this.onClick(e)}>Add ballot</button>
|
||||
<button type="button" className="add-ballot" onClick={e => this.onClick(e)}>
|
||||
Add ballot
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
let constants = {};
|
||||
constants.organization = 'poanetwork';
|
||||
constants.repoName = 'poa-chain-spec';
|
||||
constants.addressesSourceFile = 'contracts.json';
|
||||
let constants = {}
|
||||
constants.organization = 'poanetwork'
|
||||
constants.repoName = 'poa-chain-spec'
|
||||
constants.addressesSourceFile = 'contracts.json'
|
||||
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',
|
||||
'VotingToChangeProxyAddress': 'VotingToChangeProxyAddress.abi.json'
|
||||
};
|
||||
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',
|
||||
VotingToChangeProxyAddress: 'VotingToChangeProxyAddress.abi.json'
|
||||
}
|
||||
constants.NEW_MINING_KEY = {
|
||||
label: "New Mining Key",
|
||||
lastNameAndKey: "",
|
||||
fullName: "",
|
||||
value: "0x0000000000000000000000000000000000000000"
|
||||
};
|
||||
constants.minBallotDurationInDays = 2;
|
||||
constants.startTimeOffsetInMinutes = 5;
|
||||
constants.endTimeDefaultInMinutes = 2890;
|
||||
label: 'New Mining Key',
|
||||
lastNameAndKey: '',
|
||||
fullName: '',
|
||||
value: '0x0000000000000000000000000000000000000000'
|
||||
}
|
||||
constants.minBallotDurationInDays = 2
|
||||
constants.startTimeOffsetInMinutes = 5
|
||||
constants.endTimeDefaultInMinutes = 2890
|
||||
constants.getTransactionReceiptInterval = 5000
|
||||
module.exports = {
|
||||
constants
|
||||
}
|
||||
constants
|
||||
}
|
||||
|
|
|
@ -1,99 +1,104 @@
|
|||
import Web3 from 'web3';
|
||||
import { networkAddresses } from './addresses';
|
||||
import helpers from "./helpers";
|
||||
import Web3 from 'web3'
|
||||
import { networkAddresses } from './addresses'
|
||||
import helpers from './helpers'
|
||||
|
||||
export default class VotingToChangeKeys {
|
||||
async init({web3, netId}) {
|
||||
const {VOTING_TO_CHANGE_KEYS_ADDRESS} = networkAddresses(netId);
|
||||
console.log('VotingToChangeKeys address', VOTING_TO_CHANGE_KEYS_ADDRESS);
|
||||
let web3_10 = new Web3(web3.currentProvider);
|
||||
async init({ web3, netId }) {
|
||||
const { VOTING_TO_CHANGE_KEYS_ADDRESS } = networkAddresses(netId)
|
||||
console.log('VotingToChangeKeys address', VOTING_TO_CHANGE_KEYS_ADDRESS)
|
||||
let web3_10 = new Web3(web3.currentProvider)
|
||||
|
||||
const branch = helpers.getBranch(netId);
|
||||
const branch = helpers.getBranch(netId)
|
||||
|
||||
let votingToChangeKeysABI = await helpers.getABI(branch, 'VotingToChangeKeys')
|
||||
|
||||
this.votingToChangeKeysInstance = new web3_10.eth.Contract(votingToChangeKeysABI, VOTING_TO_CHANGE_KEYS_ADDRESS);
|
||||
this.gasPrice = web3_10.utils.toWei('1', 'gwei');
|
||||
this.votingToChangeKeysInstance = new web3_10.eth.Contract(votingToChangeKeysABI, VOTING_TO_CHANGE_KEYS_ADDRESS)
|
||||
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
|
||||
this.address = VOTING_TO_CHANGE_KEYS_ADDRESS
|
||||
}
|
||||
|
||||
//setters
|
||||
createBallot({startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, sender, memo}) {
|
||||
let method;
|
||||
createBallot({ startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo }) {
|
||||
let method
|
||||
if (this.votingToChangeKeysInstance.methods.createBallot) {
|
||||
method = this.votingToChangeKeysInstance.methods.createBallot;
|
||||
method = this.votingToChangeKeysInstance.methods.createBallot
|
||||
} else {
|
||||
method = this.votingToChangeKeysInstance.methods.createVotingForKeys;
|
||||
method = this.votingToChangeKeysInstance.methods.createVotingForKeys
|
||||
}
|
||||
return method(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo).send({from: sender, gasPrice: this.gasPrice});
|
||||
return method(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, memo).encodeABI()
|
||||
}
|
||||
|
||||
createBallotToAddNewValidator({startTime, endTime, affectedKey, newVotingKey, newPayoutKey, sender, memo}) {
|
||||
return this.votingToChangeKeysInstance.methods.createBallotToAddNewValidator(startTime, endTime, affectedKey, newVotingKey, newPayoutKey, memo).send({from: sender, gasPrice: this.gasPrice});
|
||||
createBallotToAddNewValidator({ startTime, endTime, affectedKey, newVotingKey, newPayoutKey, memo }) {
|
||||
return this.votingToChangeKeysInstance.methods
|
||||
.createBallotToAddNewValidator(startTime, endTime, affectedKey, newVotingKey, newPayoutKey, memo)
|
||||
.encodeABI()
|
||||
}
|
||||
|
||||
vote(_id, choice, sender) {
|
||||
return this.votingToChangeKeysInstance.methods.vote(_id, choice).send({from: sender, gasPrice: this.gasPrice});
|
||||
vote(_id, choice) {
|
||||
return this.votingToChangeKeysInstance.methods.vote(_id, choice).encodeABI()
|
||||
}
|
||||
|
||||
finalize(_id, sender) {
|
||||
return this.votingToChangeKeysInstance.methods.finalize(_id).send({from: sender, gasPrice: this.gasPrice});
|
||||
finalize(_id) {
|
||||
return this.votingToChangeKeysInstance.methods.finalize(_id).encodeABI()
|
||||
}
|
||||
|
||||
//getters
|
||||
areBallotParamsValid({ballotType, affectedKey, affectedKeyType, miningKey}) {
|
||||
return this.votingToChangeKeysInstance.methods.areBallotParamsValid(ballotType, affectedKey, affectedKeyType, miningKey).call();
|
||||
areBallotParamsValid({ ballotType, affectedKey, affectedKeyType, miningKey }) {
|
||||
return this.votingToChangeKeysInstance.methods
|
||||
.areBallotParamsValid(ballotType, affectedKey, affectedKeyType, miningKey)
|
||||
.call()
|
||||
}
|
||||
|
||||
doesMethodExist(methodName) {
|
||||
return this.votingToChangeKeysInstance && this.votingToChangeKeysInstance.methods[methodName];
|
||||
return this.votingToChangeKeysInstance && this.votingToChangeKeysInstance.methods[methodName]
|
||||
}
|
||||
|
||||
nextBallotId() {
|
||||
return this.votingToChangeKeysInstance.methods.nextBallotId().call();
|
||||
return this.votingToChangeKeysInstance.methods.nextBallotId().call()
|
||||
}
|
||||
|
||||
getBallotInfo(_id, _votingKey) {
|
||||
if (this.doesMethodExist('getBallotInfo')) {
|
||||
return this.votingToChangeKeysInstance.methods.getBallotInfo(_id).call();
|
||||
return this.votingToChangeKeysInstance.methods.getBallotInfo(_id).call()
|
||||
}
|
||||
return this.votingToChangeKeysInstance.methods.votingState(_id).call();
|
||||
return this.votingToChangeKeysInstance.methods.votingState(_id).call()
|
||||
}
|
||||
|
||||
hasAlreadyVoted(_id, votingKey) {
|
||||
return this.votingToChangeKeysInstance.methods.hasAlreadyVoted(_id, votingKey).call();
|
||||
return this.votingToChangeKeysInstance.methods.hasAlreadyVoted(_id, votingKey).call()
|
||||
}
|
||||
|
||||
isValidVote(_id, votingKey) {
|
||||
return this.votingToChangeKeysInstance.methods.isValidVote(_id, votingKey).call();
|
||||
return this.votingToChangeKeysInstance.methods.isValidVote(_id, votingKey).call()
|
||||
}
|
||||
|
||||
isActive(_id) {
|
||||
return this.votingToChangeKeysInstance.methods.isActive(_id).call();
|
||||
return this.votingToChangeKeysInstance.methods.isActive(_id).call()
|
||||
}
|
||||
|
||||
canBeFinalizedNow(_id) {
|
||||
if (this.doesMethodExist('canBeFinalizedNow')) {
|
||||
return this.votingToChangeKeysInstance.methods.canBeFinalizedNow(_id).call();
|
||||
return this.votingToChangeKeysInstance.methods.canBeFinalizedNow(_id).call()
|
||||
}
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
getMiningByVotingKey(_votingKey) {
|
||||
return this.votingToChangeKeysInstance.methods.getMiningByVotingKey(_votingKey).call();
|
||||
return this.votingToChangeKeysInstance.methods.getMiningByVotingKey(_votingKey).call()
|
||||
}
|
||||
|
||||
async getValidatorActiveBallots(_votingKey) {
|
||||
let miningKey;
|
||||
let miningKey
|
||||
try {
|
||||
miningKey = await this.getMiningByVotingKey(_votingKey);
|
||||
} catch(e) {
|
||||
miningKey = "0x0000000000000000000000000000000000000000";
|
||||
miningKey = await this.getMiningByVotingKey(_votingKey)
|
||||
} catch (e) {
|
||||
miningKey = '0x0000000000000000000000000000000000000000'
|
||||
}
|
||||
return await this.votingToChangeKeysInstance.methods.validatorActiveBallots(miningKey).call();
|
||||
return await this.votingToChangeKeysInstance.methods.validatorActiveBallots(miningKey).call()
|
||||
}
|
||||
|
||||
async getBallotLimit(_votingKey) {
|
||||
const currentLimit = await this.votingToChangeKeysInstance.methods.getBallotLimitPerValidator().call();
|
||||
return currentLimit - await this.getValidatorActiveBallots(_votingKey);
|
||||
const currentLimit = await this.votingToChangeKeysInstance.methods.getBallotLimitPerValidator().call()
|
||||
return currentLimit - (await this.getValidatorActiveBallots(_votingKey))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,94 +1,100 @@
|
|||
import Web3 from 'web3';
|
||||
import { networkAddresses } from './addresses';
|
||||
import helpers from "./helpers";
|
||||
import Web3 from 'web3'
|
||||
import { networkAddresses } from './addresses'
|
||||
import helpers from './helpers'
|
||||
|
||||
export default class VotingToChangeMinThreshold {
|
||||
async init({web3, netId}) {
|
||||
const {VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS} = networkAddresses(netId);
|
||||
console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS);
|
||||
let web3_10 = new Web3(web3.currentProvider);
|
||||
async init({ web3, netId }) {
|
||||
const { VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS } = networkAddresses(netId)
|
||||
console.log('VotingToChangeMinThreshold address', VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS)
|
||||
let web3_10 = new Web3(web3.currentProvider)
|
||||
|
||||
const branch = helpers.getBranch(netId);
|
||||
const branch = helpers.getBranch(netId)
|
||||
|
||||
let votingToChangeMinThresholdABI = await helpers.getABI(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.votingToChangeMinThresholdInstance = new web3_10.eth.Contract(
|
||||
votingToChangeMinThresholdABI,
|
||||
VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
|
||||
)
|
||||
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
|
||||
this.address = VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS
|
||||
}
|
||||
|
||||
//setters
|
||||
createBallot({startTime, endTime, proposedValue, sender, memo}) {
|
||||
let method;
|
||||
createBallot({ startTime, endTime, proposedValue, memo }) {
|
||||
let method
|
||||
if (this.votingToChangeMinThresholdInstance.methods.createBallot) {
|
||||
method = this.votingToChangeMinThresholdInstance.methods.createBallot;
|
||||
method = this.votingToChangeMinThresholdInstance.methods.createBallot
|
||||
} else {
|
||||
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold;
|
||||
method = this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold
|
||||
}
|
||||
return method(startTime, endTime, proposedValue, memo).send({from: sender, gasPrice: this.gasPrice})
|
||||
return method(startTime, endTime, proposedValue, memo).encodeABI()
|
||||
}
|
||||
|
||||
vote(_id, choice, sender) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.vote(_id, choice).send({from: sender, gasPrice: this.gasPrice})
|
||||
vote(_id, choice) {
|
||||
return this.votingToChangeMinThresholdInstance.methods
|
||||
.vote(_id, choice)
|
||||
.encodeABI()
|
||||
}
|
||||
|
||||
finalize(_id, sender) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).send({from: sender, gasPrice: this.gasPrice})
|
||||
finalize(_id) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).encodeABI()
|
||||
}
|
||||
|
||||
//getters
|
||||
doesMethodExist(methodName) {
|
||||
if (this.votingToChangeMinThresholdInstance.methods[methodName]) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
nextBallotId() {
|
||||
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call()
|
||||
}
|
||||
|
||||
getBallotInfo(_id, _votingKey) {
|
||||
if (this.doesMethodExist('getBallotInfo')) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call()
|
||||
}
|
||||
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call()
|
||||
}
|
||||
|
||||
hasAlreadyVoted(_id, votingKey) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.hasAlreadyVoted(_id, votingKey).call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.hasAlreadyVoted(_id, votingKey).call()
|
||||
}
|
||||
|
||||
isValidVote(_id, votingKey) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call()
|
||||
}
|
||||
|
||||
isActive(_id) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call()
|
||||
}
|
||||
|
||||
canBeFinalizedNow(_id) {
|
||||
if (this.doesMethodExist('canBeFinalizedNow')) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.canBeFinalizedNow(_id).call()
|
||||
}
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
getMiningByVotingKey(_votingKey) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.getMiningByVotingKey(_votingKey).call();
|
||||
return this.votingToChangeMinThresholdInstance.methods.getMiningByVotingKey(_votingKey).call()
|
||||
}
|
||||
|
||||
async getValidatorActiveBallots(_votingKey) {
|
||||
let miningKey;
|
||||
let miningKey
|
||||
try {
|
||||
miningKey = await this.getMiningByVotingKey(_votingKey);
|
||||
} catch(e) {
|
||||
miningKey = "0x0000000000000000000000000000000000000000";
|
||||
miningKey = await this.getMiningByVotingKey(_votingKey)
|
||||
} catch (e) {
|
||||
miningKey = '0x0000000000000000000000000000000000000000'
|
||||
}
|
||||
return await this.votingToChangeMinThresholdInstance.methods.validatorActiveBallots(miningKey).call();
|
||||
return await this.votingToChangeMinThresholdInstance.methods.validatorActiveBallots(miningKey).call()
|
||||
}
|
||||
|
||||
async getBallotLimit(_votingKey) {
|
||||
const currentLimit = await this.votingToChangeMinThresholdInstance.methods.getBallotLimitPerValidator().call();
|
||||
return currentLimit - await this.getValidatorActiveBallots(_votingKey);
|
||||
const currentLimit = await this.votingToChangeMinThresholdInstance.methods.getBallotLimitPerValidator().call()
|
||||
return currentLimit - (await this.getValidatorActiveBallots(_votingKey))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,94 +1,95 @@
|
|||
import Web3 from 'web3';
|
||||
import { networkAddresses } from './addresses';
|
||||
import helpers from "./helpers";
|
||||
import Web3 from 'web3'
|
||||
import { networkAddresses } from './addresses'
|
||||
import helpers from './helpers'
|
||||
|
||||
export default class VotingToChangeProxy {
|
||||
async init({web3, netId}) {
|
||||
const {VOTING_TO_CHANGE_PROXY_ADDRESS} = networkAddresses(netId);
|
||||
async init({ web3, netId }) {
|
||||
const { VOTING_TO_CHANGE_PROXY_ADDRESS } = networkAddresses(netId)
|
||||
console.log('VotingToChangeProxy address', VOTING_TO_CHANGE_PROXY_ADDRESS)
|
||||
let web3_10 = new Web3(web3.currentProvider);
|
||||
let web3_10 = new Web3(web3.currentProvider)
|
||||
|
||||
const branch = helpers.getBranch(netId);
|
||||
const branch = helpers.getBranch(netId)
|
||||
|
||||
let votingToChangeProxyABI = await helpers.getABI(branch, 'VotingToChangeProxyAddress')
|
||||
|
||||
this.votingToChangeProxyInstance = new web3_10.eth.Contract(votingToChangeProxyABI, VOTING_TO_CHANGE_PROXY_ADDRESS);
|
||||
this.gasPrice = web3_10.utils.toWei('1', 'gwei');
|
||||
this.votingToChangeProxyInstance = new web3_10.eth.Contract(votingToChangeProxyABI, VOTING_TO_CHANGE_PROXY_ADDRESS)
|
||||
this.gasPrice = web3_10.utils.toWei('1', 'gwei')
|
||||
this.address = VOTING_TO_CHANGE_PROXY_ADDRESS
|
||||
}
|
||||
|
||||
//setters
|
||||
createBallot({startTime, endTime, proposedValue, contractType, sender, memo}) {
|
||||
let method;
|
||||
createBallot({ startTime, endTime, proposedValue, contractType, memo }) {
|
||||
let method
|
||||
if (this.votingToChangeProxyInstance.methods.createBallot) {
|
||||
method = this.votingToChangeProxyInstance.methods.createBallot;
|
||||
method = this.votingToChangeProxyInstance.methods.createBallot
|
||||
} else {
|
||||
method = this.votingToChangeProxyInstance.methods.createBallotToChangeProxyAddress;
|
||||
method = this.votingToChangeProxyInstance.methods.createBallotToChangeProxyAddress
|
||||
}
|
||||
return method(startTime, endTime, proposedValue, contractType, memo).send({from: sender, gasPrice: this.gasPrice})
|
||||
return method(startTime, endTime, proposedValue, contractType, memo).encodeABI()
|
||||
}
|
||||
|
||||
vote(_id, choice, sender) {
|
||||
return this.votingToChangeProxyInstance.methods.vote(_id, choice).send({from: sender, gasPrice: this.gasPrice})
|
||||
vote(_id, choice) {
|
||||
return this.votingToChangeProxyInstance.methods.vote(_id, choice).encodeABI()
|
||||
}
|
||||
|
||||
finalize(_id, sender) {
|
||||
return this.votingToChangeProxyInstance.methods.finalize(_id).send({from: sender, gasPrice: this.gasPrice})
|
||||
finalize(_id) {
|
||||
return this.votingToChangeProxyInstance.methods.finalize(_id).encodeABI()
|
||||
}
|
||||
|
||||
//getters
|
||||
doesMethodExist(methodName) {
|
||||
if (this.votingToChangeProxyInstance.methods[methodName]) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
nextBallotId() {
|
||||
return this.votingToChangeProxyInstance.methods.nextBallotId().call();
|
||||
return this.votingToChangeProxyInstance.methods.nextBallotId().call()
|
||||
}
|
||||
|
||||
getBallotInfo(_id, _votingKey) {
|
||||
if (this.doesMethodExist('getBallotInfo')) {
|
||||
return this.votingToChangeProxyInstance.methods.getBallotInfo(_id, _votingKey).call();
|
||||
return this.votingToChangeProxyInstance.methods.getBallotInfo(_id, _votingKey).call()
|
||||
}
|
||||
return this.votingToChangeProxyInstance.methods.votingState(_id).call();
|
||||
return this.votingToChangeProxyInstance.methods.votingState(_id).call()
|
||||
}
|
||||
|
||||
hasAlreadyVoted(_id, votingKey) {
|
||||
return this.votingToChangeProxyInstance.methods.hasAlreadyVoted(_id, votingKey).call();
|
||||
return this.votingToChangeProxyInstance.methods.hasAlreadyVoted(_id, votingKey).call()
|
||||
}
|
||||
|
||||
isValidVote(_id, votingKey) {
|
||||
return this.votingToChangeProxyInstance.methods.isValidVote(_id, votingKey).call();
|
||||
return this.votingToChangeProxyInstance.methods.isValidVote(_id, votingKey).call()
|
||||
}
|
||||
|
||||
isActive(_id) {
|
||||
return this.votingToChangeProxyInstance.methods.isActive(_id).call();
|
||||
return this.votingToChangeProxyInstance.methods.isActive(_id).call()
|
||||
}
|
||||
|
||||
canBeFinalizedNow(_id) {
|
||||
if (this.doesMethodExist('canBeFinalizedNow')) {
|
||||
return this.votingToChangeProxyInstance.methods.canBeFinalizedNow(_id).call();
|
||||
return this.votingToChangeProxyInstance.methods.canBeFinalizedNow(_id).call()
|
||||
}
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
getMiningByVotingKey(_votingKey) {
|
||||
return this.votingToChangeProxyInstance.methods.getMiningByVotingKey(_votingKey).call();
|
||||
return this.votingToChangeProxyInstance.methods.getMiningByVotingKey(_votingKey).call()
|
||||
}
|
||||
|
||||
async getValidatorActiveBallots(_votingKey) {
|
||||
let miningKey;
|
||||
let miningKey
|
||||
try {
|
||||
miningKey = await this.getMiningByVotingKey(_votingKey);
|
||||
} catch(e) {
|
||||
miningKey = "0x0000000000000000000000000000000000000000";
|
||||
miningKey = await this.getMiningByVotingKey(_votingKey)
|
||||
} catch (e) {
|
||||
miningKey = '0x0000000000000000000000000000000000000000'
|
||||
}
|
||||
return await this.votingToChangeProxyInstance.methods.validatorActiveBallots(miningKey).call();
|
||||
return await this.votingToChangeProxyInstance.methods.validatorActiveBallots(miningKey).call()
|
||||
}
|
||||
|
||||
async getBallotLimit(_votingKey) {
|
||||
const currentLimit = await this.votingToChangeProxyInstance.methods.getBallotLimitPerValidator().call();
|
||||
return currentLimit - await this.getValidatorActiveBallots(_votingKey);
|
||||
const currentLimit = await this.votingToChangeProxyInstance.methods.getBallotLimitPerValidator().call()
|
||||
return currentLimit - (await this.getValidatorActiveBallots(_votingKey))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { addressesURL, wrongRepoAlert } from "./helpers";
|
||||
import { addressesURL, wrongRepoAlert } from './helpers'
|
||||
// const local = {
|
||||
// VOTING_TO_CHANGE_KEYS_ADDRESS: '0xecdbe3937cf6ff27f70480855cfe03254f915b48',
|
||||
// VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS: '0x5ae30d4c8892292e0d8164f87a2e12dff9dc99e1',
|
||||
|
@ -8,45 +8,45 @@ import { addressesURL, wrongRepoAlert } from "./helpers";
|
|||
// POA_ADDRESS: '0xf472e0e43570b9afaab67089615080cf7c20018d',
|
||||
// }
|
||||
|
||||
let SOKOL_ADDRESSES = {};
|
||||
let CORE_ADDRESSES = {};
|
||||
let SOKOL_ADDRESSES = {}
|
||||
let CORE_ADDRESSES = {}
|
||||
|
||||
async function getContractsAddresses(branch) {
|
||||
let addr = addressesURL(branch);
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(addr);
|
||||
} catch(e) {
|
||||
return wrongRepoAlert(addr);
|
||||
}
|
||||
let addr = addressesURL(branch)
|
||||
let response
|
||||
try {
|
||||
response = await fetch(addr)
|
||||
} catch (e) {
|
||||
return wrongRepoAlert(addr)
|
||||
}
|
||||
|
||||
let contracts = await response.json();
|
||||
let contracts = await response.json()
|
||||
|
||||
switch (branch) {
|
||||
case 'core':
|
||||
CORE_ADDRESSES = contracts;
|
||||
break;
|
||||
case 'sokol':
|
||||
SOKOL_ADDRESSES = contracts;
|
||||
break;
|
||||
default:
|
||||
CORE_ADDRESSES = contracts;
|
||||
break;
|
||||
}
|
||||
switch (branch) {
|
||||
case 'core':
|
||||
CORE_ADDRESSES = contracts
|
||||
break
|
||||
case 'sokol':
|
||||
SOKOL_ADDRESSES = contracts
|
||||
break
|
||||
default:
|
||||
CORE_ADDRESSES = contracts
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function getAddresses(netId) {
|
||||
switch (netId) {
|
||||
case '77':
|
||||
return SOKOL_ADDRESSES
|
||||
case '99':
|
||||
return CORE_ADDRESSES
|
||||
default:
|
||||
return CORE_ADDRESSES
|
||||
}
|
||||
switch (netId) {
|
||||
case '77':
|
||||
return SOKOL_ADDRESSES
|
||||
case '99':
|
||||
return CORE_ADDRESSES
|
||||
default:
|
||||
return CORE_ADDRESSES
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getContractsAddresses: getContractsAddresses,
|
||||
networkAddresses: getAddresses
|
||||
}
|
||||
getContractsAddresses: getContractsAddresses,
|
||||
networkAddresses: getAddresses
|
||||
}
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
var toAscii = (hex) => {
|
||||
var toAscii = hex => {
|
||||
var str = '',
|
||||
i = 0,
|
||||
l = hex.length;
|
||||
i = 0,
|
||||
l = hex.length
|
||||
if (hex.substring(0, 2) === '0x') {
|
||||
i = 2;
|
||||
i = 2
|
||||
}
|
||||
for (; i < l; i+=2) {
|
||||
var code = parseInt(hex.substr(i, 2), 16);
|
||||
if (code === 0) continue; // this is added
|
||||
str += String.fromCharCode(code);
|
||||
for (; i < l; i += 2) {
|
||||
var code = parseInt(hex.substr(i, 2), 16)
|
||||
if (code === 0) continue // this is added
|
||||
str += String.fromCharCode(code)
|
||||
}
|
||||
return str;
|
||||
};
|
||||
return str
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
toAscii: toAscii
|
||||
toAscii: toAscii,
|
||||
sleep: sleep
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue