Merge pull request #201 from varasev/finalize-note-fix
(Fix) a bug in displaying a text note near the Finalize button
This commit is contained in:
commit
27655e420f
|
@ -23,7 +23,9 @@ const zeroTimeTo = '00:00'
|
|||
@observer
|
||||
export class BallotCard extends React.Component {
|
||||
@observable cancelDeadline = 0
|
||||
@observable nowTimeUnix
|
||||
@observable startTime
|
||||
@observable startTimeUnix
|
||||
@observable endTime
|
||||
@observable timeTo = {}
|
||||
@observable
|
||||
|
@ -56,6 +58,7 @@ export class BallotCard extends React.Component {
|
|||
@observable hasAlreadyVoted
|
||||
@observable memo
|
||||
@observable quorumState
|
||||
@observable minBallotDuration
|
||||
|
||||
@computed
|
||||
get cancelOrFinalizeButtonDisplayName() {
|
||||
|
@ -101,7 +104,7 @@ export class BallotCard extends React.Component {
|
|||
return `You can cancel this ballot within ${this.timeToCancel.displayValue}`
|
||||
} else {
|
||||
let description = 'Finalization is available after ballot time is finished'
|
||||
if (this.canBeFinalized !== null) {
|
||||
if (this.canBeFinalized !== null && this.nowTimeUnix - this.startTimeUnix > this.minBallotDuration) {
|
||||
description += ' or all validators are voted'
|
||||
}
|
||||
return description
|
||||
|
@ -208,6 +211,10 @@ export class BallotCard extends React.Component {
|
|||
const msStart = start.diff(_now)
|
||||
const msFinish = finish.diff(_now)
|
||||
|
||||
this.nowTimeUnix = moment()
|
||||
.utc()
|
||||
.unix()
|
||||
|
||||
if (msCancel > 0 && !this.isCanceled) {
|
||||
this.timeToCancel.val = msCancel
|
||||
this.timeToCancel.displayValue = this.formatMs(msCancel, ':mm:ss')
|
||||
|
@ -248,6 +255,7 @@ export class BallotCard extends React.Component {
|
|||
.utc((votingState.creationTime + contractsStore.ballotCancelingThreshold) * 1000)
|
||||
.format(USDateTimeFormat)
|
||||
}
|
||||
this.startTimeUnix = moment.utc(votingState.startTime * 1000) / 1000
|
||||
this.startTime = moment.utc(votingState.startTime * 1000).format(USDateTimeFormat)
|
||||
this.endTime = moment.utc(votingState.endTime * 1000).format(USDateTimeFormat)
|
||||
// getCreator
|
||||
|
@ -297,6 +305,8 @@ export class BallotCard extends React.Component {
|
|||
if (votingType === 'votingToManageEmissionFunds') {
|
||||
this.getQuorumState()
|
||||
}
|
||||
|
||||
this.minBallotDuration = this.getMinBallotDuration(contractsStore, votingType)
|
||||
}
|
||||
|
||||
formatMs(ms, format) {
|
||||
|
@ -605,6 +615,19 @@ export class BallotCard extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
getMinBallotDuration(contractsStore, votingType) {
|
||||
switch (votingType) {
|
||||
case 'votingToChangeKeys':
|
||||
return contractsStore.minBallotDuration.keys
|
||||
case 'votingToChangeMinThreshold':
|
||||
return contractsStore.minBallotDuration.minThreshold
|
||||
case 'votingToChangeProxy':
|
||||
return contractsStore.minBallotDuration.proxy
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.interval = setInterval(() => {
|
||||
this.calcTimeTo()
|
||||
|
|
|
@ -85,4 +85,8 @@ export default class VotingToChangeKeys {
|
|||
const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
|
||||
return _limitPerValidator - _activeBallots
|
||||
}
|
||||
|
||||
async minBallotDuration() {
|
||||
return await this.instance.methods.minBallotDuration().call()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,4 +77,8 @@ export default class VotingToChangeMinThreshold {
|
|||
const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
|
||||
return _limitPerValidator - _activeBallots
|
||||
}
|
||||
|
||||
async minBallotDuration() {
|
||||
return await this.instance.methods.minBallotDuration().call()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,4 +73,8 @@ export default class VotingToChangeProxy {
|
|||
const _activeBallots = await this.instance.methods.validatorActiveBallots(_miningKey).call()
|
||||
return _limitPerValidator - _activeBallots
|
||||
}
|
||||
|
||||
async minBallotDuration() {
|
||||
return await this.instance.methods.minBallotDuration().call()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ class AppMainRouter extends Component {
|
|||
contractsStore.getKeysBallotThreshold()
|
||||
contractsStore.getProxyBallotThreshold()
|
||||
contractsStore.getBallotCancelingThreshold()
|
||||
contractsStore.getBallotsLimits()
|
||||
|
||||
await contractsStore.getBallotsLimits()
|
||||
|
||||
await contractsStore.getAllValidatorMetadata()
|
||||
await contractsStore.getAllBallots()
|
||||
|
|
|
@ -43,6 +43,7 @@ class ContractsStore {
|
|||
@observable emissionFundsBallotThreshold
|
||||
@observable ballotCancelingThreshold
|
||||
@observable validatorLimits
|
||||
@observable minBallotDuration
|
||||
@observable validatorsMetadata
|
||||
@observable netId
|
||||
|
||||
|
@ -51,6 +52,7 @@ class ContractsStore {
|
|||
this.miningKey = null
|
||||
this.validatorsMetadata = {}
|
||||
this.validatorLimits = { keys: null, minThreshold: null, proxy: null }
|
||||
this.minBallotDuration = { keys: 0, minThreshold: 0, proxy: 0 }
|
||||
}
|
||||
|
||||
@computed
|
||||
|
@ -388,21 +390,50 @@ class ContractsStore {
|
|||
|
||||
@action
|
||||
async getBallotsLimits() {
|
||||
if (this.web3Instance && this.netId) {
|
||||
const limitPerValidator = await this.ballotsStorage.instance.methods.getBallotLimitPerValidator().call()
|
||||
return new Promise(async resolve => {
|
||||
if (this.web3Instance && this.netId) {
|
||||
const limitPerValidator = await this.ballotsStorage.instance.methods.getBallotLimitPerValidator().call()
|
||||
|
||||
let getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.miningKey, limitPerValidator)
|
||||
let getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(this.miningKey, limitPerValidator)
|
||||
let getProxyLimit = await this.votingToChangeProxy.getBallotLimit(this.miningKey, limitPerValidator)
|
||||
const getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.miningKey, limitPerValidator)
|
||||
const getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(
|
||||
this.miningKey,
|
||||
limitPerValidator
|
||||
)
|
||||
const getProxyLimit = await this.votingToChangeProxy.getBallotLimit(this.miningKey, limitPerValidator)
|
||||
|
||||
await Promise.all([getKeysLimit, getMinThresholdLimit, getProxyLimit]).then(
|
||||
([keysLimit, minThresholdLimit, proxyLimit]) => {
|
||||
this.validatorLimits.keys = keysLimit
|
||||
this.validatorLimits.minThreshold = minThresholdLimit
|
||||
this.validatorLimits.proxy = proxyLimit
|
||||
}
|
||||
)
|
||||
}
|
||||
const getKeysMinBallotDuration = await this.votingToChangeKeys.minBallotDuration()
|
||||
const getMinThresholdMinBallotDuration = await this.votingToChangeMinThreshold.minBallotDuration()
|
||||
const getProxyMinBallotDuration = await this.votingToChangeProxy.minBallotDuration()
|
||||
|
||||
await Promise.all([
|
||||
getKeysLimit,
|
||||
getMinThresholdLimit,
|
||||
getProxyLimit,
|
||||
getKeysMinBallotDuration,
|
||||
getMinThresholdMinBallotDuration,
|
||||
getProxyMinBallotDuration
|
||||
]).then(
|
||||
([
|
||||
keysLimit,
|
||||
minThresholdLimit,
|
||||
proxyLimit,
|
||||
keysMinBallotDuration,
|
||||
minThresholdMinBallotDuration,
|
||||
proxyMinBallotDuration
|
||||
]) => {
|
||||
this.validatorLimits.keys = keysLimit
|
||||
this.validatorLimits.minThreshold = minThresholdLimit
|
||||
this.validatorLimits.proxy = proxyLimit
|
||||
this.minBallotDuration.keys = keysMinBallotDuration
|
||||
this.minBallotDuration.minThreshold = minThresholdMinBallotDuration
|
||||
this.minBallotDuration.proxy = proxyMinBallotDuration
|
||||
resolve()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
Loading…
Reference in New Issue