(Fix) Optimization
This commit is contained in:
parent
d9514c84e2
commit
ebd0b7d8aa
|
@ -167,7 +167,10 @@ export class BallotCard extends React.Component {
|
||||||
@action("Get votingState")
|
@action("Get votingState")
|
||||||
getVotingState = async () => {
|
getVotingState = async () => {
|
||||||
const { contractsStore, id, votingType } = this.props;
|
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) {
|
if (votingState) {
|
||||||
// getTimes
|
// getTimes
|
||||||
this.startTime = moment.utc(votingState.startTime * 1000).format(USDateTimeFormat);
|
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")
|
@action("Get votingState of keys ballot")
|
||||||
getVotingState = async () => {
|
getVotingState = async () => {
|
||||||
const { contractsStore, id } = this.props;
|
const { contractsStore, id } = this.props;
|
||||||
let votingState;
|
let votingState = this.props.votingState;
|
||||||
|
if (!votingState) {
|
||||||
try {
|
try {
|
||||||
votingState = await contractsStore.votingToChangeKeys.votingState(id);
|
votingState = await contractsStore.votingToChangeKeys.votingState(id);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (votingState) {
|
if (votingState) {
|
||||||
this.affectedKey = votingState.affectedKey;
|
this.affectedKey = votingState.affectedKey;
|
||||||
this.affectedKeyType = votingState.affectedKeyType;
|
this.affectedKeyType = votingState.affectedKeyType;
|
||||||
|
@ -213,7 +215,7 @@ export class BallotKeysCard extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { id } = this.props;
|
let { id, votingState } = this.props;
|
||||||
|
|
||||||
let affectedKeyClassName;
|
let affectedKeyClassName;
|
||||||
let affectedKey = <p>{this.affectedKey}</p>;
|
let affectedKey = <p>{this.affectedKey}</p>;
|
||||||
|
@ -240,7 +242,7 @@ export class BallotKeysCard extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
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-i ballots-about-i_action">
|
||||||
<div className="ballots-about-td">
|
<div className="ballots-about-td">
|
||||||
<p className="ballots-about-i--title">Action</p>
|
<p className="ballots-about-i--title">Action</p>
|
||||||
|
|
|
@ -22,8 +22,12 @@ export class BallotMinThresholdCard extends React.Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
if (this.props.votingState) {
|
||||||
|
this.proposedValue = this.props.votingState.proposedValue;
|
||||||
|
} else {
|
||||||
this.getProposedValue(this.props.id);
|
this.getProposedValue(this.props.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isSearchPattern = () => {
|
isSearchPattern = () => {
|
||||||
let { commonStore } = this.props;
|
let { commonStore } = this.props;
|
||||||
|
@ -35,9 +39,9 @@ export class BallotMinThresholdCard extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { id } = this.props;
|
let { id, votingState } = this.props;
|
||||||
return (
|
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-i ballots-about-i_proposed-min-threshold">
|
||||||
<div className="ballots-about-td">
|
<div className="ballots-about-td">
|
||||||
<p className="ballots-about-i--title">Proposed min threshold</p>
|
<p className="ballots-about-i--title">Proposed min threshold</p>
|
||||||
|
|
|
@ -35,9 +35,14 @@ export class BallotProxyCard extends React.Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
if (this.props.votingState) {
|
||||||
|
this.proposedAddress = this.props.votingState.proposedValue;
|
||||||
|
this.contractType = this.props.votingState.contractType;
|
||||||
|
} else {
|
||||||
this.getProposedAddress();
|
this.getProposedAddress();
|
||||||
this.getContractType();
|
this.getContractType();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isSearchPattern = () => {
|
isSearchPattern = () => {
|
||||||
let { commonStore } = this.props;
|
let { commonStore } = this.props;
|
||||||
|
@ -50,9 +55,9 @@ export class BallotProxyCard extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { ballotStore, id } = this.props;
|
const { ballotStore, id, votingState } = this.props;
|
||||||
return (
|
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-i ballots-about-i_contract-type">
|
||||||
<div className="ballots-about-td">
|
<div className="ballots-about-td">
|
||||||
<p className="ballots-about-i--title">Contract type</p>
|
<p className="ballots-about-i--title">Contract type</p>
|
||||||
|
|
|
@ -56,6 +56,10 @@ export default class VotingToChangeKeys {
|
||||||
return this.votingToChangeKeysInstance.methods.getEndTime(_id).call();
|
return this.votingToChangeKeysInstance.methods.getEndTime(_id).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nextBallotId() {
|
||||||
|
return this.votingToChangeKeysInstance.methods.nextBallotId().call();
|
||||||
|
}
|
||||||
|
|
||||||
votingState(_id) {
|
votingState(_id) {
|
||||||
if (this.doesMethodExist('votingState')) {
|
if (this.doesMethodExist('votingState')) {
|
||||||
return this.votingToChangeKeysInstance.methods.votingState(_id).call();
|
return this.votingToChangeKeysInstance.methods.votingState(_id).call();
|
||||||
|
|
|
@ -51,6 +51,10 @@ export default class VotingToChangeMinThreshold {
|
||||||
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
|
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nextBallotId() {
|
||||||
|
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call();
|
||||||
|
}
|
||||||
|
|
||||||
votingState(_id) {
|
votingState(_id) {
|
||||||
if (this.doesMethodExist('votingState')) {
|
if (this.doesMethodExist('votingState')) {
|
||||||
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
|
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
|
||||||
|
|
|
@ -51,6 +51,10 @@ export default class VotingToChangeProxy {
|
||||||
return this.votingToChangeProxyInstance.methods.getEndTime(_id).call();
|
return this.votingToChangeProxyInstance.methods.getEndTime(_id).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nextBallotId() {
|
||||||
|
return this.votingToChangeProxyInstance.methods.nextBallotId().call();
|
||||||
|
}
|
||||||
|
|
||||||
votingState(_id) {
|
votingState(_id) {
|
||||||
if (this.doesMethodExist('votingState')) {
|
if (this.doesMethodExist('votingState')) {
|
||||||
return this.votingToChangeProxyInstance.methods.votingState(_id).call();
|
return this.votingToChangeProxyInstance.methods.votingState(_id).call();
|
||||||
|
|
|
@ -154,78 +154,90 @@ class ContractsStore {
|
||||||
|
|
||||||
@action("Get all keys ballots")
|
@action("Get all keys ballots")
|
||||||
getAllBallots = async () => {
|
getAllBallots = async () => {
|
||||||
let allKeysBallots, allMinThresholdBallots, allProxyBallots;
|
let keysNextBallotId = 0, minThresholdNextBallotId = 0, proxyNextBallotId = 0;
|
||||||
try {
|
try {
|
||||||
[allKeysBallots, allMinThresholdBallots, allProxyBallots] = await this.getAllBallotsIDsInternal();
|
[keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId] = await this.getAllBallotsNextIDs();
|
||||||
|
keysNextBallotId = Number(keysNextBallotId);
|
||||||
|
minThresholdNextBallotId = Number(minThresholdNextBallotId);
|
||||||
|
proxyNextBallotId = Number(proxyNextBallotId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
let allKeysBallotsIDs = this.getCards(allKeysBallots, "votingToChangeKeys");
|
const allKeysPromise = this.getCards(keysNextBallotId, "votingToChangeKeys");
|
||||||
let allMinThresholdBallotsIDs = this.getCards(allMinThresholdBallots, "votingToChangeMinThreshold");
|
const allMinThresholdPromise = this.getCards(minThresholdNextBallotId, "votingToChangeMinThreshold");
|
||||||
let allProxyBallotsIDs = this.getCards(allProxyBallots, "votingToChangeProxy");
|
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();
|
commonStore.hideLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCards = async (allBallots, contractType) => {
|
getCards = async (nextBallotId, contractType) => {
|
||||||
let allBallotsIDs = [];
|
if (nextBallotId) {
|
||||||
if (allBallots) {
|
for (let id = nextBallotId - 1; id >= 0; id--) {
|
||||||
allBallotsIDs = allBallots.map((event) => event.returnValues.id)
|
|
||||||
for (let i = allBallotsIDs.length - 1; i >= 0; i--) {
|
|
||||||
|
|
||||||
let startTime = 0;
|
let startTime = 0;
|
||||||
|
let votingState;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
startTime = await this[contractType].getStartTime(allBallotsIDs[i]);
|
votingState = await this[contractType].votingState(id);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e.message);
|
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;
|
let card;
|
||||||
switch(contractType) {
|
switch(contractType) {
|
||||||
case "votingToChangeKeys":
|
case "votingToChangeKeys":
|
||||||
card = <BallotKeysCard
|
card = <BallotKeysCard
|
||||||
id={allBallotsIDs[i]}
|
id={id}
|
||||||
type={ballotStore.BallotType.keys}
|
type={ballotStore.BallotType.keys}
|
||||||
key={ballotsStore.ballotCards.length}
|
key={ballotsStore.ballotCards.length}
|
||||||
startTime={startTime}/>
|
startTime={startTime}
|
||||||
|
votingState={votingState}/>
|
||||||
break;
|
break;
|
||||||
case "votingToChangeMinThreshold":
|
case "votingToChangeMinThreshold":
|
||||||
card = <BallotMinThresholdCard
|
card = <BallotMinThresholdCard
|
||||||
id={allBallotsIDs[i]}
|
id={id}
|
||||||
type={ballotStore.BallotType.minThreshold}
|
type={ballotStore.BallotType.minThreshold}
|
||||||
key={ballotsStore.ballotCards.length}
|
key={ballotsStore.ballotCards.length}
|
||||||
startTime={startTime}/>
|
startTime={startTime}
|
||||||
|
votingState={votingState}/>
|
||||||
break;
|
break;
|
||||||
case "votingToChangeProxy":
|
case "votingToChangeProxy":
|
||||||
card = <BallotProxyCard
|
card = <BallotProxyCard
|
||||||
id={allBallotsIDs[i]}
|
id={id}
|
||||||
type={ballotStore.BallotType.proxy}
|
type={ballotStore.BallotType.proxy}
|
||||||
key={ballotsStore.ballotCards.length}
|
key={ballotsStore.ballotCards.length}
|
||||||
startTime={startTime}/>
|
startTime={startTime}
|
||||||
|
votingState={votingState}/>
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ballotsStore.ballotCards.push(card);
|
ballotsStore.ballotCards.push(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
return allBallotsIDs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action("Get all keys ballots internal")
|
@action("Get all keys next ballot ids")
|
||||||
getAllBallotsIDsInternal = async () => {
|
getAllBallotsNextIDs = async () => {
|
||||||
let getAllKeysBallotsIDs = this.votingToChangeKeys.votingToChangeKeysInstance.getPastEvents('BallotCreated', {fromBlock: 0});
|
const keysNextBallotId = this.votingToChangeKeys.nextBallotId();
|
||||||
let getAllMinThresholdBallotsIDs = this.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.getPastEvents('BallotCreated', {fromBlock: 0});
|
const minThresholdNextBallotId = this.votingToChangeMinThreshold.nextBallotId();
|
||||||
let getAllProxyBallotsIDs = this.votingToChangeProxy.votingToChangeProxyInstance.getPastEvents('BallotCreated', {fromBlock: 0});
|
const proxyNextBallotId = this.votingToChangeProxy.nextBallotId();
|
||||||
|
return Promise.all([keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId]);
|
||||||
return Promise.all([getAllKeysBallotsIDs, getAllMinThresholdBallotsIDs, getAllProxyBallotsIDs]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
Loading…
Reference in New Issue