(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 { 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'){

View File

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

View File

@ -22,8 +22,8 @@ Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>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
`;
}

View File

@ -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: "",