From e1dbd90c76f80df9b1c92c5a9228b7c69a3f7dbf Mon Sep 17 00:00:00 2001 From: Vadim Arasev Date: Thu, 14 Jun 2018 11:05:35 +0300 Subject: [PATCH] (Fix) Light optimization --- src/components/BallotCard.jsx | 43 ++++++++++++++++++--- src/components/BallotKeysCard.jsx | 62 ++++++++++++++++++++++++------- 2 files changed, 86 insertions(+), 19 deletions(-) diff --git a/src/components/BallotCard.jsx b/src/components/BallotCard.jsx index bfff5f3..1bd09f2 100644 --- a/src/components/BallotCard.jsx +++ b/src/components/BallotCard.jsx @@ -164,6 +164,42 @@ export class BallotCard extends React.Component { } } + @action("Get votingState") + getVotingState = async () => { + const { contractsStore, id, votingType } = this.props; + const votingState = await this.repeatGetProperty(contractsStore, votingType, id, "votingState", 0); + if (votingState) { + // getTimes + this.startTime = moment.utc(votingState.startTime * 1000).format(USDateTimeFormat); + this.endTime = moment.utc(votingState.endTime * 1000).format(USDateTimeFormat); + this.calcTimeTo(); + // getCreator + this.getValidatorFullname(votingState.creator); + // getTotalVoters + if (votingState.totalVoters) { + this.totalVoters = Number(votingState.totalVoters); + } + // getProgress + if (votingState.progress) { + this.progress = Number(votingState.progress); + } + // getIsFinalized + this.isFinalized = votingState.isFinalized; + // getMemo + this.memo = votingState.memo; + } else { + this.getTimes(); + const creator = await this.repeatGetProperty(contractsStore, votingType, id, "getCreator", 0); + if (creator) { + this.getValidatorFullname(creator); + } + this.getTotalVoters(); + this.getProgress(); + this.getIsFinalized(); + this.getMemo(); + } + } + @action("Get progress") getProgress = async () => { const { contractsStore, id, votingType } = this.props; @@ -371,13 +407,8 @@ export class BallotCard extends React.Component { super(props); this.isFinalized = false; this.hasAlreadyVoted = false; - this.getTimes(); - this.getCreator(); - this.getTotalVoters(); - this.getProgress(); + this.getVotingState(); this.getHasAlreadyVoted(); - this.getIsFinalized(); - this.getMemo(); } componentDidMount() { diff --git a/src/components/BallotKeysCard.jsx b/src/components/BallotKeysCard.jsx index 6ddddc7..6550263 100644 --- a/src/components/BallotKeysCard.jsx +++ b/src/components/BallotKeysCard.jsx @@ -33,6 +33,43 @@ export class BallotKeysCard extends React.Component { } } + @action("Get votingState of keys ballot") + getVotingState = async () => { + const { contractsStore, id } = this.props; + let votingState; + try { + votingState = await contractsStore.votingToChangeKeys.votingState(id); + } catch(e) { + console.log(e.message); + } + if (votingState) { + this.affectedKey = votingState.affectedKey; + this.affectedKeyType = votingState.affectedKeyType; + this.ballotType = votingState.ballotType; + this.getBallotTypeDisplayName(this.ballotType); + this.miningKey = votingState.miningKey; + + if (this.miningKey && this.miningKey !== '0x0000000000000000000000000000000000000000') { + let metadata; + try { + metadata = await contractsStore.getValidatorMetadata(this.miningKey); + } catch(e) { + console.log(e.message); + } + if (metadata) { + this.miningKey = `${metadata.lastName} ${this.miningKey}`; + } else { + this.miningKey = `${this.miningKey}`; + } + } + } else { + this.getAffectedKey(); + this.getAffectedKeyType(); + this.getBallotType(); + this.getMiningKey(); + } + } + @action("Get ballot type of keys ballot") getBallotType = async () => { const { contractsStore, id } = this.props; @@ -109,26 +146,25 @@ export class BallotKeysCard extends React.Component { } catch(e) { console.log(e.message); } - try { - metadata = await contractsStore.getValidatorMetadata(miningKey); - } catch(e) { - console.log(e.message); - } - if (metadata) { - this.miningKey = `${metadata.lastName} ${miningKey}`; - } else { - this.miningKey = `${miningKey}`; + if (miningKey && miningKey !== '0x0000000000000000000000000000000000000000') { + try { + metadata = await contractsStore.getValidatorMetadata(miningKey); + } catch(e) { + console.log(e.message); + } + if (metadata) { + this.miningKey = `${metadata.lastName} ${miningKey}`; + } else { + this.miningKey = `${miningKey}`; + } } } constructor(props) { super(props); - this.getAffectedKey(); + this.getVotingState(); this.getNewVotingKey(); this.getNewPayoutKey(); - this.getAffectedKeyType(); - this.getBallotType(); - this.getMiningKey(); } getAffectedKeyTypeDisplayName = () => {