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