(Fix) Optimization for new smart contracts
This commit is contained in:
parent
5a370b8eac
commit
61dc67ce2b
|
@ -2,7 +2,6 @@ import React from "react";
|
|||
import moment from "moment";
|
||||
import { observable, action, computed } from "mobx";
|
||||
import { inject, observer } from "mobx-react";
|
||||
import { toAscii } from "../helpers";
|
||||
import { messages } from "../messages";
|
||||
import swal from "sweetalert2";
|
||||
|
||||
|
@ -33,6 +32,7 @@ export class BallotCard extends React.Component {
|
|||
@observable progress;
|
||||
@observable totalVoters;
|
||||
@observable isFinalized;
|
||||
@observable canBeFinalized;
|
||||
@observable hasAlreadyVoted;
|
||||
@observable memo;
|
||||
|
||||
|
@ -188,8 +188,16 @@ export class BallotCard extends React.Component {
|
|||
}
|
||||
// getIsFinalized
|
||||
this.isFinalized = votingState.isFinalized;
|
||||
// canBeFinalizedNow
|
||||
this.canBeFinalized = votingState.hasOwnProperty('canBeFinalizedNow') ? votingState.canBeFinalizedNow : null;
|
||||
// getMemo
|
||||
this.memo = votingState.memo;
|
||||
// hasAlreadyVoted
|
||||
if (votingState.hasOwnProperty('hasAlreadyVoted')) {
|
||||
this.hasAlreadyVoted = votingState.hasAlreadyVoted;
|
||||
} else {
|
||||
this.getHasAlreadyVoted();
|
||||
}
|
||||
} else {
|
||||
this.getTimes();
|
||||
const creator = await this.repeatGetProperty(contractsStore, votingType, id, "getCreator", 0);
|
||||
|
@ -199,7 +207,9 @@ export class BallotCard extends React.Component {
|
|||
this.getTotalVoters();
|
||||
this.getProgress();
|
||||
this.getIsFinalized();
|
||||
this.canBeFinalizedNow();
|
||||
this.getMemo();
|
||||
this.getHasAlreadyVoted();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,12 +241,10 @@ export class BallotCard extends React.Component {
|
|||
@action("Get validator full name")
|
||||
getValidatorFullname = async (_miningKey) => {
|
||||
const { contractsStore } = this.props;
|
||||
let validator = await this.repeatGetProperty(contractsStore, "validatorMetadata", _miningKey, "validators", 0);
|
||||
let firstName, lastName, fullName
|
||||
if (validator) {
|
||||
firstName = toAscii(validator.firstName);
|
||||
lastName = toAscii(validator.lastName);
|
||||
fullName = `${firstName} ${lastName}`;
|
||||
const miningKeyLowerCase = _miningKey.toLowerCase();
|
||||
let fullName;
|
||||
if (contractsStore.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
|
||||
fullName = contractsStore.validatorsMetadata[miningKeyLowerCase].fullName;
|
||||
}
|
||||
this.creatorMiningKey = _miningKey;
|
||||
this.creator = fullName ? fullName : _miningKey;
|
||||
|
@ -274,7 +282,7 @@ export class BallotCard extends React.Component {
|
|||
canBeFinalizedNow = async () => {
|
||||
const { contractsStore, id, votingType } = this.props;
|
||||
let _canBeFinalizedNow = await this.repeatGetProperty(contractsStore, votingType, id, "canBeFinalizedNow", 0);
|
||||
return _canBeFinalizedNow;
|
||||
this.canBeFinalized = _canBeFinalizedNow;
|
||||
}
|
||||
|
||||
getMemo = async () => {
|
||||
|
@ -335,12 +343,13 @@ export class BallotCard extends React.Component {
|
|||
return;
|
||||
}
|
||||
commonStore.showLoading();
|
||||
let canBeFinalized = await this.canBeFinalizedNow();
|
||||
if (canBeFinalized === null) {
|
||||
await this.canBeFinalizedNow();
|
||||
let _canBeFinalized = this.canBeFinalized;
|
||||
if (_canBeFinalized === null) {
|
||||
console.log('canBeFinalizedNow is not existed');
|
||||
canBeFinalized = !(await this.isActive());
|
||||
_canBeFinalized = !(await this.isActive());
|
||||
}
|
||||
if (!canBeFinalized) {
|
||||
if (!_canBeFinalized) {
|
||||
commonStore.hideLoading();
|
||||
swal("Warning!", messages.INVALID_FINALIZE_MSG, "warning");
|
||||
return;
|
||||
|
@ -411,7 +420,6 @@ export class BallotCard extends React.Component {
|
|||
this.isFinalized = false;
|
||||
this.hasAlreadyVoted = false;
|
||||
this.getVotingState();
|
||||
this.getHasAlreadyVoted();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -426,7 +434,7 @@ export class BallotCard extends React.Component {
|
|||
|
||||
showCard = () => {
|
||||
let { commonStore } = this.props;
|
||||
let checkToFinalizeFilter = commonStore.isToFinalizeFilter ? !this.isFinalized && this.timeToFinish.val == 0 && this.timeToStart.val == 0 : true;
|
||||
let checkToFinalizeFilter = commonStore.isToFinalizeFilter ? !this.isFinalized && (this.timeToFinish.val == 0 || this.canBeFinalized) && this.timeToStart.val == 0 : true;
|
||||
let show = commonStore.isActiveFilter ? !this.isFinalized : checkToFinalizeFilter;
|
||||
return show;
|
||||
}
|
||||
|
|
|
@ -52,18 +52,30 @@ export class BallotKeysCard extends React.Component {
|
|||
this.miningKey = votingState.miningKey;
|
||||
|
||||
if (this.miningKey && this.miningKey !== '0x0000000000000000000000000000000000000000') {
|
||||
for (let i = 0; i < contractsStore.validatorsMetadata.length; i++) {
|
||||
if (contractsStore.validatorsMetadata[i].value.toLowerCase() === this.miningKey.toLowerCase()) {
|
||||
this.miningKey = contractsStore.validatorsMetadata[i].labelInvers;
|
||||
break;
|
||||
}
|
||||
const miningKeyLowerCase = this.miningKey.toLowerCase();
|
||||
if (contractsStore.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
|
||||
this.miningKey = contractsStore.validatorsMetadata[miningKeyLowerCase].lastNameAndKey;
|
||||
}
|
||||
}
|
||||
|
||||
if (votingState.hasOwnProperty('newVotingKey')) {
|
||||
this.newVotingKey = votingState.newVotingKey;
|
||||
} else {
|
||||
this.getNewVotingKey();
|
||||
}
|
||||
|
||||
if (votingState.hasOwnProperty('newPayoutKey')) {
|
||||
this.newPayoutKey = votingState.newPayoutKey;
|
||||
} else {
|
||||
this.getNewPayoutKey();
|
||||
}
|
||||
} else {
|
||||
this.getAffectedKey();
|
||||
this.getAffectedKeyType();
|
||||
this.getBallotType();
|
||||
this.getMiningKey();
|
||||
this.getNewVotingKey();
|
||||
this.getNewPayoutKey();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,12 +156,10 @@ export class BallotKeysCard extends React.Component {
|
|||
console.log(e.message);
|
||||
}
|
||||
if (miningKey && miningKey !== '0x0000000000000000000000000000000000000000') {
|
||||
const miningKeyLowerCase = this.miningKey.toLowerCase();
|
||||
this.miningKey = miningKey;
|
||||
for (let i = 0; i < contractsStore.validatorsMetadata.length; i++) {
|
||||
if (contractsStore.validatorsMetadata[i].value.toLowerCase() === this.miningKey.toLowerCase()) {
|
||||
this.miningKey = contractsStore.validatorsMetadata[i].labelInvers;
|
||||
break;
|
||||
}
|
||||
if (contractsStore.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
|
||||
this.miningKey = contractsStore.validatorsMetadata[miningKeyLowerCase].lastNameAndKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +167,6 @@ export class BallotKeysCard extends React.Component {
|
|||
constructor(props) {
|
||||
super(props);
|
||||
this.getVotingState();
|
||||
this.getNewVotingKey();
|
||||
this.getNewPayoutKey();
|
||||
}
|
||||
|
||||
getAffectedKeyTypeDisplayName = () => {
|
||||
|
|
|
@ -8,7 +8,12 @@ import "react-select/dist/react-select.css";
|
|||
export class BallotKeysMetadata extends React.Component {
|
||||
render() {
|
||||
const { ballotStore, contractsStore } = this.props;
|
||||
const options = contractsStore.validatorsMetadata.slice();
|
||||
let options = [];
|
||||
for (var key in contractsStore.validatorsMetadata) {
|
||||
if (contractsStore.validatorsMetadata.hasOwnProperty(key)) {
|
||||
options.push(contractsStore.validatorsMetadata[key]);
|
||||
}
|
||||
}
|
||||
let newVotingPayoutKeys = '';
|
||||
if (ballotStore.isNewValidatorPersonalData && contractsStore.votingToChangeKeys.doesMethodExist('createBallotToAddNewValidator')) {
|
||||
newVotingPayoutKeys = <div>
|
||||
|
|
|
@ -14,6 +14,8 @@ constants.ABIsSources = {
|
|||
};
|
||||
constants.NEW_MINING_KEY = {
|
||||
label: "New Mining Key",
|
||||
lastNameAndKey: "",
|
||||
fullName: "",
|
||||
value: "0x0000000000000000000000000000000000000000"
|
||||
};
|
||||
module.exports = {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import Web3 from 'web3';
|
||||
import moment from 'moment';
|
||||
import { networkAddresses } from './addresses';
|
||||
import helpers from "./helpers";
|
||||
import { toAscii } from "../helpers";
|
||||
|
@ -17,35 +16,21 @@ export default class ValidatorMetadata {
|
|||
this.metadataInstance = new web3_10.eth.Contract(MetadataAbi, METADATA_ADDRESS);
|
||||
}
|
||||
|
||||
async getValidatorData({votingKey, miningKey}){
|
||||
async getValidatorFullName({votingKey, miningKey}){
|
||||
miningKey = miningKey || await this.getMiningByVoting(votingKey);
|
||||
let validatorData = await this.metadataInstance.methods.validators(miningKey).call();
|
||||
let createdDate = validatorData.createdDate > 0 ? moment.unix(validatorData.createdDate).format('YYYY-MM-DD') : ''
|
||||
let updatedDate = validatorData.updatedDate > 0 ? moment.unix(validatorData.updatedDate).format('YYYY-MM-DD') : ''
|
||||
let expirationDate = validatorData.expirationDate > 0 ? moment.unix(validatorData.expirationDate).format('YYYY-MM-DD') : ''
|
||||
let validator;
|
||||
if (this.metadataInstance.methods.getValidatorName) {
|
||||
validator = await this.metadataInstance.methods.getValidatorName(miningKey).call();
|
||||
} else {
|
||||
validator = await this.metadataInstance.methods.validators(miningKey).call();
|
||||
}
|
||||
return {
|
||||
firstName: toAscii(validatorData.firstName),
|
||||
lastName: toAscii(validatorData.lastName),
|
||||
fullAddress: validatorData.fullAddress,
|
||||
createdDate,
|
||||
updatedDate,
|
||||
expirationDate,
|
||||
licenseId: toAscii(validatorData.licenseId),
|
||||
us_state: toAscii(validatorData.state),
|
||||
postal_code: toAscii(validatorData.zipcode),
|
||||
firstName: toAscii(validator.firstName),
|
||||
lastName: toAscii(validator.lastName)
|
||||
}
|
||||
}
|
||||
|
||||
async getMiningByVoting(votingKey){
|
||||
return await this.metadataInstance.methods.getMiningByVotingKey(votingKey).call();
|
||||
}
|
||||
|
||||
async getMinThreshold({miningKey}) {
|
||||
let validatorData = await this.metadataInstance.methods.validators(miningKey).call();
|
||||
return validatorData.minThreshold;
|
||||
}
|
||||
|
||||
validators(_miningKey) {
|
||||
return this.metadataInstance.methods.validators(_miningKey).call();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,13 @@ export default class VotingToChangeKeys {
|
|||
return null;
|
||||
}
|
||||
|
||||
getBallotInfo(_id, _votingKey) {
|
||||
if (this.doesMethodExist('getBallotInfo')) {
|
||||
return this.votingToChangeKeysInstance.methods.getBallotInfo(_id).call();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getCreator(_id) {
|
||||
if (this.doesMethodExist('getCreator')) {
|
||||
return this.votingToChangeKeysInstance.methods.getCreator(_id).call();
|
||||
|
|
|
@ -62,6 +62,13 @@ export default class VotingToChangeMinThreshold {
|
|||
return null;
|
||||
}
|
||||
|
||||
getBallotInfo(_id, _votingKey) {
|
||||
if (this.doesMethodExist('getBallotInfo')) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getCreator(_id) {
|
||||
if (this.doesMethodExist('getCreator')) {
|
||||
return this.votingToChangeMinThresholdInstance.methods.getCreator(_id).call();
|
||||
|
|
|
@ -62,6 +62,13 @@ export default class VotingToChangeProxy {
|
|||
return null;
|
||||
}
|
||||
|
||||
getBallotInfo(_id, _votingKey) {
|
||||
if (this.doesMethodExist('getBallotInfo')) {
|
||||
return this.votingToChangeProxyInstance.methods.getBallotInfo(_id, _votingKey).call();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getCreator(_id) {
|
||||
if (this.doesMethodExist('getCreator')) {
|
||||
return this.votingToChangeProxyInstance.methods.getCreator(_id).call();
|
||||
|
|
|
@ -39,7 +39,7 @@ class ContractsStore {
|
|||
constructor() {
|
||||
this.votingKey = null;
|
||||
this.miningKey = null;
|
||||
this.validatorsMetadata = [];
|
||||
this.validatorsMetadata = {};
|
||||
this.validatorLimits = {keys: null, minThreshold: null, proxy: null};
|
||||
}
|
||||
|
||||
|
@ -178,57 +178,58 @@ class ContractsStore {
|
|||
}
|
||||
|
||||
getCards = async (nextBallotId, contractType) => {
|
||||
if (nextBallotId) {
|
||||
for (let id = nextBallotId - 1; id >= 0; id--) {
|
||||
let startTime = 0;
|
||||
let votingState;
|
||||
for (let id = nextBallotId - 1; id >= 0; id--) {
|
||||
let startTime = 0;
|
||||
let votingState;
|
||||
|
||||
try {
|
||||
try {
|
||||
votingState = await this[contractType].getBallotInfo(id, this.votingKey);
|
||||
if (!votingState) {
|
||||
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);
|
||||
}
|
||||
|
||||
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={id}
|
||||
type={ballotStore.BallotType.keys}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
case "votingToChangeMinThreshold":
|
||||
card = <BallotMinThresholdCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.minThreshold}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
case "votingToChangeProxy":
|
||||
card = <BallotProxyCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.proxy}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
}
|
||||
|
||||
ballotsStore.ballotCards.push(card);
|
||||
}
|
||||
|
||||
let card;
|
||||
switch(contractType) {
|
||||
case "votingToChangeKeys":
|
||||
card = <BallotKeysCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.keys}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
case "votingToChangeMinThreshold":
|
||||
card = <BallotMinThresholdCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.minThreshold}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
case "votingToChangeProxy":
|
||||
card = <BallotProxyCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.proxy}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}
|
||||
startTime={startTime}/>
|
||||
break;
|
||||
}
|
||||
|
||||
ballotsStore.ballotCards.push(card);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,16 +265,25 @@ class ContractsStore {
|
|||
|
||||
@action
|
||||
async getAllValidatorMetadata() {
|
||||
this.validatorsMetadata.push(constants.NEW_MINING_KEY);
|
||||
//this.validatorsMetadata.push(constants.NEW_MINING_KEY);
|
||||
this.validatorsMetadata[constants.NEW_MINING_KEY.value] = constants.NEW_MINING_KEY;
|
||||
|
||||
const keys = await this.poaConsensus.getValidators();
|
||||
this.validatorsLength = keys.length;
|
||||
keys.forEach(async (key) => {
|
||||
const metadata = await this.validatorMetadata.getValidatorData({miningKey: key})
|
||||
this.validatorsMetadata.push({
|
||||
const metadata = await this.validatorMetadata.getValidatorFullName({miningKey: key})
|
||||
//this.validatorsMetadata.push({
|
||||
// label: `${key} ${metadata.lastName}`,
|
||||
// lastNameAndKey: `${metadata.lastName} ${key}`,
|
||||
// fullName: `${metadata.firstName} ${metadata.lastName}`,
|
||||
// value: key
|
||||
//})
|
||||
this.validatorsMetadata[key.toLowerCase()] = {
|
||||
label: `${key} ${metadata.lastName}`,
|
||||
labelInvers: `${metadata.lastName} ${key}`,
|
||||
lastNameAndKey: `${metadata.lastName} ${key}`,
|
||||
fullName: `${metadata.firstName} ${metadata.lastName}`,
|
||||
value: key
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue