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