(Fix) Optimization
This commit is contained in:
parent
d9514c84e2
commit
ebd0b7d8aa
|
@ -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);
|
||||
|
|
|
@ -36,12 +36,14 @@ export class BallotKeysCard extends React.Component {
|
|||
@action("Get votingState of keys ballot")
|
||||
getVotingState = async () => {
|
||||
const { contractsStore, id } = this.props;
|
||||
let votingState;
|
||||
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;
|
||||
this.affectedKeyType = votingState.affectedKeyType;
|
||||
|
@ -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>
|
||||
|
|
|
@ -22,8 +22,12 @@ export class BallotMinThresholdCard extends React.Component {
|
|||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
if (this.props.votingState) {
|
||||
this.proposedValue = this.props.votingState.proposedValue;
|
||||
} else {
|
||||
this.getProposedValue(this.props.id);
|
||||
}
|
||||
}
|
||||
|
||||
isSearchPattern = () => {
|
||||
let { commonStore } = this.props;
|
||||
|
@ -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>
|
||||
|
|
|
@ -35,9 +35,14 @@ export class BallotProxyCard extends React.Component {
|
|||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
if (this.props.votingState) {
|
||||
this.proposedAddress = this.props.votingState.proposedValue;
|
||||
this.contractType = this.props.votingState.contractType;
|
||||
} else {
|
||||
this.getProposedAddress();
|
||||
this.getContractType();
|
||||
}
|
||||
}
|
||||
|
||||
isSearchPattern = () => {
|
||||
let { commonStore } = this.props;
|
||||
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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":
|
||||
card = <BallotKeysCard
|
||||
id={allBallotsIDs[i]}
|
||||
id={id}
|
||||
type={ballotStore.BallotType.keys}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
startTime={startTime}/>
|
||||
startTime={startTime}
|
||||
votingState={votingState}/>
|
||||
break;
|
||||
case "votingToChangeMinThreshold":
|
||||
card = <BallotMinThresholdCard
|
||||
id={allBallotsIDs[i]}
|
||||
id={id}
|
||||
type={ballotStore.BallotType.minThreshold}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
startTime={startTime}/>
|
||||
startTime={startTime}
|
||||
votingState={votingState}/>
|
||||
break;
|
||||
case "votingToChangeProxy":
|
||||
card = <BallotProxyCard
|
||||
id={allBallotsIDs[i]}
|
||||
id={id}
|
||||
type={ballotStore.BallotType.proxy}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
startTime={startTime}/>
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue