From 55d8c5632c5f449fa0c619a1ff2d6492b26a29da Mon Sep 17 00:00:00 2001 From: Roman Storm Date: Fri, 19 Jan 2018 19:03:26 -0800 Subject: [PATCH] (Fix) Add front end validation --- src/components/NewBallot.jsx | 13 +++++++++++++ src/messages.js | 2 ++ src/stores/ContractsStore.js | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/src/components/NewBallot.jsx b/src/components/NewBallot.jsx index 345f4ae..45ff830 100644 --- a/src/components/NewBallot.jsx +++ b/src/components/NewBallot.jsx @@ -20,6 +20,7 @@ export class NewBallot extends React.Component { checkValidation() { const { commonStore, contractsStore, ballotStore, validatorStore } = this.props; const isAfter = moment(ballotStore.endTime).isAfter(moment()); + const isTwoDaysMinimum = moment(ballotStore.endTime).isAfter(moment().add(2, 'days')); if (ballotStore.isNewValidatorPersonalData) { for (let validatorProp in validatorStore) { @@ -37,6 +38,18 @@ export class NewBallot extends React.Component { return false; } + if(!ballotStore.memo){ + swal("Warning!", messages.DESCRIPTION_IS_EMPTY, "warning"); + commonStore.hideLoading(); + return false; + } + + if(!isTwoDaysMinimum) { + swal("Warning!", messages.SHOULD_BE_MORE_THAN_TWO_DAYS, "warning"); + commonStore.hideLoading(); + return false; + } + if (ballotStore.isBallotForKey) { for (let ballotKeysProp in ballotStore.ballotKeys) { if (ballotStore.ballotKeys[ballotKeysProp].length === 0) { diff --git a/src/messages.js b/src/messages.js index 42297b7..c28b4c9 100644 --- a/src/messages.js +++ b/src/messages.js @@ -21,6 +21,8 @@ Check POA Network wi messages.ballotIsNotActiveMsg = function(timeToStart) { return `The ballot is not active yet. Time to start: ${timeToStart}`; }; +messages.SHOULD_BE_MORE_THAN_TWO_DAYS = "Ballot end time should be at least 48 hours from now"; +messages.DESCRIPTION_IS_EMPTY = "Description cannot be empty"; module.exports = { messages }; \ No newline at end of file diff --git a/src/stores/ContractsStore.js b/src/stores/ContractsStore.js index 6e85bc4..267662e 100644 --- a/src/stores/ContractsStore.js +++ b/src/stores/ContractsStore.js @@ -193,11 +193,17 @@ class ContractsStore { @action async getAllValidatorMetadata() { + const newMiningKey = { + label: "New Mining Key", + value: "0x0000000000000000000000000000000000000000" + } + this.validatorsMetadata.push(newMiningKey); const keys = await this.poaConsensus.getValidators(); keys.forEach(async (key) => { const metadata = await this.validatorMetadata.getValidatorData({miningKey: key}) this.validatorsMetadata.push({label: `${key} ${metadata.lastName}`, value: key}) }) + } }