Display votes amount fix

This commit is contained in:
viktor 2017-12-26 13:07:55 +03:00
parent df8362b294
commit e4f1ac8a3f
11 changed files with 362 additions and 187 deletions

View File

@ -20,27 +20,33 @@ export class BallotKeysCard extends React.Component {
@observable creator;
@observable progress;
@observable totalVoters;
@observable votesForNumber;
@observable votesAgainstNumber;
@observable votesForPercents;
@observable votesAgainstPercents;
@observable isFinalized;
@observable isFiltered;
@computed get getVotesFor() {
this.votesForNumber = (this.totalVoters + this.progress) / 2
@computed get votesForNumber() {
let votes = (this.totalVoters + this.progress) / 2;
return votes;
}
@computed get getVotesForPercents() {
this.votesForPercents = this.votesForNumber / this.totalVoters * 100
@computed get votesForPercents() {
if (this.totalVoters <= 0)
return 0;
let votesPercents = Math.round(this.votesForNumber / this.totalVoters * 100);
return votesPercents;
}
@computed get getVotesAgainst() {
this.votesAgainstNumber = (this.totalVoters - this.progress) / 2
@computed get votesAgainstNumber() {
let votes = (this.totalVoters - this.progress) / 2;
return votes;
}
@computed get getVotesAgainstPercents() {
this.votesAgainstPercents = this.votesAgainstNumber / this.totalVoters * 100
@computed get votesAgainstPercents() {
if (this.totalVoters <= 0)
return 0;
let votesPercents = Math.round(this.votesAgainstNumber / this.totalVoters * 100);
return votesPercents;
}
@action("Get ballotTypeDisplayName")
@ -82,16 +88,16 @@ export class BallotKeysCard extends React.Component {
}
@action("Get start time of keys ballot")
getStartTime = async (_id) => {
const { contractsStore } = this.props;
let startTime = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getStartTime(_id).call()
getStartTime = async () => {
const { contractsStore, id } = this.props;
let startTime = await contractsStore.votingToChangeKeys.getStartTime(id);
this.startTime = moment.utc(startTime * 1000).format('DD/MM/YYYY h:mm:ss A');
}
@action("Get end time of keys ballot")
getEndTime = async (_id) => {
const { contractsStore } = this.props;
let endTime = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getEndTime(_id).call()
getEndTime = async () => {
const { contractsStore, id } = this.props;
let endTime = await contractsStore.votingToChangeKeys.getEndTime(id);
this.endTime = moment.utc(endTime * 1000).format('DD/MM/YYYY h:mm:ss A');
}
@ -108,47 +114,47 @@ export class BallotKeysCard extends React.Component {
}
@action("Get times")
getTimes = async (_id) => {
await this.getStartTime(_id);
await this.getEndTime(_id);
getTimes = async () => {
await this.getStartTime();
await this.getEndTime();
this.calcTimeToFinish();
}
@action("Get ballot type of keys ballot")
getBallotType = async (_id) => {
const { contractsStore } = this.props;
let ballotType = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getBallotType(_id).call()
getBallotType = async () => {
const { contractsStore, id } = this.props;
let ballotType = await contractsStore.votingToChangeKeys.getBallotType(id);
this.ballotType = ballotType;
this.getBallotTypeDisplayName(ballotType);
}
@action("Get affected key type of keys ballot")
getAffectedKeyType = async (_id) => {
const { contractsStore } = this.props;
let affectedKeyType = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getAffectedKeyType(_id).call()
getAffectedKeyType = async () => {
const { contractsStore, id } = this.props;
let affectedKeyType = await contractsStore.votingToChangeKeys.getAffectedKeyType(id);
this.affectedKeyType = affectedKeyType;
this.getAffectedKeyTypeDisplayName(affectedKeyType);
}
@action("Get affected key of keys ballot")
getAffectedKey = async (_id) => {
const { contractsStore } = this.props;
let affectedKey = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getAffectedKey(_id).call()
getAffectedKey = async () => {
const { contractsStore, id } = this.props;
let affectedKey = await contractsStore.votingToChangeKeys.getAffectedKey(id);
this.affectedKey = affectedKey;
}
@action("Get creator")
getCreator = async (_id) => {
const { contractsStore } = this.props;
let votingState = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.votingState(_id).call()
getCreator = async () => {
const { contractsStore, id } = this.props;
let votingState = await contractsStore.votingToChangeKeys.votingState(id);
this.getValidatorFullname(votingState.creator);
}
@action("Get validator full name")
getValidatorFullname = async (_miningKey) => {
const { contractsStore } = this.props;
let validator = await contractsStore.validatorMetadata.metadataInstance.methods.validators(_miningKey).call();
let validator = await contractsStore.validatorMetadata.validators(_miningKey);
let firstName = toAscii(validator.firstName);
let lastName = toAscii(validator.lastName);
let fullName = `${firstName} ${lastName}`
@ -156,37 +162,39 @@ export class BallotKeysCard extends React.Component {
}
@action("Get total voters")
getTotalVoters = async (_id) => {
const { contractsStore } = this.props;
this.totalVoters = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getTotalVoters(_id).call();
getTotalVoters = async () => {
const { contractsStore, id } = this.props;
let totalVoters = await contractsStore.votingToChangeKeys.getTotalVoters(id);
this.totalVoters = Number(totalVoters);
}
@action("Get progress")
getProgress = async (_id) => {
const { contractsStore } = this.props;
this.progress = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getProgress(_id).call();
getProgress = async () => {
const { contractsStore, id } = this.props;
let progress = await contractsStore.votingToChangeKeys.getProgress(id);
this.progress = Number(progress);
}
@action("Get isFinalized")
getIsFinalized = async(_id) => {
const { contractsStore } = this.props;
this.isFinalized = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getIsFinalized(_id).call();
getIsFinalized = async() => {
const { contractsStore, id } = this.props;
this.isFinalized = await contractsStore.votingToChangeKeys.getIsFinalized(id);
}
isValidaVote = async () => {
const { contractsStore } = this.props;
let isValidVote = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.isValidVote(this.props.id, contractsStore.votingKey).call();
const { contractsStore, id } = this.props;
let isValidVote = await contractsStore.votingToChangeKeys.isValidVote(id, contractsStore.votingKey);
return isValidVote;
}
isActive = async () => {
const { contractsStore } = this.props;
let isActive = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.isActive(this.props.id).call();
const { contractsStore, id } = this.props;
let isActive = await contractsStore.votingToChangeKeys.isActive(id);
return isActive;
}
vote = async (e, _type) => {
const { commonStore, contractsStore } = this.props;
const { commonStore, contractsStore, id } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", constants.INVALID_VOTING_KEY_MSG, "warning");
@ -199,7 +207,7 @@ export class BallotKeysCard extends React.Component {
swal("Warning!", constants.INVALID_VOTE_MSG, "warning");
return;
}
contractsStore.votingToChangeKeys.vote(this.props.id, _type, contractsStore.votingKey)
contractsStore.votingToChangeKeys.vote(id, _type, contractsStore.votingKey)
.on("receipt", () => {
commonStore.hideLoading();
swal("Congratulations!", constants.VOTED_SUCCESS_MSG, "success").then((result) => {
@ -213,7 +221,7 @@ export class BallotKeysCard extends React.Component {
}
finalize = async (e) => {
const { commonStore, contractsStore } = this.props;
const { commonStore, contractsStore, id } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", constants.INVALID_VOTING_KEY_MSG, "warning");
@ -230,7 +238,7 @@ export class BallotKeysCard extends React.Component {
swal("Warning!", constants.INVALID_FINALIZE_MSG, "warning");
return;
}
contractsStore.votingToChangeKeys.finalize(this.props.id, contractsStore.votingKey)
contractsStore.votingToChangeKeys.finalize(id, contractsStore.votingKey)
.on("receipt", () => {
commonStore.hideLoading();
swal("Congratulations!", constants.FINALIZED_SUCCESS_MSG, "success").then((result) => {
@ -245,19 +253,15 @@ export class BallotKeysCard extends React.Component {
constructor(props) {
super(props);
this.votesForNumber = 0;
this.votesAgainstNumber = 0;
this.votesForPercents = 0;
this.votesAgainstPercents = 0;
this.isFinalized = false;
this.getTimes(this.props.id);
this.getAffectedKey(this.props.id);
this.getAffectedKeyType(this.props.id);
this.getBallotType(this.props.id);
this.getCreator(this.props.id);
this.getTotalVoters(this.props.id);
this.getProgress(this.props.id);
this.getIsFinalized(this.props.id);
this.getTimes();
this.getAffectedKey();
this.getAffectedKeyType();
this.getBallotType();
this.getCreator();
this.getTotalVoters();
this.getProgress();
this.getIsFinalized();
}
checkFilter = () => {
@ -267,7 +271,7 @@ export class BallotKeysCard extends React.Component {
}
render () {
let { commonStore, contractsStore } = this.props;
let { contractsStore } = this.props;
let ballotClass = this.checkFilter() ? "ballots-i display-none" : "ballots-i";
return (
<div className={ballotClass}>

View File

@ -1,6 +1,6 @@
import React from 'react';
import moment from 'moment';
import { observable, action } from "mobx";
import { observable, action, computed } from "mobx";
import { inject, observer } from "mobx-react";
import { toAscii } from "../helpers";
import { constants } from "../constants";
@ -16,22 +16,44 @@ export class BallotMinThresholdCard extends React.Component {
@observable creator;
@observable progress;
@observable totalVoters;
@observable votesForNumber;
@observable votesAgainstNumber;
@observable votesForPercents;
@observable votesAgainstPercents;
@computed get votesForNumber() {
let votes = (this.totalVoters + this.progress) / 2;
return votes;
}
@computed get votesForPercents() {
if (this.totalVoters <= 0)
return 0;
let votesPercents = Math.round(this.votesForNumber / this.totalVoters * 100);
return votesPercents;
}
@computed get votesAgainstNumber() {
let votes = (this.totalVoters - this.progress) / 2;
return votes;
}
@computed get votesAgainstPercents() {
if (this.totalVoters <= 0)
return 0;
let votesPercents = Math.round(this.votesAgainstNumber / this.totalVoters * 100);
return votesPercents;
}
@action("Get start time of min threshold ballot")
getStartTime = async (_id) => {
const { contractsStore } = this.props;
let startTime = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.getStartTime(_id).call()
getStartTime = async () => {
const { contractsStore, id } = this.props;
let startTime = await contractsStore.votingToChangeMinThreshold.getStartTime(id);
this.startTime = moment.utc(startTime * 1000).format('DD/MM/YYYY h:mm:ss A');
}
@action("Get end time of min threshold ballot")
getEndTime = async (_id) => {
const { contractsStore } = this.props;
let endTime = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call()
getEndTime = async () => {
const { contractsStore, id } = this.props;
let endTime = await contractsStore.votingToChangeMinThreshold.getEndTime(id);
this.endTime = moment.utc(endTime * 1000).format('DD/MM/YYYY h:mm:ss A');
}
@ -48,30 +70,30 @@ export class BallotMinThresholdCard extends React.Component {
}
@action("Get times")
getTimes = async (_id) => {
await this.getStartTime(_id);
await this.getEndTime(_id);
getTimes = async () => {
await this.getStartTime();
await this.getEndTime();
this.calcTimeToFinish();
}
@action("Get proposed value of min threshold ballot")
getProposedValue = async (_id) => {
const { contractsStore } = this.props;
let proposedValue = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.getProposedValue(_id).call()
getProposedValue = async () => {
const { contractsStore, id } = this.props;
let proposedValue = await contractsStore.votingToChangeMinThreshold.getProposedValue(id);
this.proposedValue = proposedValue;
}
@action("Get creator")
getCreator = async (_id) => {
const { contractsStore } = this.props;
let votingState = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.votingState(_id).call()
getCreator = async () => {
const { contractsStore, id } = this.props;
let votingState = await contractsStore.votingToChangeMinThreshold.votingState(id);
this.getValidatorFullname(votingState.creator);
}
@action("Get validator full name")
getValidatorFullname = async (_miningKey) => {
const { contractsStore } = this.props;
let validator = await contractsStore.validatorMetadata.metadataInstance.methods.validators(_miningKey).call();
let validator = await contractsStore.validatorMetadata.validators(_miningKey);
let firstName = toAscii(validator.firstName);
let lastName = toAscii(validator.lastName);
let fullName = `${firstName} ${lastName}`
@ -79,37 +101,39 @@ export class BallotMinThresholdCard extends React.Component {
}
@action("Get total voters")
getTotalVoters = async (_id) => {
const { contractsStore } = this.props;
this.totalVoters = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.getTotalVoters(_id).call();
getTotalVoters = async () => {
const { contractsStore, id } = this.props;
let totalVoters = await contractsStore.votingToChangeMinThreshold.getTotalVoters(id);
this.totalVoters = Number(totalVoters);
}
@action("Get progress")
getProgress = async (_id) => {
const { contractsStore } = this.props;
this.progress = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.getProgress(_id).call();
getProgress = async () => {
const { contractsStore, id } = this.props;
let progress = await contractsStore.votingToChangeMinThreshold.getProgress(id);
this.progress = Number(progress);
}
@action("Get isFinalized")
getIsFinalized = async(_id) => {
const { contractsStore } = this.props;
this.isFinalized = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.getIsFinalized(_id).call();
getIsFinalized = async() => {
const { contractsStore, id } = this.props;
this.isFinalized = await contractsStore.votingToChangeMinThreshold.getIsFinalized(id);
}
isValidaVote = async () => {
const { contractsStore } = this.props;
let isValidVote = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.isValidVote(this.props.id, contractsStore.votingKey).call();
const { contractsStore, id } = this.props;
let isValidVote = await contractsStore.votingToChangeMinThreshold.isValidVote(id, contractsStore.votingKey);
return isValidVote;
}
isActive = async () => {
const { contractsStore } = this.props;
let isActive = await contractsStore.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.methods.isActive(this.props.id).call();
const { contractsStore, id } = this.props;
let isActive = await contractsStore.votingToChangeMinThreshold.isActive(id);
return isActive;
}
vote = async (e, _type) => {
const { commonStore, contractsStore } = this.props;
const { commonStore, contractsStore, id } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", constants.INVALID_VOTING_KEY_MSG, "warning");
@ -122,7 +146,7 @@ export class BallotMinThresholdCard extends React.Component {
swal("Warning!", constants.INVALID_VOTE_MSG, "warning");
return;
}
contractsStore.votingToChangeMinThreshold.vote(this.props.id, _type, contractsStore.votingKey)
contractsStore.votingToChangeMinThreshold.vote(id, _type, contractsStore.votingKey)
.on("receipt", () => {
commonStore.hideLoading();
swal("Congratulations!", constants.VOTED_SUCCESS_MSG, "success").then((result) => {
@ -136,7 +160,7 @@ export class BallotMinThresholdCard extends React.Component {
}
finalize = async (e) => {
const { commonStore, contractsStore } = this.props;
const { commonStore, contractsStore, id } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", constants.INVALID_VOTING_KEY_MSG, "warning");
@ -153,7 +177,7 @@ export class BallotMinThresholdCard extends React.Component {
swal("Warning!", constants.INVALID_FINALIZE_MSG, "warning");
return;
}
contractsStore.votingToChangeMinThreshold.finalize(this.props.id, contractsStore.votingKey)
contractsStore.votingToChangeMinThreshold.finalize(id, contractsStore.votingKey)
.on("receipt", () => {
commonStore.hideLoading();
swal("Congratulations!", constants.FINALIZED_SUCCESS_MSG, "success").then((result) => {
@ -168,10 +192,6 @@ export class BallotMinThresholdCard extends React.Component {
constructor(props) {
super(props);
this.votesForNumber = 0;
this.votesAgainstNumber = 0;
this.votesForPercents = 0;
this.votesAgainstPercents = 0;
this.getTimes(this.props.id);
this.getProposedValue(this.props.id);
this.getCreator(this.props.id);

View File

@ -1,6 +1,6 @@
import React from 'react';
import moment from 'moment';
import { observable, action } from "mobx";
import { observable, action, computed } from "mobx";
import { inject, observer } from "mobx-react";
import { toAscii } from "../helpers";
import { constants } from "../constants";
@ -17,22 +17,44 @@ export class BallotProxyCard extends React.Component {
@observable creator;
@observable progress;
@observable totalVoters;
@observable votesForNumber;
@observable votesAgainstNumber;
@observable votesForPercents;
@observable votesAgainstPercents;
@computed get votesForNumber() {
let votes = (this.totalVoters + this.progress) / 2;
return votes;
}
@computed get votesForPercents() {
if (this.totalVoters <= 0)
return 0;
let votesPercents = Math.round(this.votesForNumber / this.totalVoters * 100);
return votesPercents;
}
@computed get votesAgainstNumber() {
let votes = (this.totalVoters - this.progress) / 2;
return votes;
}
@computed get votesAgainstPercents() {
if (this.totalVoters <= 0)
return 0;
let votesPercents = Math.round(this.votesAgainstNumber / this.totalVoters * 100);
return votesPercents;
}
@action("Get start time of proxy ballot")
getStartTime = async (_id) => {
const { contractsStore } = this.props;
let startTime = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.getStartTime(_id).call()
getStartTime = async () => {
const { contractsStore, id } = this.props;
let startTime = await contractsStore.votingToChangeProxy.getStartTime(id);
this.startTime = moment.utc(startTime * 1000).format('DD/MM/YYYY h:mm:ss A');
}
@action("Get end time of proxy ballot")
getEndTime = async (_id) => {
const { contractsStore } = this.props;
let endTime = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.getEndTime(_id).call()
getEndTime = async () => {
const { contractsStore, id } = this.props;
let endTime = await contractsStore.votingToChangeProxy.getEndTime(id);
this.endTime = moment.utc(endTime * 1000).format('DD/MM/YYYY h:mm:ss A');
}
@ -49,37 +71,37 @@ export class BallotProxyCard extends React.Component {
}
@action("Get times")
getTimes = async (_id) => {
await this.getStartTime(_id);
await this.getEndTime(_id);
getTimes = async () => {
await this.getStartTime();
await this.getEndTime();
this.calcTimeToFinish();
}
@action("Get proposed address of proxy ballot")
getProposedAddress = async (_id) => {
const { contractsStore } = this.props;
let proposedAddress = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.getProposedValue(_id).call()
getProposedAddress = async () => {
const { contractsStore, id } = this.props;
let proposedAddress = await contractsStore.votingToChangeProxy.getProposedValue(id);
this.proposedAddress = proposedAddress;
}
@action("Get contract type of proxy ballot")
getContractType = async (_id) => {
const { contractsStore } = this.props;
let contractType = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.getContractType(_id).call()
getContractType = async () => {
const { contractsStore, id } = this.props;
let contractType = await contractsStore.votingToChangeProxy.getContractType(id);
this.contractType = contractType;
}
@action("Get creator")
getCreator = async (_id) => {
const { contractsStore } = this.props;
let votingState = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.votingState(_id).call()
getCreator = async () => {
const { contractsStore, id } = this.props;
let votingState = await contractsStore.votingToChangeProxy.votingState(id);
this.getValidatorFullname(votingState.creator);
}
@action("Get validator full name")
getValidatorFullname = async (_miningKey) => {
const { contractsStore } = this.props;
let validator = await contractsStore.validatorMetadata.metadataInstance.methods.validators(_miningKey).call();
let validator = await contractsStore.validatorMetadata.validators(_miningKey);
let firstName = toAscii(validator.firstName);
let lastName = toAscii(validator.lastName);
let fullName = `${firstName} ${lastName}`
@ -87,37 +109,39 @@ export class BallotProxyCard extends React.Component {
}
@action("Get total voters")
getTotalVoters = async (_id) => {
const { contractsStore } = this.props;
this.totalVoters = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.getTotalVoters(_id).call();
getTotalVoters = async () => {
const { contractsStore, id } = this.props;
let totalVoters = await contractsStore.votingToChangeProxy.getTotalVoters(id);
this.totalVoters = Number(totalVoters);
}
@action("Get progress")
getProgress = async (_id) => {
const { contractsStore } = this.props;
this.progress = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.getProgress(_id).call();
getProgress = async () => {
const { contractsStore, id } = this.props;
let progress = await contractsStore.votingToChangeProxy.getProgress(id);
this.progress = Number(progress);
}
@action("Get isFinalized")
getIsFinalized = async (_id) => {
const { contractsStore } = this.props;
this.isFinalized = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.getIsFinalized(_id).call();
getIsFinalized = async () => {
const { contractsStore, id } = this.props;
this.isFinalized = await contractsStore.votingToChangeProxy.getIsFinalized(id);
}
isValidaVote = async () => {
const { contractsStore } = this.props;
let isValidVote = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.isValidVote(this.props.id, contractsStore.votingKey).call();
const { contractsStore, id } = this.props;
let isValidVote = await contractsStore.votingToChangeProxy.isValidVote(id, contractsStore.votingKey);
return isValidVote;
}
isActive = async () => {
const { contractsStore } = this.props;
let isActive = await contractsStore.votingToChangeProxy.votingToChangeProxyInstance.methods.isActive(this.props.id).call();
const { contractsStore, id } = this.props;
let isActive = await contractsStore.votingToChangeProxy.isActive(id);
return isActive;
}
vote = async (e, _type) => {
const { commonStore, contractsStore } = this.props;
const { commonStore, contractsStore, id } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", constants.INVALID_VOTING_KEY_MSG, "warning");
@ -130,7 +154,7 @@ export class BallotProxyCard extends React.Component {
swal("Warning!", constants.INVALID_VOTE_MSG, "warning");
return;
}
contractsStore.votingToChangeProxy.vote(this.props.id, _type, contractsStore.votingKey)
contractsStore.votingToChangeProxy.vote(id, _type, contractsStore.votingKey)
.on("receipt", () => {
commonStore.hideLoading();
swal("Congratulations!", constants.VOTED_SUCCESS_MSG, "success").then((result) => {
@ -144,7 +168,7 @@ export class BallotProxyCard extends React.Component {
}
finalize = async (e) => {
const { commonStore, contractsStore } = this.props;
const { commonStore, contractsStore, id } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", constants.INVALID_VOTING_KEY_MSG, "warning");
@ -161,7 +185,7 @@ export class BallotProxyCard extends React.Component {
swal("Warning!", constants.INVALID_FINALIZE_MSG, "warning");
return;
}
contractsStore.votingToChangeProxy.finalize(this.props.id, contractsStore.votingKey)
contractsStore.votingToChangeProxy.finalize(id, contractsStore.votingKey)
.on("receipt", () => {
commonStore.hideLoading();
swal("Congratulations!", constants.FINALIZED_SUCCESS_MSG, "success").then((result) => {
@ -176,17 +200,13 @@ export class BallotProxyCard extends React.Component {
constructor(props) {
super(props);
this.votesForNumber = 0;
this.votesAgainstNumber = 0;
this.votesForPercents = 0;
this.votesAgainstPercents = 0;
this.getTimes(this.props.id);
this.getProposedAddress(this.props.id);
this.getContractType(this.props.id);
this.getCreator(this.props.id);
this.getTotalVoters(this.props.id);
this.getProgress(this.props.id);
this.getIsFinalized(this.props.id);
this.getTimes();
this.getProposedAddress();
this.getContractType();
this.getCreator();
this.getTotalVoters();
this.getProgress();
this.getIsFinalized();
}
render () {

View File

@ -2,16 +2,11 @@ import React from 'react';
import { inject, observer } from "mobx-react";
import "babel-polyfill";
@inject("commonStore", "contractsStore", "ballotStore", "ballotsStore")
@inject("ballotsStore")
@observer
export class Ballots extends React.Component {
render () {
const { commonStore, ballotsStore } = this.props;
/*if (ballotsStore.ballotCards.length > 0) {
commonStore.hideLoading();
} else {
commonStore.showLoading();
}*/
const { ballotsStore } = this.props;
return (
<section className="container ballots">
<h1 className="title">Ballots</h1>

View File

@ -7,7 +7,7 @@ export const Footer = () => (
<p className="footer-rights">2017 POA Network. All rights reserved.</p>
<Link to="/poa-dapps-voting" className="footer-logo"></Link>
<div className="socials">
<a href="https://twitter.com/oraclesorg" className="socials-i socials-i_twitter"></a>
<a href="https://twitter.com/poanetwork" className="socials-i socials-i_twitter"></a>
<a href="https://poa.network" className="socials-i socials-i_oracles"></a>
<a href="https://t.me/oraclesnetwork" className="socials-i socials-i_telegram"></a>
<a href="https://github.com/poanetwork/" className="socials-i socials-i_github"></a>

View File

@ -7,6 +7,7 @@ import { KeysTypes } from './KeysTypes';
import { BallotKeysMetadata } from './BallotKeysMetadata';
import { BallotMinThresholdMetadata } from './BallotMinThresholdMetadata';
import { BallotProxyMetadata } from './BallotProxyMetadata';
import { constants } from "../constants";
@inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing")
@observer
@ -31,7 +32,7 @@ export class NewBallot extends React.Component {
}
if (!isAfter) {
swal("Warning!", "Ballot end time should be greater than now", "warning");
swal("Warning!", constants.END_TIME_SHOULD_BE_GREATER_THAN_NOW_MSG, "warning");
commonStore.hideLoading();
return false;
}
@ -48,7 +49,7 @@ export class NewBallot extends React.Component {
let isAffectedKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.affectedKey);
if (!isAffectedKeyAddress) {
swal("Warning!", `Ballot affectedKey isn't address`, "warning");
swal("Warning!", constants.AFFECTED_KEY_IS_NOT_ADDRESS_MSG, "warning");
commonStore.hideLoading();
return false;
}
@ -56,7 +57,7 @@ export class NewBallot extends React.Component {
let isMiningKeyAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotKeys.miningKey);
if (!isMiningKeyAddress) {
swal("Warning!", `Ballot miningKey isn't address`, "warning");
swal("Warning!", constants.MINING_KEY_IS_NOT_ADDRESS_MSG, "warning");
commonStore.hideLoading();
return false;
}
@ -84,7 +85,7 @@ export class NewBallot extends React.Component {
let isAddress = contractsStore.web3Instance.isAddress(ballotStore.ballotProxy.proposedAddress);
if (!isAddress) {
swal("Warning!", `Ballot proposedAddress isn't address`, "warning");
swal("Warning!", constants.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG, "warning");
commonStore.hideLoading();
return false;
}
@ -148,7 +149,7 @@ export class NewBallot extends React.Component {
const isValidVotingKey = contractsStore.isValidVotingKey;
if (!isValidVotingKey) {
commonStore.hideLoading();
swal("Warning!", "The key is not valid voting Key! Please make sure you have loaded correct voting key in metamask", "warning");
swal("Warning!", constants.INVALID_VOTING_KEY_MSG, "warning");
return;
}
const isFormValid = this.checkValidation();
@ -172,7 +173,7 @@ export class NewBallot extends React.Component {
methodToCreateBallot(curDateInSeconds)
.on("receipt", () => {
commonStore.hideLoading();
swal("Congratulations!", "You successfully created a new ballot", "success").then((result) => {
swal("Congratulations!", constants.BALLOT_CREATED_SUCCESS_MSG, "success").then((result) => {
push(`${commonStore.rootPath}`);
});
})

View File

@ -1,10 +1,15 @@
let constants = {};
constants.INVALID_VOTING_KEY_MSG = "The key is not valid voting Key! Please make sure you have loaded correct voting key in metamask";
constants.VOTED_SUCCESS_MSG = "You successfully voted";
constants.BALLOT_CREATED_SUCCESS_MSG = "You successfully created a new ballot";
constants.FINALIZED_SUCCESS_MSG = "You successfully finalized";
constants.ALREADY_FINALIZED_MSG = "This ballot is already finalized";
constants.INVALID_VOTE_MSG = "You can't vote on this ballot";
constants.INVALID_FINALIZE_MSG = "You can't finalize this ballot";
constants.AFFECTED_KEY_IS_NOT_ADDRESS_MSG = `Ballot affectedKey isn't address`;
constants.MINING_KEY_IS_NOT_ADDRESS_MSG = `Ballot miningKey isn't address`;
constants.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG = `Ballot proposedAddress isn't address`;
constants.END_TIME_SHOULD_BE_GREATER_THAN_NOW_MSG = "Ballot end time should be greater than now";
module.exports = {
constants
}

View File

@ -53,5 +53,9 @@ export default class Metadata {
async getMinThreshold({miningKey}) {
let validatorData = await this.metadataInstance.methods.validators(miningKey).call();
return validatorData.minThreshold;
}
}
validators(_miningKey) {
return this.metadataInstance.methods.validators(_miningKey).call();
}
}

View File

@ -11,15 +11,61 @@ export default class VotingToChangeKeys {
}
}
//setters
createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, sender) {
return this.votingToChangeKeysInstance.methods.createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType).send({from: sender})
return this.votingToChangeKeysInstance.methods.createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType).send({from: sender});
}
vote(id, choice, sender) {
return this.votingToChangeKeysInstance.methods.vote(id, choice).send({from: sender})
vote(_id, choice, sender) {
return this.votingToChangeKeysInstance.methods.vote(_id, choice).send({from: sender});
}
finalize(id, sender) {
return this.votingToChangeKeysInstance.methods.finalize(id).send({from: sender})
finalize(_id, sender) {
return this.votingToChangeKeysInstance.methods.finalize(_id).send({from: sender});
}
//getters
getStartTime(_id) {
return this.votingToChangeKeysInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeKeysInstance.methods.getEndTime(_id).call();
}
votingState(_id) {
return this.votingToChangeKeysInstance.methods.votingState(_id).call();
}
getTotalVoters(_id) {
return this.votingToChangeKeysInstance.methods.getTotalVoters(_id).call();
}
getProgress(_id) {
return this.votingToChangeKeysInstance.methods.getProgress(_id).call();
}
getIsFinalized(_id) {
return this.votingToChangeKeysInstance.methods.getIsFinalized(_id).call();
}
isValidVote(_id, votingKey) {
return this.votingToChangeKeysInstance.methods.isValidVote(_id, votingKey).call();
}
isActive(_id) {
return this.votingToChangeKeysInstance.methods.isActive(_id).call();
}
getBallotType(_id) {
return this.votingToChangeKeysInstance.methods.getBallotType(_id).call();
}
getAffectedKeyType(_id) {
return this.votingToChangeKeysInstance.methods.getAffectedKeyType(_id).call();
}
getAffectedKey(_id) {
return this.votingToChangeKeysInstance.methods.getAffectedKey(_id).call();
}
}

View File

@ -11,15 +11,53 @@ export default class VotingToChangeMinThreshold {
}
}
//setters
createBallotToChangeThreshold(startTime, endTime, proposedValue, sender) {
return this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold(startTime, endTime, proposedValue).send({from: sender})
}
vote(id, choice, sender) {
return this.votingToChangeMinThresholdInstance.methods.vote(id, choice).send({from: sender})
vote(_id, choice, sender) {
return this.votingToChangeMinThresholdInstance.methods.vote(_id, choice).send({from: sender})
}
finalize(id, sender) {
return this.votingToChangeMinThresholdInstance.methods.finalize(id).send({from: sender})
finalize(_id, sender) {
return this.votingToChangeMinThresholdInstance.methods.finalize(_id).send({from: sender})
}
//getters
getStartTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
}
votingState(_id) {
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
}
getTotalVoters(_id) {
return this.votingToChangeMinThresholdInstance.methods.getTotalVoters(_id).call();
}
getProgress(_id) {
return this.votingToChangeMinThresholdInstance.methods.getProgress(_id).call();
}
getIsFinalized(_id) {
return this.votingToChangeMinThresholdInstance.methods.getIsFinalized(_id).call();
}
isValidVote(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.isValidVote(_id, votingKey).call();
}
isActive(_id) {
return this.votingToChangeMinThresholdInstance.methods.isActive(_id).call();
}
getProposedValue(_id) {
return this.votingToChangeMinThresholdInstance.methods.getProposedValue(_id).call();
}
}

View File

@ -11,15 +11,57 @@ export default class VotingToChangeProxy {
}
}
//setters
createBallotToChangeProxyAddress(startTime, endTime, proposedValue, contractType, sender) {
return this.votingToChangeProxyInstance.methods.createBallotToChangeProxyAddress(startTime, endTime, proposedValue, contractType).send({from: sender})
}
vote(id, choice, sender) {
return this.votingToChangeProxyInstance.methods.vote(id, choice).send({from: sender})
vote(_id, choice, sender) {
return this.votingToChangeProxyInstance.methods.vote(_id, choice).send({from: sender})
}
finalize(id, sender) {
return this.votingToChangeProxyInstance.methods.finalize(id).send({from: sender})
finalize(_id, sender) {
return this.votingToChangeProxyInstance.methods.finalize(_id).send({from: sender})
}
}
//getters
getStartTime(_id) {
return this.votingToChangeProxyInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeProxyInstance.methods.getEndTime(_id).call();
}
votingState(_id) {
return this.votingToChangeProxyInstance.methods.votingState(_id).call();
}
getTotalVoters(_id) {
return this.votingToChangeProxyInstance.methods.getTotalVoters(_id).call();
}
getProgress(_id) {
return this.votingToChangeProxyInstance.methods.getProgress(_id).call();
}
getIsFinalized(_id) {
return this.votingToChangeProxyInstance.methods.getIsFinalized(_id).call();
}
isValidVote(_id, votingKey) {
return this.votingToChangeProxyInstance.methods.isValidVote(_id, votingKey).call();
}
isActive(_id) {
return this.votingToChangeProxyInstance.methods.isActive(_id).call();
}
getProposedValue(_id) {
return this.votingToChangeProxyInstance.methods.getProposedValue(_id).call();
}
getContractType(_id) {
return this.votingToChangeProxyInstance.methods.getContractType(_id).call();
}
}