From 9f72ef8a00af19d5f05ade153dd5f85853aaed43 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 21 Mar 2018 20:15:40 +0300 Subject: [PATCH] 14 days upper limit for ballot's duration (#109) --- src/components/NewBallot.jsx | 14 +++++++++++--- src/messages.js | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/NewBallot.jsx b/src/components/NewBallot.jsx index 59c2473..de97888 100644 --- a/src/components/NewBallot.jsx +++ b/src/components/NewBallot.jsx @@ -20,7 +20,7 @@ export class NewBallot extends React.Component { 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 neededHours = Math.round(neededMinutes / 60); let duration = 48 - neededHours; if (ballotStore.isNewValidatorPersonalData) { @@ -33,19 +33,27 @@ export class NewBallot extends React.Component { } } - if(!ballotStore.memo){ + if(!ballotStore.memo) { swal("Warning!", messages.DESCRIPTION_IS_EMPTY, "warning"); commonStore.hideLoading(); return false; } if(neededMinutes > 0) { - neededMinutes = neededHours*60 - neededMinutes; + neededMinutes = neededHours * 60 - neededMinutes; swal("Warning!", messages.SHOULD_BE_MORE_THAN_TWO_DAYS(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'); + if (exceededMinutes > 0) { + 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 (!ballotStore.ballotKeys[ballotKeysProp]) { diff --git a/src/messages.js b/src/messages.js index 08513c6..156feb6 100644 --- a/src/messages.js +++ b/src/messages.js @@ -27,6 +27,9 @@ messages.SHOULD_BE_MORE_THAN_TWO_DAYS = (duration, neededHours, neededMinutes) = Please add ${neededHours} hours and ${neededMinutes} minutes in order to set correct end time `; } +messages.SHOULD_BE_LESS_OR_EQUAL_14_DAYS = (duration) => { + return `Ballot end time should not be more than 14 days from now in UTC time. Current duration is ${duration} hours.`; +} messages.FAILED_TX = `Your transaction was failed. Please make sure you set correct parameters for ballot creation. Make sure you don't have Transaction Error. Exception thrown in contract code message in metamask before you sign it.` messages.DESCRIPTION_IS_EMPTY = "Description cannot be empty";