From 336fb891bf5b42ab4237cc2dd901f1320418cae6 Mon Sep 17 00:00:00 2001 From: Vadim Arasev Date: Thu, 21 Jun 2018 19:17:46 +0300 Subject: [PATCH] (Refactor) Collapse core and demo branches --- src/components/NewBallot.jsx | 32 ++++++++++++++++++-------------- src/constants.js | 3 +++ src/messages.js | 4 ++-- src/stores/BallotStore.js | 5 ++--- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/components/NewBallot.jsx b/src/components/NewBallot.jsx index 7e24460..0e10e7f 100644 --- a/src/components/NewBallot.jsx +++ b/src/components/NewBallot.jsx @@ -8,6 +8,7 @@ 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") @observer export class NewBallot extends React.Component { @@ -18,10 +19,6 @@ export class NewBallot extends React.Component { checkValidation() { 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) { for (let validatorProp in validatorStore) { @@ -39,9 +36,15 @@ export class NewBallot extends React.Component { 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; - 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(); return false; } @@ -124,10 +127,10 @@ export class NewBallot extends React.Component { return true; } - createBallotForKeys = (curDateInSeconds) => { + createBallotForKeys = (startTime) => { const { ballotStore, contractsStore } = this.props; const inputToMethod = { - startTime: curDateInSeconds, + startTime: startTime, endTime: ballotStore.endTimeUnix, affectedKey: ballotStore.ballotKeys.affectedKey, affectedKeyType: ballotStore.ballotKeys.keyType, @@ -151,10 +154,10 @@ export class NewBallot extends React.Component { return method; } - createBallotForMinThreshold = (curDateInSeconds) => { + createBallotForMinThreshold = (startTime) => { const { ballotStore, contractsStore } = this.props; const inputToMethod = { - startTime: curDateInSeconds, + startTime: startTime, endTime: ballotStore.endTimeUnix, proposedValue: ballotStore.ballotMinThreshold.proposedValue, sender: contractsStore.votingKey, @@ -164,10 +167,10 @@ export class NewBallot extends React.Component { return method; } - createBallotForProxy = (curDateInSeconds) => { + createBallotForProxy = (startTime) => { const { ballotStore, contractsStore } = this.props; const inputToMethod = { - startTime: curDateInSeconds, + startTime: startTime, endTime: ballotStore.endTimeUnix, proposedValue: ballotStore.ballotProxy.proposedAddress, contractType: ballotStore.ballotProxy.contractType, @@ -218,8 +221,9 @@ export class NewBallot extends React.Component { default: 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) => { commonStore.hideLoading(); if(tx.status === '0x1'){ diff --git a/src/constants.js b/src/constants.js index 69c8db7..03fc83f 100644 --- a/src/constants.js +++ b/src/constants.js @@ -18,6 +18,9 @@ constants.NEW_MINING_KEY = { fullName: "", value: "0x0000000000000000000000000000000000000000" }; +constants.minBallotDurationInDays = 2; +constants.startTimeOffsetInMinutes = 5; +constants.endTimeDefaultInMinutes = 2890; module.exports = { constants } \ No newline at end of file diff --git a/src/messages.js b/src/messages.js index 412c06e..b3c22f3 100644 --- a/src/messages.js +++ b/src/messages.js @@ -22,8 +22,8 @@ Check POA Network wi messages.ballotIsNotActiveMsg = (timeToStart) => { return `The ballot is not active yet. Time to start: ${timeToStart}`; }; -messages.SHOULD_BE_MORE_THAN_TWO_DAYS = (duration, neededHours, neededMinutes) => { - return `Ballot end time should be at least 48 hours from now in UTC time. Current duration is ${duration} hours. +messages.SHOULD_BE_MORE_THAN_MIN_DURATION = (minDuration, duration, neededHours, neededMinutes) => { + 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 `; } diff --git a/src/stores/BallotStore.js b/src/stores/BallotStore.js index b33b27a..af2f047 100644 --- a/src/stores/BallotStore.js +++ b/src/stores/BallotStore.js @@ -1,5 +1,6 @@ import { observable, computed, action, toJS } from 'mobx'; import moment from 'moment'; +import { constants } from "../constants"; class BallotStore { BallotType = { @@ -37,14 +38,12 @@ class BallotStore { constructor() { - const twoDays = moment().add(2, 'days').add(10, 'minutes').format("YYYY-MM-DDTHH:mm"); this.ballotType = null; - this.endTime = twoDays; + this.endTime = moment().add(constants.endTimeDefaultInMinutes, 'minutes').format("YYYY-MM-DDTHH:mm"); this.ballotKeys = { keyType: null, keysBallotType: null, - //memo: "", affectedKey: "", newVotingKey: "", newPayoutKey: "",