(Fix) Fix of searching and code refactoring

This commit is contained in:
Vadim Arasev 2018-06-20 15:23:22 +03:00
parent 001e6c642d
commit 744026532d
10 changed files with 195 additions and 641 deletions

View File

@ -11,7 +11,7 @@ const USDateTimeFormat = "MM/DD/YYYY h:mm:ss A";
const zeroTimeTo = "00:00";
@inject("commonStore", "contractsStore", "ballotStore", "routing")
@inject("commonStore", "contractsStore", "routing")
@observer
export class BallotCard extends React.Component {
@observable startTime;
@ -93,20 +93,6 @@ export class BallotCard extends React.Component {
return votesPercents;
}
@action("Get start time of keys ballot")
getStartTime = async () => {
const { contractsStore, id, votingType } = this.props;
let 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 = await this.repeatGetProperty(contractsStore, votingType, id, "getEndTime", 0);
this.endTime = moment.utc(endTime * 1000).format(USDateTimeFormat);
}
@action("Calculate time to start/finish")
calcTimeTo = () => {
const _now = moment();
@ -141,114 +127,6 @@ export class BallotCard extends React.Component {
return formattedMs;
}
@action("Get times")
getTimes = async () => {
await this.getStartTime();
await this.getEndTime();
this.calcTimeTo();
}
@action("Get creator")
getCreator = async () => {
const { contractsStore, id, votingType } = this.props;
let creator = await this.repeatGetProperty(contractsStore, votingType, id, "getCreator", 0);
if (creator) {
this.getValidatorFullname(creator);
} else {
let votingState = await this.repeatGetProperty(contractsStore, votingType, id, "votingState", 0);
if (votingState) {
this.getValidatorFullname(votingState.creator);
}
}
}
@action("Get votingState")
getVotingState = async () => {
const { contractsStore, id, votingType } = this.props;
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);
this.endTime = moment.utc(votingState.endTime * 1000).format(USDateTimeFormat);
this.calcTimeTo();
// getCreator
this.getValidatorFullname(votingState.creator);
// getTotalVoters
if (votingState.totalVoters) {
this.totalVoters = Number(votingState.totalVoters);
}
// getProgress
if (votingState.progress) {
this.progress = Number(votingState.progress);
}
// 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);
if (creator) {
this.getValidatorFullname(creator);
}
this.getTotalVoters();
this.getProgress();
this.getIsFinalized();
this.canBeFinalizedNow();
this.getMemo();
this.getHasAlreadyVoted();
}
}
@action("Get progress")
getProgress = async () => {
const { contractsStore, id, votingType } = this.props;
let progress = await this.repeatGetProperty(contractsStore, votingType, id, "getProgress", 0);
if (progress) {
this.progress = Number(progress);
}
}
@action("Get total voters")
getTotalVoters = async () => {
const { contractsStore, id, votingType } = this.props;
let totalVoters = await this.repeatGetProperty(contractsStore, votingType, id, "getTotalVoters", 0);
if (totalVoters) {
this.totalVoters = Number(totalVoters);
}
}
@action("Get isFinalized")
getIsFinalized = async() => {
const { contractsStore, id, votingType } = this.props;
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;
const miningKeyLowerCase = _miningKey.toLowerCase();
let fullName;
if (contractsStore.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
fullName = contractsStore.validatorsMetadata[miningKeyLowerCase].fullName;
}
this.creatorMiningKey = _miningKey;
this.creator = fullName ? fullName : _miningKey;
}
@action("validator has already voted")
getHasAlreadyVoted = async () => {
const { contractsStore, id, votingType } = this.props;
@ -284,13 +162,6 @@ export class BallotCard extends React.Component {
this.canBeFinalized = _canBeFinalizedNow;
}
getMemo = async () => {
const { contractsStore, id, votingType } = this.props;
let memo = await this.repeatGetProperty(contractsStore, votingType, id, "getMemo", 0);
this.memo = memo;
return memo;
}
vote = async ({choice}) => {
if (this.timeToStart.val > 0) {
swal("Warning!", messages.ballotIsNotActiveMsg(this.timeTo.displayValue), "warning");
@ -416,9 +287,30 @@ export class BallotCard extends React.Component {
constructor(props) {
super(props);
this.isFinalized = false;
this.hasAlreadyVoted = false;
this.getVotingState();
const { votingState } = this.props;
// getTimes
this.startTime = moment.utc(votingState.startTime * 1000).format(USDateTimeFormat);
this.endTime = moment.utc(votingState.endTime * 1000).format(USDateTimeFormat);
this.calcTimeTo();
// getCreator
this.creator = votingState.creator;
this.creatorMiningKey = votingState.creatorMiningKey;
// getTotalVoters
this.totalVoters = Number(votingState.totalVoters);
// getProgress
this.progress = Number(votingState.progress);
// 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();
}
}
componentDidMount() {
@ -433,34 +325,11 @@ export class BallotCard extends React.Component {
showCard = () => {
let { commonStore } = this.props;
let checkToFinalizeFilter = commonStore.isToFinalizeFilter ? !this.isFinalized && (this.timeToFinish.val == 0 || this.canBeFinalized) && 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;
}
isCreatorPattern = () => {
let { commonStore } = this.props;
if (commonStore.searchTerm) {
if (commonStore.searchTerm.length > 0) {
const _isCreatorPattern = String(this.creator).toLowerCase().includes(commonStore.searchTerm);
const _isCreatorMiningKeyPattern = String(this.creatorMiningKey).toLowerCase().includes(commonStore.searchTerm);
return _isCreatorPattern || _isCreatorMiningKeyPattern;
}
}
return true;
}
isMemoPattern = () => {
let { commonStore } = this.props;
if (commonStore.searchTerm) {
if (commonStore.searchTerm.length > 0) {
const _isMemoPattern = String(this.memo).toLowerCase().includes(commonStore.searchTerm);
return _isMemoPattern;
}
}
return true;
}
typeName(type){
switch(type) {
case "votingToChangeMinThreshold":
@ -475,9 +344,8 @@ export class BallotCard extends React.Component {
}
render () {
let { contractsStore, votingType, children, isSearchPattern } = this.props;
let isFromSearch = (this.isCreatorPattern() || this.isMemoPattern() || isSearchPattern);
let ballotClass = (this.showCard() && isFromSearch) ? this.isFinalized ? "ballots-i" : "ballots-i ballots-i-not-finalized" : "ballots-i display-none";
let { contractsStore, votingType, children } = this.props;
let ballotClass = this.showCard() ? this.isFinalized ? "ballots-i" : "ballots-i ballots-i-not-finalized" : "ballots-i display-none";
let voteScaleClass = this.isFinalized ? "vote-scale" : "vote-scale vote-scale-not-finalized";
let hasAlreadyVotedLabel = <div className="ballots-i--vote ballots-i--vote-label ballots-i--vote-label-right ballots-i--vote_no">You already voted</div>;
let showHasAlreadyVotedLabel = this.hasAlreadyVoted ? hasAlreadyVotedLabel : "";

View File

@ -1,247 +1,24 @@
import React from "react";
import { observable, action } from "mobx";
import { inject, observer } from "mobx-react";
import { BallotCard } from "./BallotCard";
@inject("commonStore", "contractsStore", "ballotStore", "routing")
@inject("commonStore", "routing")
@observer
export class BallotKeysCard extends React.Component {
@observable affectedKey;
@observable newVotingKey;
@observable newPayoutKey;
@observable affectedKeyType;
@observable ballotType;
@observable ballotTypeDisplayName;
@observable miningKey;
@action("Get ballotTypeDisplayName")
getBallotTypeDisplayName(ballotType) {
const { ballotStore } = this.props;
switch(parseInt(ballotType, 10)) {
case ballotStore.KeysBallotType.add:
this.ballotTypeDisplayName = "add";
break;
case ballotStore.KeysBallotType.remove:
this.ballotTypeDisplayName = "remove";
break;
case ballotStore.KeysBallotType.swap:
this.ballotTypeDisplayName = "swap";
break;
default:
this.ballotTypeDisplayName = "";
break;
}
}
@action("Get votingState of keys ballot")
getVotingState = async () => {
const { contractsStore, id } = this.props;
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;
this.ballotType = votingState.ballotType;
this.getBallotTypeDisplayName(this.ballotType);
this.miningKey = votingState.miningKey;
if (this.miningKey && this.miningKey !== '0x0000000000000000000000000000000000000000') {
const miningKeyLowerCase = this.miningKey.toLowerCase();
if (contractsStore.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
this.miningKey = contractsStore.validatorsMetadata[miningKeyLowerCase].lastNameAndKey;
}
}
if (votingState.hasOwnProperty('newVotingKey')) {
this.newVotingKey = votingState.newVotingKey;
if (this.newVotingKey === "0x0000000000000000000000000000000000000000") {
this.newVotingKey = "";
}
} else {
this.getNewVotingKey();
}
if (votingState.hasOwnProperty('newPayoutKey')) {
this.newPayoutKey = votingState.newPayoutKey;
if (this.newPayoutKey === "0x0000000000000000000000000000000000000000") {
this.newPayoutKey = "";
}
} else {
this.getNewPayoutKey();
}
} else {
this.getAffectedKey();
this.getAffectedKeyType();
this.getBallotType();
this.getMiningKey();
this.getNewVotingKey();
this.getNewPayoutKey();
}
}
@action("Get ballot type of keys ballot")
getBallotType = async () => {
const { contractsStore, id } = this.props;
let ballotType;
try {
ballotType = await contractsStore.votingToChangeKeys.getBallotType(id);
} catch(e) {
console.log(e.message);
}
this.ballotType = ballotType;
this.getBallotTypeDisplayName(ballotType);
}
@action("Get affected key type of keys ballot")
getAffectedKeyType = async () => {
const { contractsStore, id } = this.props;
let affectedKeyType;
try {
affectedKeyType = await contractsStore.votingToChangeKeys.getAffectedKeyType(id);
} catch(e) {
console.log(e.message);
}
this.affectedKeyType = affectedKeyType;
}
@action("Get affected key of keys ballot")
getAffectedKey = async () => {
const { contractsStore, id } = this.props;
let affectedKey;
try {
affectedKey = await contractsStore.votingToChangeKeys.getAffectedKey(id);
} catch (e) {
console.log(e.message);
}
this.affectedKey = affectedKey;
}
@action("Get new voting key of keys ballot")
getNewVotingKey = async () => {
const { contractsStore, id } = this.props;
let newVotingKey;
try {
newVotingKey = await contractsStore.votingToChangeKeys.getNewVotingKey(id);
if (newVotingKey === "0x0000000000000000000000000000000000000000") {
newVotingKey = "";
}
} catch (e) {
console.log(e.message);
}
this.newVotingKey = newVotingKey;
}
@action("Get new payout key of keys ballot")
getNewPayoutKey = async () => {
const { contractsStore, id } = this.props;
let newPayoutKey;
try {
newPayoutKey = await contractsStore.votingToChangeKeys.getNewPayoutKey(id);
if (newPayoutKey === "0x0000000000000000000000000000000000000000") {
newPayoutKey = "";
}
} catch (e) {
console.log(e.message);
}
this.newPayoutKey = newPayoutKey;
}
@action("Get mining key of keys ballot")
getMiningKey = async () => {
const { contractsStore, id } = this.props;
let miningKey;
try {
miningKey = await contractsStore.votingToChangeKeys.getMiningKey(id);
} catch(e) {
console.log(e.message);
}
if (miningKey && miningKey !== '0x0000000000000000000000000000000000000000') {
const miningKeyLowerCase = this.miningKey.toLowerCase();
this.miningKey = miningKey;
if (contractsStore.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
this.miningKey = contractsStore.validatorsMetadata[miningKeyLowerCase].lastNameAndKey;
}
}
}
constructor(props) {
super(props);
this.getVotingState();
}
getAffectedKeyTypeDisplayName = () => {
const { ballotStore } = this.props;
let result;
switch(parseInt(this.affectedKeyType, 10)) {
case ballotStore.KeyType.mining:
result = "mining";
break;
case ballotStore.KeyType.voting:
result = "voting";
break;
case ballotStore.KeyType.payout:
result = "payout";
break;
default:
result = "";
break;
}
if (this.isAddMining()) {
if (this.newVotingKey) result += ', voting';
if (this.newPayoutKey) result += ', payout';
}
return result;
}
isAddMining = () => {
const { ballotStore } = this.props;
const ballotType = parseInt(this.ballotType, 10);
const affectedKeyType = parseInt(this.affectedKeyType, 10);
return ballotType === ballotStore.KeysBallotType.add && affectedKeyType === ballotStore.KeyType.mining;
}
isSearchPattern = () => {
let { commonStore } = this.props;
if (commonStore.searchTerm) {
const affectedKeyTypeDisplayName = this.getAffectedKeyTypeDisplayName();
const isMiningKeyPattern = String(this.miningKey).toLowerCase().includes(commonStore.searchTerm);
const isAffectedKeyPattern = String(this.affectedKey).toLowerCase().includes(commonStore.searchTerm);
const isNewVotingKeyPattern = String(this.newVotingKey).toLowerCase().includes(commonStore.searchTerm);
const isNewPayoutKeyPattern = String(this.newPayoutKey).toLowerCase().includes(commonStore.searchTerm);
const isAffectedKeyTypeDisplayNamePattern = String(affectedKeyTypeDisplayName).toLowerCase().includes(commonStore.searchTerm);
const isBallotTypeDisplayNamePattern = String(this.ballotTypeDisplayName).toLowerCase().includes(commonStore.searchTerm);
return (
isMiningKeyPattern ||
isAffectedKeyPattern ||
isNewVotingKeyPattern ||
isNewPayoutKeyPattern ||
isAffectedKeyTypeDisplayNamePattern ||
isBallotTypeDisplayNamePattern
);
}
return true;
}
render () {
let { id, votingState } = this.props;
let affectedKeyClassName;
let affectedKey = <p>{this.affectedKey}</p>;
let affectedKey = <p>{votingState.affectedKey}</p>;
let newVotingKey;
let newPayoutKey;
let miningKeyDiv;
if (this.isAddMining()) {
if (votingState.isAddMining) {
affectedKeyClassName = 'ballots-about-i_key_wide';
if (this.newVotingKey || this.newPayoutKey) {
affectedKey = <p>Mining: {this.affectedKey}</p>;
if (this.newVotingKey) newVotingKey = <p>Voting: {this.newVotingKey}</p>;
if (this.newPayoutKey) newPayoutKey = <p>Payout: {this.newPayoutKey}</p>;
if (votingState.newVotingKey || votingState.newPayoutKey) {
affectedKey = <p>Mining: {votingState.affectedKey}</p>;
if (votingState.newVotingKey) newVotingKey = <p>Voting: {votingState.newVotingKey}</p>;
if (votingState.newPayoutKey) newPayoutKey = <p>Payout: {votingState.newPayoutKey}</p>;
}
} else {
affectedKeyClassName = 'ballots-about-i_key';
@ -250,19 +27,19 @@ export class BallotKeysCard extends React.Component {
<p className="ballots-about-i--title">Validator key</p>
</div>
<div className="ballots-about-td">
<p>{this.miningKey}</p>
<p>{votingState.miningKey}</p>
</div>
</div>;
}
return (
<BallotCard votingType="votingToChangeKeys" votingState={votingState} id={id} isSearchPattern={this.isSearchPattern()}>
<BallotCard votingType="votingToChangeKeys" votingState={votingState} id={id}>
<div className="ballots-about-i ballots-about-i_action">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Action</p>
</div>
<div className="ballots-about-td">
<p>{this.ballotTypeDisplayName}</p>
<p>{votingState.ballotTypeDisplayName}</p>
</div>
</div>
<div className="ballots-about-i ballots-about-i_type">
@ -270,7 +47,7 @@ export class BallotKeysCard extends React.Component {
<p className="ballots-about-i--title">Key type</p>
</div>
<div className="ballots-about-td">
<p>{this.getAffectedKeyTypeDisplayName()}</p>
<p>{votingState.affectedKeyTypeDisplayName}</p>
</div>
</div>
<div className={`ballots-about-i ${affectedKeyClassName}`}>

View File

@ -1,53 +1,20 @@
import React from "react";
import { observable, action } from "mobx";
import { inject, observer } from "mobx-react";
import { BallotCard } from "./BallotCard";
@inject("commonStore", "contractsStore", "routing")
@inject("commonStore", "routing")
@observer
export class BallotMinThresholdCard extends React.Component {
@observable proposedValue;
@action("Get proposed value of min threshold ballot")
getProposedValue = async () => {
const { contractsStore, id } = this.props;
let proposedValue;
try {
proposedValue = await contractsStore.votingToChangeMinThreshold.getProposedValue(id);
} catch(e) {
console.log(e.message);
}
this.proposedValue = proposedValue;
}
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;
if (commonStore.searchTerm) {
const isProposedValuePattern = String(this.proposedValue).toLowerCase().includes(commonStore.searchTerm);
return (isProposedValuePattern);
}
return true;
}
render () {
let { id, votingState } = this.props;
return (
<BallotCard votingType="votingToChangeMinThreshold" votingState={votingState} id={id} isSearchPattern={this.isSearchPattern()}>
<BallotCard votingType="votingToChangeMinThreshold" votingState={votingState} id={id}>
<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>
</div>
<div className="ballots-about-td">
<p>{this.proposedValue}</p>
<p>{votingState.proposedValue}</p>
</div>
</div>
</BallotCard>

View File

@ -1,69 +1,20 @@
import React from "react";
import { observable, action } from "mobx";
import { inject, observer } from "mobx-react";
import { BallotCard } from "./BallotCard";
@inject("commonStore", "contractsStore", "ballotStore", "routing")
@inject("commonStore", "ballotStore", "routing")
@observer
export class BallotProxyCard extends React.Component {
@observable proposedAddress;
@observable contractType;
@action("Get proposed address of proxy ballot")
getProposedAddress = async () => {
const { contractsStore, id } = this.props;
let proposedAddress;
try {
proposedAddress = await contractsStore.votingToChangeProxy.getProposedValue(id);
} catch(e) {
console.log(e.message);
}
this.proposedAddress = proposedAddress;
}
@action("Get contract type of proxy ballot")
getContractType = async () => {
const { contractsStore, id } = this.props;
let contractType;
try {
contractType = await contractsStore.votingToChangeProxy.getContractType(id);
} catch(e) {
console.log(e.message);
}
this.contractType = contractType;
}
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;
if (commonStore.searchTerm) {
const isProposedAddressPattern = String(this.proposedAddress).toLowerCase().includes(commonStore.searchTerm);
const isContractTypePattern = String(this.contractType).toLowerCase().includes(commonStore.searchTerm);
return (isProposedAddressPattern || isContractTypePattern);
}
return true;
}
render () {
const { ballotStore, id, votingState } = this.props;
const { id, votingState } = this.props;
return (
<BallotCard votingType="votingToChangeProxy" votingState={votingState} id={id} isSearchPattern={this.isSearchPattern()}>
<BallotCard votingType="votingToChangeProxy" votingState={votingState} id={id}>
<div className="ballots-about-i ballots-about-i_contract-type">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Contract type</p>
</div>
<div className="ballots-about-td">
<p>{ballotStore.ProxyBallotType[this.contractType]}</p>
<p>{votingState.contractTypeDisplayName}</p>
</div>
</div>
<div className="ballots-about-i ballots-about-i_proposed-address">
@ -71,7 +22,7 @@ export class BallotProxyCard extends React.Component {
<p className="ballots-about-i--title">Proposed contract address</p>
</div>
<div className="ballots-about-td">
<p>{this.proposedAddress}</p>
<p>{votingState.proposedValue}</p>
</div>
</div>
</BallotCard>

View File

@ -3,7 +3,7 @@ import { observable } from "mobx";
import { inject, observer } from "mobx-react";
import "babel-polyfill";
@inject("commonStore", "ballotsStore")
@inject("commonStore", "ballotsStore", "ballotStore", "contractsStore")
@observer
export class Ballots extends React.Component {
@observable limit;
@ -21,6 +21,60 @@ export class Ballots extends React.Component {
commonStore.loadMoreLimit = this.limit;
}
filterBySearchTerm = (searchTerm, ballotCards) => {
const { ballotStore } = this.props;
searchTerm = searchTerm.toLowerCase();
for (let i = 0; i < ballotCards.length; i++) {
const votingState = ballotCards[i].props.votingState;
const contractType = ballotCards[i].props.type;
if (String(votingState.creator).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.creatorMiningKey).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.memo).toLowerCase().includes(searchTerm)) {
continue;
}
if (contractType === ballotStore.BallotType.keys) {
if (String(votingState.miningKey).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.affectedKey).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.newVotingKey).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.newPayoutKey).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.affectedKeyTypeDisplayName).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.ballotTypeDisplayName).toLowerCase().includes(searchTerm)) {
continue;
}
} else if (contractType === ballotStore.BallotType.minThreshold) {
if (String(votingState.proposedValue).toLowerCase().includes(searchTerm)) {
continue;
}
} else if (contractType === ballotStore.BallotType.proxy) {
if (String(votingState.proposedValue).toLowerCase().includes(searchTerm)) {
continue;
}
if (String(votingState.contractTypeDisplayName).toLowerCase().includes(searchTerm)) {
continue;
}
}
ballotCards.splice(i--, 1);
}
return ballotCards;
}
componentWillMount () {
const { commonStore } = this.props;
commonStore.isActiveFilter = this.props.isActiveFilter;
@ -30,8 +84,13 @@ export class Ballots extends React.Component {
render () {
const { ballotsStore, commonStore } = this.props;
let ballotCards = ballotsStore.ballotCards.toJS().sort((a, b) => {
return b.props.startTime - a.props.startTime;
})
return b.props.votingState.startTime - a.props.votingState.startTime;
});
if (commonStore.searchTerm) {
ballotCards = this.filterBySearchTerm(commonStore.searchTerm, ballotCards);
}
let loadMoreButton;
if (ballotCards.length > this.limit && !commonStore.isActiveFilter && !commonStore.isToFinalizeFilter) {
loadMoreButton = <div className="center">

View File

@ -37,6 +37,8 @@ export class Validator extends React.Component {
case "administrative_area_level_1":
address_components.administrative_area_level_1 = address_component.long_name;
break;
default:
break;
}
validatorStore.address = `${address_components.street_number} ${address_components.route} ${address_components.locality}`;
validatorStore.state = address_components.administrative_area_level_1;

View File

@ -48,14 +48,6 @@ export default class VotingToChangeKeys {
return this.votingToChangeKeysInstance && this.votingToChangeKeysInstance.methods[methodName];
}
getStartTime(_id) {
return this.votingToChangeKeysInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeKeysInstance.methods.getEndTime(_id).call();
}
nextBallotId() {
return this.votingToChangeKeysInstance.methods.nextBallotId().call();
}
@ -74,25 +66,6 @@ export default class VotingToChangeKeys {
return null;
}
getCreator(_id) {
if (this.doesMethodExist('getCreator')) {
return this.votingToChangeKeysInstance.methods.getCreator(_id).call();
}
return null;
}
getTotalVoters(_id) {
return this.votingToChangeKeysInstance.methods.getTotalVoters(_id).call();
}
getProgress(_id) {
return this.votingToChangeKeysInstance.methods.getProgress(_id).call();
}
getIsFinalized(_id) {
return this.votingToChangeKeysInstance.methods.getIsFinalized(_id).call();
}
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeKeysInstance.methods.hasAlreadyVoted(_id, votingKey).call();
}
@ -112,44 +85,10 @@ export default class VotingToChangeKeys {
return null;
}
getBallotType(_id) {
return this.votingToChangeKeysInstance.methods.getBallotType(_id).call();
}
getAffectedKeyType(_id) {
return this.votingToChangeKeysInstance.methods.getAffectedKeyType(_id).call();
}
getAffectedKey(_id) {
return this.votingToChangeKeysInstance.methods.getAffectedKey(_id).call();
}
getNewVotingKey(_id) {
if (this.doesMethodExist('getNewVotingKey')) {
return this.votingToChangeKeysInstance.methods.getNewVotingKey(_id).call();
}
return "";
}
getNewPayoutKey(_id) {
if (this.doesMethodExist('getNewPayoutKey')) {
return this.votingToChangeKeysInstance.methods.getNewPayoutKey(_id).call();
}
return "";
}
getMiningKey(_id) {
return this.votingToChangeKeysInstance.methods.getMiningKey(_id).call();
}
getMiningByVotingKey(_votingKey) {
return this.votingToChangeKeysInstance.methods.getMiningByVotingKey(_votingKey).call();
}
getMemo(_id) {
return this.votingToChangeKeysInstance.methods.getMemo(_id).call();
}
async getValidatorActiveBallots(_votingKey) {
let miningKey;
try {

View File

@ -43,14 +43,6 @@ export default class VotingToChangeMinThreshold {
return false;
}
getStartTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeMinThresholdInstance.methods.getEndTime(_id).call();
}
nextBallotId() {
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call();
}
@ -69,25 +61,6 @@ export default class VotingToChangeMinThreshold {
return null;
}
getCreator(_id) {
if (this.doesMethodExist('getCreator')) {
return this.votingToChangeMinThresholdInstance.methods.getCreator(_id).call();
}
return null;
}
getTotalVoters(_id) {
return this.votingToChangeMinThresholdInstance.methods.getTotalVoters(_id).call();
}
getProgress(_id) {
return this.votingToChangeMinThresholdInstance.methods.getProgress(_id).call();
}
getIsFinalized(_id) {
return this.votingToChangeMinThresholdInstance.methods.getIsFinalized(_id).call();
}
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeMinThresholdInstance.methods.hasAlreadyVoted(_id, votingKey).call();
}
@ -107,18 +80,10 @@ export default class VotingToChangeMinThreshold {
return null;
}
getProposedValue(_id) {
return this.votingToChangeMinThresholdInstance.methods.getProposedValue(_id).call();
}
getMiningByVotingKey(_votingKey) {
return this.votingToChangeMinThresholdInstance.methods.getMiningByVotingKey(_votingKey).call();
}
getMemo(_id) {
return this.votingToChangeMinThresholdInstance.methods.getMemo(_id).call();
}
async getValidatorActiveBallots(_votingKey) {
let miningKey;
try {

View File

@ -43,14 +43,6 @@ export default class VotingToChangeProxy {
return false;
}
getStartTime(_id) {
return this.votingToChangeProxyInstance.methods.getStartTime(_id).call();
}
getEndTime(_id) {
return this.votingToChangeProxyInstance.methods.getEndTime(_id).call();
}
nextBallotId() {
return this.votingToChangeProxyInstance.methods.nextBallotId().call();
}
@ -69,25 +61,6 @@ export default class VotingToChangeProxy {
return null;
}
getCreator(_id) {
if (this.doesMethodExist('getCreator')) {
return this.votingToChangeProxyInstance.methods.getCreator(_id).call();
}
return null;
}
getTotalVoters(_id) {
return this.votingToChangeProxyInstance.methods.getTotalVoters(_id).call();
}
getProgress(_id) {
return this.votingToChangeProxyInstance.methods.getProgress(_id).call();
}
getIsFinalized(_id) {
return this.votingToChangeProxyInstance.methods.getIsFinalized(_id).call();
}
hasAlreadyVoted(_id, votingKey) {
return this.votingToChangeProxyInstance.methods.hasAlreadyVoted(_id, votingKey).call();
}
@ -107,18 +80,6 @@ export default class VotingToChangeProxy {
return null;
}
getProposedValue(_id) {
return this.votingToChangeProxyInstance.methods.getProposedValue(_id).call();
}
getContractType(_id) {
return this.votingToChangeProxyInstance.methods.getContractType(_id).call();
}
getMemo(_id) {
return this.votingToChangeProxyInstance.methods.getMemo(_id).call();
}
getMiningByVotingKey(_votingKey) {
return this.votingToChangeProxyInstance.methods.getMiningByVotingKey(_votingKey).call();
}

View File

@ -44,7 +44,7 @@ class ContractsStore {
}
@computed get isValidVotingKey() {
if (this.miningKey != "0x0000000000000000000000000000000000000000") return true;
if (this.miningKey && this.miningKey !== "0x0000000000000000000000000000000000000000") return true;
return false
}
@ -177,30 +177,96 @@ class ContractsStore {
}
}
fillCardVotingState = (votingState, contractType) => {
const creatorLowerCase = votingState.creator.toLowerCase();
votingState.creatorMiningKey = votingState.creator;
if (this.validatorsMetadata.hasOwnProperty(creatorLowerCase)) {
const creatorFullName = this.validatorsMetadata[creatorLowerCase].fullName;
if (creatorFullName) {
votingState.creator = creatorFullName;
}
}
if (contractType === "votingToChangeKeys") {
votingState.isAddMining = false;
switch (Number(votingState.ballotType)) {
case ballotStore.KeysBallotType.add:
votingState.ballotTypeDisplayName = "add";
if (Number(votingState.affectedKeyType) === ballotStore.KeyType.mining) {
votingState.isAddMining = true;
}
break;
case ballotStore.KeysBallotType.remove:
votingState.ballotTypeDisplayName = "remove";
break;
case ballotStore.KeysBallotType.swap:
votingState.ballotTypeDisplayName = "swap";
break;
default:
votingState.ballotTypeDisplayName = "";
break;
}
if (!votingState.hasOwnProperty('newVotingKey')) {
votingState.newVotingKey = "";
}
if (votingState.newVotingKey === "0x0000000000000000000000000000000000000000") {
votingState.newVotingKey = "";
}
if (!votingState.hasOwnProperty('newPayoutKey')) {
votingState.newPayoutKey = "";
}
if (votingState.newPayoutKey === "0x0000000000000000000000000000000000000000") {
votingState.newPayoutKey = "";
}
switch(Number(votingState.affectedKeyType)) {
case ballotStore.KeyType.mining:
votingState.affectedKeyTypeDisplayName = "mining";
break;
case ballotStore.KeyType.voting:
votingState.affectedKeyTypeDisplayName = "voting";
break;
case ballotStore.KeyType.payout:
votingState.affectedKeyTypeDisplayName = "payout";
break;
default:
votingState.affectedKeyTypeDisplayName = "";
break;
}
if (votingState.isAddMining) {
if (votingState.newVotingKey) votingState.affectedKeyTypeDisplayName += ', voting';
if (votingState.newPayoutKey) votingState.affectedKeyTypeDisplayName += ', payout';
}
if (votingState.miningKey && votingState.miningKey !== '0x0000000000000000000000000000000000000000') {
const miningKeyLowerCase = votingState.miningKey.toLowerCase();
if (this.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
votingState.miningKey = this.validatorsMetadata[miningKeyLowerCase].lastNameAndKey;
}
}
} else if (contractType === "votingToChangeProxy") {
votingState.contractTypeDisplayName = ballotStore.ProxyBallotType[votingState.contractType];
}
return votingState;
}
getCards = async (nextBallotId, contractType) => {
for (let id = nextBallotId - 1; id >= 0; id--) {
let startTime = 0;
let votingState;
try {
votingState = await this[contractType].getBallotInfo(id, this.votingKey);
if (!votingState) {
votingState = await this[contractType].votingState(id);
}
votingState = this.fillCardVotingState(votingState, contractType);
} 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":
@ -208,24 +274,23 @@ class ContractsStore {
id={id}
type={ballotStore.BallotType.keys}
key={ballotsStore.ballotCards.length}
votingState={votingState}
startTime={startTime}/>
votingState={votingState}/>
break;
case "votingToChangeMinThreshold":
card = <BallotMinThresholdCard
id={id}
type={ballotStore.BallotType.minThreshold}
key={ballotsStore.ballotCards.length}
votingState={votingState}
startTime={startTime}/>
votingState={votingState}/>
break;
case "votingToChangeProxy":
card = <BallotProxyCard
id={id}
type={ballotStore.BallotType.proxy}
key={ballotsStore.ballotCards.length}
votingState={votingState}
startTime={startTime}/>
votingState={votingState}/>
break;
default:
break;
}