(Fix) ballot duration in alert

This commit is contained in:
Vadim Arasev 2018-07-18 15:07:09 +03:00
parent 524033a1fb
commit 2d2189590f
1 changed files with 18 additions and 9 deletions

View File

@ -19,6 +19,13 @@ export class NewBallot extends React.Component {
this.onClick = this.onClick.bind(this)
}
getStartTimeUnix() {
return moment
.utc()
.add(constants.startTimeOffsetInMinutes, 'minutes')
.unix()
}
checkValidation() {
const { commonStore, contractsStore, ballotStore, validatorStore } = this.props
@ -39,16 +46,21 @@ export class NewBallot extends React.Component {
}
const minBallotDurationInHours = constants.minBallotDurationInDays * 24
const startTime = this.getStartTimeUnix()
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
let neededHours = Math.floor(neededMinutes / 60)
let duration = moment.unix(ballotStore.endTimeUnix).diff(moment.unix(startTime), 'hours')
if (duration < 0) {
duration = 0
}
if (neededMinutes > 0) {
neededMinutes = neededHours * 60 - neededMinutes
neededMinutes = Math.abs(neededHours * 60 - neededMinutes)
swal(
'Warning!',
messages.SHOULD_BE_MORE_THAN_MIN_DURATION(minBallotDurationInHours, duration, neededHours, neededMinutes),
@ -240,10 +252,7 @@ export class NewBallot extends React.Component {
break
}
const startTime = moment
.utc()
.add(constants.startTimeOffsetInMinutes, 'minutes')
.unix()
const startTime = this.getStartTimeUnix()
web3.eth.sendTransaction(
{
@ -338,7 +347,7 @@ export class NewBallot extends React.Component {
className={this.menuItemActive(ballotStore.BallotType.minThreshold)}
onClick={e => ballotStore.changeBallotType(e, ballotStore.BallotType.minThreshold)}
>
Consenus Threshold Ballot
Consensus Threshold Ballot
</div>
<div
className={this.menuItemActive(ballotStore.BallotType.proxy)}
@ -399,7 +408,7 @@ export class NewBallot extends React.Component {
onChange={e => ballotStore.changeBallotType(e, ballotStore.BallotType.minThreshold)}
/>
<label htmlFor="ballot-for-consensus" className="radio">
Consenus Threshold Ballot
Consensus Threshold Ballot
</label>
<p className="hint">Ballot to change the minimum threshold for consensus to vote for keys.</p>
</div>