(Refactor) Collapse core and demo branches

This commit is contained in:
Vadim Arasev 2018-06-21 19:17:46 +03:00
parent 744026532d
commit 336fb891bf
4 changed files with 25 additions and 19 deletions

View File

@ -8,6 +8,7 @@ import { BallotKeysMetadata } from './BallotKeysMetadata';
import { BallotMinThresholdMetadata } from './BallotMinThresholdMetadata'; import { BallotMinThresholdMetadata } from './BallotMinThresholdMetadata';
import { BallotProxyMetadata } from './BallotProxyMetadata'; import { BallotProxyMetadata } from './BallotProxyMetadata';
import { messages } from "../messages"; import { messages } from "../messages";
import { constants } from "../constants";
@inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing") @inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing")
@observer @observer
export class NewBallot extends React.Component { export class NewBallot extends React.Component {
@ -18,10 +19,6 @@ export class NewBallot extends React.Component {
checkValidation() { checkValidation() {
const { commonStore, contractsStore, ballotStore, validatorStore } = this.props; const { commonStore, contractsStore, ballotStore, validatorStore } = this.props;
const twoDays = moment.utc().add(2, 'days').format();
let neededMinutes = moment(twoDays).diff(moment(ballotStore.endTime), 'minutes');
let neededHours = Math.round(neededMinutes / 60);
let duration = 48 - neededHours;
if (ballotStore.isNewValidatorPersonalData) { if (ballotStore.isNewValidatorPersonalData) {
for (let validatorProp in validatorStore) { for (let validatorProp in validatorStore) {
@ -39,9 +36,15 @@ export class NewBallot extends React.Component {
return false; return false;
} }
if(neededMinutes > 0) { 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; neededMinutes = neededHours * 60 - neededMinutes;
swal("Warning!", messages.SHOULD_BE_MORE_THAN_TWO_DAYS(duration, neededHours, neededMinutes), "warning"); swal("Warning!", messages.SHOULD_BE_MORE_THAN_MIN_DURATION(minBallotDurationInHours, duration, neededHours, neededMinutes), "warning");
commonStore.hideLoading(); commonStore.hideLoading();
return false; return false;
} }
@ -124,10 +127,10 @@ export class NewBallot extends React.Component {
return true; return true;
} }
createBallotForKeys = (curDateInSeconds) => { createBallotForKeys = (startTime) => {
const { ballotStore, contractsStore } = this.props; const { ballotStore, contractsStore } = this.props;
const inputToMethod = { const inputToMethod = {
startTime: curDateInSeconds, startTime: startTime,
endTime: ballotStore.endTimeUnix, endTime: ballotStore.endTimeUnix,
affectedKey: ballotStore.ballotKeys.affectedKey, affectedKey: ballotStore.ballotKeys.affectedKey,
affectedKeyType: ballotStore.ballotKeys.keyType, affectedKeyType: ballotStore.ballotKeys.keyType,
@ -151,10 +154,10 @@ export class NewBallot extends React.Component {
return method; return method;
} }
createBallotForMinThreshold = (curDateInSeconds) => { createBallotForMinThreshold = (startTime) => {
const { ballotStore, contractsStore } = this.props; const { ballotStore, contractsStore } = this.props;
const inputToMethod = { const inputToMethod = {
startTime: curDateInSeconds, startTime: startTime,
endTime: ballotStore.endTimeUnix, endTime: ballotStore.endTimeUnix,
proposedValue: ballotStore.ballotMinThreshold.proposedValue, proposedValue: ballotStore.ballotMinThreshold.proposedValue,
sender: contractsStore.votingKey, sender: contractsStore.votingKey,
@ -164,10 +167,10 @@ export class NewBallot extends React.Component {
return method; return method;
} }
createBallotForProxy = (curDateInSeconds) => { createBallotForProxy = (startTime) => {
const { ballotStore, contractsStore } = this.props; const { ballotStore, contractsStore } = this.props;
const inputToMethod = { const inputToMethod = {
startTime: curDateInSeconds, startTime: startTime,
endTime: ballotStore.endTimeUnix, endTime: ballotStore.endTimeUnix,
proposedValue: ballotStore.ballotProxy.proposedAddress, proposedValue: ballotStore.ballotProxy.proposedAddress,
contractType: ballotStore.ballotProxy.contractType, contractType: ballotStore.ballotProxy.contractType,
@ -218,8 +221,9 @@ export class NewBallot extends React.Component {
default: default:
break; break;
} }
let curDateInSeconds = moment.utc().add(5, 'minutes').unix();
methodToCreateBallot(curDateInSeconds) const startTime = moment.utc().add(constants.startTimeOffsetInMinutes, 'minutes').unix();
methodToCreateBallot(startTime)
.on("receipt", (tx) => { .on("receipt", (tx) => {
commonStore.hideLoading(); commonStore.hideLoading();
if(tx.status === '0x1'){ if(tx.status === '0x1'){

View File

@ -18,6 +18,9 @@ constants.NEW_MINING_KEY = {
fullName: "", fullName: "",
value: "0x0000000000000000000000000000000000000000" value: "0x0000000000000000000000000000000000000000"
}; };
constants.minBallotDurationInDays = 2;
constants.startTimeOffsetInMinutes = 5;
constants.endTimeDefaultInMinutes = 2890;
module.exports = { module.exports = {
constants constants
} }

View File

@ -22,8 +22,8 @@ Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>wi
messages.ballotIsNotActiveMsg = (timeToStart) => { messages.ballotIsNotActiveMsg = (timeToStart) => {
return `The ballot is not active yet. Time to start: ${timeToStart}`; return `The ballot is not active yet. Time to start: ${timeToStart}`;
}; };
messages.SHOULD_BE_MORE_THAN_TWO_DAYS = (duration, neededHours, neededMinutes) => { messages.SHOULD_BE_MORE_THAN_MIN_DURATION = (minDuration, duration, neededHours, neededMinutes) => {
return `Ballot end time should be at least 48 hours from now in UTC time. Current duration is ${duration} hours. return `Ballot end time should be at least ${minDuration} hours from now in UTC time. Current duration is ${duration} hours.
Please add ${neededHours} hours and ${neededMinutes} minutes in order to set correct end time Please add ${neededHours} hours and ${neededMinutes} minutes in order to set correct end time
`; `;
} }

View File

@ -1,5 +1,6 @@
import { observable, computed, action, toJS } from 'mobx'; import { observable, computed, action, toJS } from 'mobx';
import moment from 'moment'; import moment from 'moment';
import { constants } from "../constants";
class BallotStore { class BallotStore {
BallotType = { BallotType = {
@ -37,14 +38,12 @@ class BallotStore {
constructor() { constructor() {
const twoDays = moment().add(2, 'days').add(10, 'minutes').format("YYYY-MM-DDTHH:mm");
this.ballotType = null; this.ballotType = null;
this.endTime = twoDays; this.endTime = moment().add(constants.endTimeDefaultInMinutes, 'minutes').format("YYYY-MM-DDTHH:mm");
this.ballotKeys = { this.ballotKeys = {
keyType: null, keyType: null,
keysBallotType: null, keysBallotType: null,
//memo: "",
affectedKey: "", affectedKey: "",
newVotingKey: "", newVotingKey: "",
newPayoutKey: "", newPayoutKey: "",