(Fix) Light optimization

This commit is contained in:
Vadim Arasev 2018-06-14 11:05:35 +03:00
parent d075d8a43c
commit e1dbd90c76
2 changed files with 86 additions and 19 deletions

View File

@ -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() {

View File

@ -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 = () => {