order of cards: new at the top; speed and stability of card loading
This commit is contained in:
parent
2c80777d9d
commit
7bcd4f9a91
|
@ -90,24 +90,14 @@ export class BallotCard extends React.Component {
|
|||
@action("Get start time of keys ballot")
|
||||
getStartTime = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let startTime;
|
||||
try {
|
||||
startTime = await this.getContract(contractsStore, votingType).getStartTime(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let startTime = startTime = await this.repeatGetProperty(contractsStore, votingType, id, "getStartTime", 0);
|
||||
this.startTime = moment.utc(startTime * 1000).format(USDateTimeFormat);
|
||||
}
|
||||
|
||||
@action("Get end time of keys ballot")
|
||||
getEndTime = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let endTime;
|
||||
try {
|
||||
endTime = await this.getContract(contractsStore, votingType).getEndTime(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let endTime = await this.repeatGetProperty(contractsStore, votingType, id, "getEndTime", 0);
|
||||
this.endTime = moment.utc(endTime * 1000).format(USDateTimeFormat);
|
||||
}
|
||||
|
||||
|
@ -156,12 +146,7 @@ export class BallotCard extends React.Component {
|
|||
@action("Get creator")
|
||||
getCreator = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let votingState;
|
||||
try {
|
||||
votingState = await this.getContract(contractsStore, votingType).votingState(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let votingState = await this.repeatGetProperty(contractsStore, votingType, id, "votingState", 0);
|
||||
if (votingState) {
|
||||
this.getValidatorFullname(votingState.creator);
|
||||
}
|
||||
|
@ -170,12 +155,7 @@ export class BallotCard extends React.Component {
|
|||
@action("Get progress")
|
||||
getProgress = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let progress;
|
||||
try {
|
||||
progress = await this.getContract(contractsStore, votingType).getProgress(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let progress = await this.repeatGetProperty(contractsStore, votingType, id, "getProgress", 0);
|
||||
if (progress) {
|
||||
this.progress = Number(progress);
|
||||
}
|
||||
|
@ -184,12 +164,7 @@ export class BallotCard extends React.Component {
|
|||
@action("Get total voters")
|
||||
getTotalVoters = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let totalVoters;
|
||||
try {
|
||||
totalVoters = await this.getContract(contractsStore, votingType).getTotalVoters(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let totalVoters = await this.repeatGetProperty(contractsStore, votingType, id, "getTotalVoters", 0);
|
||||
if (totalVoters) {
|
||||
this.totalVoters = Number(totalVoters);
|
||||
}
|
||||
|
@ -198,24 +173,14 @@ export class BallotCard extends React.Component {
|
|||
@action("Get isFinalized")
|
||||
getIsFinalized = async() => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let isFinalized;
|
||||
try {
|
||||
isFinalized = await this.getContract(contractsStore, votingType).getIsFinalized(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let isFinalized = await this.repeatGetProperty(contractsStore, votingType, id, "getIsFinalized", 0);
|
||||
this.isFinalized = isFinalized;
|
||||
}
|
||||
|
||||
@action("Get validator full name")
|
||||
getValidatorFullname = async (_miningKey) => {
|
||||
const { contractsStore } = this.props;
|
||||
let validator;
|
||||
try {
|
||||
validator = await contractsStore.validatorMetadata.validators(_miningKey);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let validator = await this.repeatGetProperty(contractsStore, "validatorMetadata", _miningKey, "validators", 0);
|
||||
let firstName, lastName, fullName
|
||||
if (validator) {
|
||||
firstName = toAscii(validator.firstName);
|
||||
|
@ -239,23 +204,13 @@ export class BallotCard extends React.Component {
|
|||
|
||||
isActive = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let _isActive;
|
||||
try {
|
||||
_isActive = await this.getContract(contractsStore, votingType).isActive(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let _isActive = await this.repeatGetProperty(contractsStore, votingType, id, "isActive", 0);
|
||||
return _isActive;
|
||||
}
|
||||
|
||||
getMemo = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let memo;
|
||||
try {
|
||||
memo = await this.getContract(contractsStore, votingType).getMemo(id);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
let memo = await this.repeatGetProperty(contractsStore, votingType, id, "getMemo", 0);
|
||||
this.memo = memo;
|
||||
return memo;
|
||||
}
|
||||
|
@ -328,14 +283,36 @@ export class BallotCard extends React.Component {
|
|||
});
|
||||
}
|
||||
|
||||
getContract(contractsStore, votingType) {
|
||||
switch(votingType) {
|
||||
repeatGetProperty = async (contractsStore, contractType, id, methodID, tryID) => {
|
||||
try {
|
||||
let val = await this.getContract(contractsStore, contractType)[methodID](id);
|
||||
if (tryID > 0) {
|
||||
console.log(`success from Try ${tryID + 1}`);
|
||||
}
|
||||
return val;
|
||||
} catch(e) {
|
||||
if (tryID < 10) {
|
||||
console.log(`trying to repeat get value again... Try ${tryID + 1}`);
|
||||
tryID++;
|
||||
await setTimeout(async () => {
|
||||
this.repeatGetProperty(contractsStore, contractType, id, methodID, tryID);
|
||||
}, 1000)
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getContract(contractsStore, contractType) {
|
||||
switch(contractType) {
|
||||
case "votingToChangeKeys":
|
||||
return contractsStore.votingToChangeKeys;
|
||||
case "votingToChangeMinThreshold":
|
||||
return contractsStore.votingToChangeMinThreshold;
|
||||
case "votingToChangeProxy":
|
||||
return contractsStore.votingToChangeProxy;
|
||||
case "validatorMetadata":
|
||||
return contractsStore.validatorMetadata;
|
||||
default:
|
||||
return contractsStore.votingToChangeKeys;
|
||||
}
|
||||
|
@ -419,7 +396,6 @@ export class BallotCard extends React.Component {
|
|||
|
||||
render () {
|
||||
let { contractsStore, votingType, children, isSearchPattern } = this.props;
|
||||
console.log(votingType);
|
||||
let ballotClass = (this.showCard() && (this.isCreatorPattern() || this.isMemoPattern() || isSearchPattern)) ? "ballots-i" : "ballots-i display-none";
|
||||
const threshold = this.getThreshold(contractsStore, votingType);
|
||||
return (
|
||||
|
|
|
@ -12,10 +12,13 @@ export class Ballots extends React.Component {
|
|||
|
||||
render () {
|
||||
const { ballotsStore } = this.props;
|
||||
let filteredBallotCards = ballotsStore.ballotCards.toJS().sort((a, b) => {
|
||||
return b.props.startTime - a.props.startTime;
|
||||
})
|
||||
return (
|
||||
<section className="container ballots">
|
||||
<h1 className="title">Ballots</h1>
|
||||
{ballotsStore.ballotCards.toJS()}
|
||||
{filteredBallotCards}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
|
28
src/index.js
28
src/index.js
|
@ -33,27 +33,29 @@ class AppMainRouter extends Component {
|
|||
commonStore.showLoading();
|
||||
|
||||
getWeb3().then(async (web3Config) => {
|
||||
await getContractsAddresses('sokol');
|
||||
await getContractsAddresses('core');
|
||||
let getSokolContractsAddresses = getContractsAddresses('sokol');
|
||||
let getCoreContractsAddresses = getContractsAddresses('core');
|
||||
await Promise.all([getSokolContractsAddresses, getCoreContractsAddresses]);
|
||||
|
||||
await contractsStore.setWeb3Instance(web3Config);
|
||||
await contractsStore.setPoaConsensus(web3Config);
|
||||
await contractsStore.setBallotsStorage(web3Config);
|
||||
await contractsStore.setVotingToChangeKeys(web3Config);
|
||||
await contractsStore.setVotingToChangeMinThreshold(web3Config);
|
||||
await contractsStore.setVotingToChangeProxy(web3Config);
|
||||
await contractsStore.setValidatorMetadata(web3Config);
|
||||
contractsStore.setWeb3Instance(web3Config);
|
||||
|
||||
let setPoaConsensus = contractsStore.setPoaConsensus(web3Config);
|
||||
let setBallotsStorage = contractsStore.setBallotsStorage(web3Config);
|
||||
let setVotingToChangeKeys = contractsStore.setVotingToChangeKeys(web3Config);
|
||||
let setVotingToChangeMinThreshold = contractsStore.setVotingToChangeMinThreshold(web3Config);
|
||||
let setVotingToChangeProxy = contractsStore.setVotingToChangeProxy(web3Config);
|
||||
let setValidatorMetadata = contractsStore.setValidatorMetadata(web3Config);
|
||||
|
||||
await contractsStore.getAllKeysBallots();
|
||||
await contractsStore.getAllMinThresholdBallots();
|
||||
await contractsStore.getAllProxyBallots();
|
||||
await Promise.all([setPoaConsensus, setBallotsStorage, setVotingToChangeKeys, setVotingToChangeMinThreshold, setVotingToChangeProxy, setValidatorMetadata])
|
||||
|
||||
await contractsStore.getAllBallots();
|
||||
await contractsStore.setMiningKey(web3Config);
|
||||
|
||||
contractsStore.getValidatorsLength();
|
||||
contractsStore.getKeysBallotThreshold();
|
||||
contractsStore.getMinThresholdBallotThreshold();
|
||||
contractsStore.getProxyBallotThreshold();
|
||||
contractsStore.setVotingKey(web3Config);
|
||||
await contractsStore.setMiningKey(web3Config);
|
||||
contractsStore.getValidatorActiveBallots();
|
||||
contractsStore.getAllValidatorMetadata();
|
||||
console.log("votingKey", contractsStore.votingKey);
|
||||
|
|
|
@ -13,11 +13,13 @@ import commonStore from './CommonStore'
|
|||
import { BallotKeysCard } from "../components/BallotKeysCard";
|
||||
import { BallotMinThresholdCard } from "../components/BallotMinThresholdCard";
|
||||
import { BallotProxyCard } from "../components/BallotProxyCard";
|
||||
import moment from "moment";
|
||||
|
||||
import "babel-polyfill";
|
||||
|
||||
const USDateTimeFormat = "MM/DD/YYYY h:mm:ss A";
|
||||
|
||||
class ContractsStore {
|
||||
@observable activeKeysBallotsIDs;
|
||||
@observable poaConsensus;
|
||||
@observable ballotsStorage;
|
||||
@observable votingToChangeKeys;
|
||||
|
@ -37,7 +39,6 @@ class ContractsStore {
|
|||
constructor() {
|
||||
this.votingKey = null;
|
||||
this.miningKey = null;
|
||||
this.activeKeysBallotsIDs = [];
|
||||
this.validatorsMetadata = [];
|
||||
this.validatorLimits = {keys: null, minThreshold: null, proxy: null};
|
||||
}
|
||||
|
@ -144,56 +145,100 @@ class ContractsStore {
|
|||
}
|
||||
|
||||
@action("Get all keys ballots")
|
||||
getAllKeysBallots = async () => {
|
||||
let allKeysBallots = await this.votingToChangeKeys.votingToChangeKeysInstance.getPastEvents('BallotCreated', {fromBlock: 0});
|
||||
let allKeysBallotsIDs = allKeysBallots.map((event) => event.returnValues.id)
|
||||
this.activeKeysBallotsIDs = allKeysBallotsIDs;
|
||||
for (let i = 0; i < allKeysBallotsIDs.length; i++) {
|
||||
ballotsStore.ballotCards.push(<BallotKeysCard id={this.activeKeysBallotsIDs[i]} type={ballotStore.BallotType.keys} key={ballotsStore.ballotCards.length}/>);
|
||||
}
|
||||
getAllBallots = async () => {
|
||||
let allKeysBallots, allMinThresholdBallots, allProxyBallots;
|
||||
try {
|
||||
[allKeysBallots, allMinThresholdBallots, allProxyBallots] = await this.getAllBallotsIDsInternal();
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
|
||||
if (allKeysBallotsIDs.length == 0) {
|
||||
let allKeysBallotsIDs = this.getCards(allKeysBallots, "votingToChangeKeys");
|
||||
let allMinThresholdBallotsIDs = this.getCards(allMinThresholdBallots, "votingToChangeMinThreshold");
|
||||
let allProxyBallotsIDs = this.getCards(allProxyBallots, "votingToChangeProxy");
|
||||
|
||||
await Promise.all([allKeysBallotsIDs, allMinThresholdBallotsIDs, allProxyBallotsIDs]);
|
||||
|
||||
let allBallotsIDsLength = allKeysBallotsIDs.length + allMinThresholdBallotsIDs.length + allProxyBallotsIDs.length;
|
||||
|
||||
if (allBallotsIDsLength == 0) {
|
||||
commonStore.hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
@action("Get all min threshold ballots")
|
||||
getAllMinThresholdBallots = async () => {
|
||||
let allMinThresholdBallots = await this.votingToChangeMinThreshold.votingToChangeMinThresholdInstance.getPastEvents('BallotCreated', {fromBlock: 0});
|
||||
let allMinThresholdBallotsIDs = allMinThresholdBallots.map((event) => event.returnValues.id)
|
||||
this.activeMinThresholdBallotsIDs = allMinThresholdBallotsIDs;
|
||||
for (let i = 0; i < allMinThresholdBallotsIDs.length; i++) {
|
||||
ballotsStore.ballotCards.push(<BallotMinThresholdCard id={this.activeMinThresholdBallotsIDs[i]} type={ballotStore.BallotType.keys} key={ballotsStore.ballotCards.length}/>);
|
||||
}
|
||||
getCards = async (allBallots, contractType) => {
|
||||
let allBallotsIDs = [];
|
||||
if (allBallots) {
|
||||
allBallotsIDs = allBallots.map((event) => event.returnValues.id)
|
||||
for (let i = allBallotsIDs.length - 1; i >= 0; i--) {
|
||||
|
||||
if (allMinThresholdBallotsIDs.length == 0) {
|
||||
commonStore.hideLoading();
|
||||
}
|
||||
let startTime = 0;
|
||||
try {
|
||||
startTime = await this[contractType].getStartTime(allBallotsIDs[i]);
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
|
||||
let card;
|
||||
switch(contractType) {
|
||||
case "votingToChangeKeys":
|
||||
card = <BallotKeysCard
|
||||
id={allBallotsIDs[i]}
|
||||
type={ballotStore.BallotType.keys}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
case "votingToChangeMinThreshold":
|
||||
card = <BallotMinThresholdCard
|
||||
id={allBallotsIDs[i]}
|
||||
type={ballotStore.BallotType.minThreshold}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
case "votingToChangeProxy":
|
||||
card = <BallotProxyCard
|
||||
id={allBallotsIDs[i]}
|
||||
type={ballotStore.BallotType.proxy}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
}
|
||||
|
||||
ballotsStore.ballotCards.push(card);
|
||||
}
|
||||
|
||||
return allBallotsIDs;
|
||||
}
|
||||
}
|
||||
|
||||
@action("Get all proxy ballots")
|
||||
getAllProxyBallots = async () => {
|
||||
let allProxyBallots = await this.votingToChangeProxy.votingToChangeProxyInstance.getPastEvents('BallotCreated', {fromBlock: 0});
|
||||
let allProxyBallotsIDs = allProxyBallots.map((event) => event.returnValues.id)
|
||||
this.activeProxyBallotsIDs = allProxyBallotsIDs;
|
||||
for (let i = 0; i < allProxyBallotsIDs.length; i++) {
|
||||
ballotsStore.ballotCards.push(<BallotProxyCard id={this.activeProxyBallotsIDs[i]} type={ballotStore.BallotType.keys} key={ballotsStore.ballotCards.length}/>);
|
||||
}
|
||||
|
||||
if (allProxyBallotsIDs.length == 0) {
|
||||
commonStore.hideLoading();
|
||||
}
|
||||
@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
|
||||
async getValidatorActiveBallots() {
|
||||
if(this.web3Instance && this.netId){
|
||||
await this.setVotingToChangeKeys({web3Instance: this.web3Instance, netId: this.netId})
|
||||
await this.setVotingToChangeMinThreshold({web3Instance: this.web3Instance, netId: this.netId})
|
||||
await this.setVotingToChangeProxy({web3Instance: this.web3Instance, netId: this.netId})
|
||||
this.validatorLimits.keys = await this.votingToChangeKeys.getBallotLimit(this.web3Instance.eth.defaultAccount);
|
||||
this.validatorLimits.minThreshold = await this.votingToChangeMinThreshold.getBallotLimit(this.web3Instance.eth.defaultAccount);
|
||||
this.validatorLimits.proxy = await this.votingToChangeProxy.getBallotLimit(this.web3Instance.eth.defaultAccount);
|
||||
let setVotingToChangeKeys = this.setVotingToChangeKeys({web3Instance: this.web3Instance, netId: this.netId})
|
||||
let setVotingToChangeMinThreshold = this.setVotingToChangeMinThreshold({web3Instance: this.web3Instance, netId: this.netId})
|
||||
let setVotingToChangeProxy = this.setVotingToChangeProxy({web3Instance: this.web3Instance, netId: this.netId})
|
||||
|
||||
await Promise.all([setVotingToChangeKeys, setVotingToChangeMinThreshold, setVotingToChangeProxy]);
|
||||
|
||||
let getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.web3Instance.eth.defaultAccount);
|
||||
let getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(this.web3Instance.eth.defaultAccount);
|
||||
let getProxyLimit = await this.votingToChangeProxy.getBallotLimit(this.web3Instance.eth.defaultAccount);
|
||||
|
||||
await Promise.all([getKeysLimit, getMinThresholdLimit, getProxyLimit])
|
||||
.then(([keysLimit, minThresholdLimit, proxyLimit]) => {
|
||||
this.validatorLimits.keys = keysLimit;
|
||||
this.validatorLimits.minThreshold = minThresholdLimit;
|
||||
this.validatorLimits.proxy = proxyLimit;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue