(Fix) Optimization

This commit is contained in:
Vadim Arasev 2018-06-14 15:41:01 +03:00
parent d9514c84e2
commit ebd0b7d8aa
8 changed files with 92 additions and 54 deletions

View File

@ -167,7 +167,10 @@ 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);
let votingState = this.props.votingState;
if (!votingState) {
votingState = await this.repeatGetProperty(contractsStore, votingType, id, "votingState", 0);
}
if (votingState) {
// getTimes
this.startTime = moment.utc(votingState.startTime * 1000).format(USDateTimeFormat);

View File

@ -36,11 +36,13 @@ 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);
let votingState = this.props.votingState;
if (!votingState) {
try {
votingState = await contractsStore.votingToChangeKeys.votingState(id);
} catch(e) {
console.log(e.message);
}
}
if (votingState) {
this.affectedKey = votingState.affectedKey;
@ -213,7 +215,7 @@ export class BallotKeysCard extends React.Component {
}
render () {
let { id } = this.props;
let { id, votingState } = this.props;
let affectedKeyClassName;
let affectedKey = <p>{this.affectedKey}</p>;
@ -240,7 +242,7 @@ export class BallotKeysCard extends React.Component {
}
return (
<BallotCard votingType="votingToChangeKeys" id={id} isSearchPattern={this.isSearchPattern()}>
<BallotCard votingType="votingToChangeKeys" votingState={votingState} id={id} isSearchPattern={this.isSearchPattern()}>
<div className="ballots-about-i ballots-about-i_action">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Action</p>

View File

@ -22,7 +22,11 @@ export class BallotMinThresholdCard extends React.Component {
constructor(props) {
super(props);
this.getProposedValue(this.props.id);
if (this.props.votingState) {
this.proposedValue = this.props.votingState.proposedValue;
} else {
this.getProposedValue(this.props.id);
}
}
isSearchPattern = () => {
@ -35,9 +39,9 @@ export class BallotMinThresholdCard extends React.Component {
}
render () {
let { id } = this.props;
let { id, votingState } = this.props;
return (
<BallotCard votingType="votingToChangeMinThreshold" id={id} isSearchPattern={this.isSearchPattern()}>
<BallotCard votingType="votingToChangeMinThreshold" votingState={votingState} id={id} isSearchPattern={this.isSearchPattern()}>
<div className="ballots-about-i ballots-about-i_proposed-min-threshold">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Proposed min threshold</p>

View File

@ -35,8 +35,13 @@ export class BallotProxyCard extends React.Component {
constructor(props) {
super(props);
this.getProposedAddress();
this.getContractType();
if (this.props.votingState) {
this.proposedAddress = this.props.votingState.proposedValue;
this.contractType = this.props.votingState.contractType;
} else {
this.getProposedAddress();
this.getContractType();
}
}
isSearchPattern = () => {
@ -50,9 +55,9 @@ export class BallotProxyCard extends React.Component {
}
render () {
const { ballotStore, id } = this.props;
const { ballotStore, id, votingState } = this.props;
return (
<BallotCard votingType="votingToChangeProxy" id={id} isSearchPattern={this.isSearchPattern()}>
<BallotCard votingType="votingToChangeProxy" votingState={votingState} id={id} isSearchPattern={this.isSearchPattern()}>
<div className="ballots-about-i ballots-about-i_contract-type">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Contract type</p>

View File

@ -56,6 +56,10 @@ export default class VotingToChangeKeys {
return this.votingToChangeKeysInstance.methods.getEndTime(_id).call();
}
nextBallotId() {
return this.votingToChangeKeysInstance.methods.nextBallotId().call();
}
votingState(_id) {
if (this.doesMethodExist('votingState')) {
return this.votingToChangeKeysInstance.methods.votingState(_id).call();

View File

@ -51,6 +51,10 @@ export default class VotingToChangeMinThreshold {
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
}
nextBallotId() {
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call();
}
votingState(_id) {
if (this.doesMethodExist('votingState')) {
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();

View File

@ -51,6 +51,10 @@ export default class VotingToChangeProxy {
return this.votingToChangeProxyInstance.methods.getEndTime(_id).call();
}
nextBallotId() {
return this.votingToChangeProxyInstance.methods.nextBallotId().call();
}
votingState(_id) {
if (this.doesMethodExist('votingState')) {
return this.votingToChangeProxyInstance.methods.votingState(_id).call();

View File

@ -154,78 +154,90 @@ class ContractsStore {
@action("Get all keys ballots")
getAllBallots = async () => {
let allKeysBallots, allMinThresholdBallots, allProxyBallots;
let keysNextBallotId = 0, minThresholdNextBallotId = 0, proxyNextBallotId = 0;
try {
[allKeysBallots, allMinThresholdBallots, allProxyBallots] = await this.getAllBallotsIDsInternal();
[keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId] = await this.getAllBallotsNextIDs();
keysNextBallotId = Number(keysNextBallotId);
minThresholdNextBallotId = Number(minThresholdNextBallotId);
proxyNextBallotId = Number(proxyNextBallotId);
} catch (e) {
console.log(e.message);
}
let allKeysBallotsIDs = this.getCards(allKeysBallots, "votingToChangeKeys");
let allMinThresholdBallotsIDs = this.getCards(allMinThresholdBallots, "votingToChangeMinThreshold");
let allProxyBallotsIDs = this.getCards(allProxyBallots, "votingToChangeProxy");
const allKeysPromise = this.getCards(keysNextBallotId, "votingToChangeKeys");
const allMinThresholdPromise = this.getCards(minThresholdNextBallotId, "votingToChangeMinThreshold");
const allProxyPromise = this.getCards(proxyNextBallotId, "votingToChangeProxy");
await Promise.all([allKeysBallotsIDs, allMinThresholdBallotsIDs, allProxyBallotsIDs]);
await Promise.all([allKeysPromise, allMinThresholdPromise, allProxyPromise]);
let allBallotsIDsLength = allKeysBallotsIDs.length + allMinThresholdBallotsIDs.length + allProxyBallotsIDs.length;
const allBallotsIDsLength = keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId;
if (allBallotsIDsLength == 0) {
if (allBallotsIDsLength === 0) {
commonStore.hideLoading();
}
}
getCards = async (allBallots, contractType) => {
let allBallotsIDs = [];
if (allBallots) {
allBallotsIDs = allBallots.map((event) => event.returnValues.id)
for (let i = allBallotsIDs.length - 1; i >= 0; i--) {
getCards = async (nextBallotId, contractType) => {
if (nextBallotId) {
for (let id = nextBallotId - 1; id >= 0; id--) {
let startTime = 0;
let votingState;
try {
startTime = await this[contractType].getStartTime(allBallotsIDs[i]);
votingState = await this[contractType].votingState(id);
} catch(e) {
console.log(e.message);
}
if (votingState) {
startTime = votingState.startTime;
} else {
try {
startTime = await this[contractType].getStartTime(id);
} catch(e) {
console.log(e.message);
}
}
let card;
switch(contractType) {
case "votingToChangeKeys":
case "votingToChangeKeys":
card = <BallotKeysCard
id={allBallotsIDs[i]}
type={ballotStore.BallotType.keys}
key={ballotsStore.ballotCards.length}
startTime={startTime}/>
id={id}
type={ballotStore.BallotType.keys}
key={ballotsStore.ballotCards.length}
startTime={startTime}
votingState={votingState}/>
break;
case "votingToChangeMinThreshold":
case "votingToChangeMinThreshold":
card = <BallotMinThresholdCard
id={allBallotsIDs[i]}
type={ballotStore.BallotType.minThreshold}
key={ballotsStore.ballotCards.length}
startTime={startTime}/>
id={id}
type={ballotStore.BallotType.minThreshold}
key={ballotsStore.ballotCards.length}
startTime={startTime}
votingState={votingState}/>
break;
case "votingToChangeProxy":
case "votingToChangeProxy":
card = <BallotProxyCard
id={allBallotsIDs[i]}
type={ballotStore.BallotType.proxy}
key={ballotsStore.ballotCards.length}
startTime={startTime}/>
id={id}
type={ballotStore.BallotType.proxy}
key={ballotsStore.ballotCards.length}
startTime={startTime}
votingState={votingState}/>
break;
}
ballotsStore.ballotCards.push(card);
}
return allBallotsIDs;
}
}
@action("Get all keys ballots internal")
getAllBallotsIDsInternal = async () => {
let getAllKeysBallotsIDs = this.votingToChangeKeys.votingToChangeKeysInstance.getPastEvents('BallotCreated', {fromBlock: 0});
let getAllMinThresholdBallotsIDs = this.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.getPastEvents('BallotCreated', {fromBlock: 0});
let getAllProxyBallotsIDs = this.votingToChangeProxy.votingToChangeProxyInstance.getPastEvents('BallotCreated', {fromBlock: 0});
return Promise.all([getAllKeysBallotsIDs, getAllMinThresholdBallotsIDs, getAllProxyBallotsIDs]);
@action("Get all keys next ballot ids")
getAllBallotsNextIDs = async () => {
const keysNextBallotId = this.votingToChangeKeys.nextBallotId();
const minThresholdNextBallotId = this.votingToChangeMinThreshold.nextBallotId();
const proxyNextBallotId = this.votingToChangeProxy.nextBallotId();
return Promise.all([keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId]);
}
@action