diff --git a/src/components/BallotCard.jsx b/src/components/BallotCard.jsx index 4c7b70a..fd0691b 100644 --- a/src/components/BallotCard.jsx +++ b/src/components/BallotCard.jsx @@ -1,6 +1,6 @@ import React from 'react'; import moment from 'moment'; -import { observable, action, computed, autorun } from "mobx"; +import { observable, action, computed } from "mobx"; import { inject, observer } from "mobx-react"; import { toAscii } from "../helpers"; import { constants } from "../constants"; @@ -18,7 +18,6 @@ export class BallotCard extends React.Component { @observable progress; @observable totalVoters; @observable isFinalized; - @observable isFiltered; @computed get votesForNumber() { let votes = (this.totalVoters + this.progress) / 2; @@ -197,22 +196,36 @@ export class BallotCard extends React.Component { this.getIsFinalized(); } - hideCard = () => { - let { commonStore } = this.props; - let hideCard = commonStore.isActiveFilter && this.isFinalized; - if (commonStore.searchTerm) { - if (commonStore.searchTerm.length == 0) return hideCard; - if (String(this.creator).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - } else { - return hideCard; - } + componentDidMount() { + this.interval = setInterval(() => { + this.calcTimeToFinish() + }, 1000) + } + componentWillUnmount() { + window.clearInterval(this.interval); + } + + showCard = () => { + let { commonStore } = this.props; + let show = commonStore.isActiveFilter ? !this.isFinalized : true; + return show; + } + + isCreatorPattern = () => { + let { commonStore } = this.props; + if (commonStore.searchTerm) { + if (commonStore.searchTerm.length > 0) { + const isCreatorPattern = String(this.creator).toLowerCase().includes(commonStore.searchTerm) + return isCreatorPattern; + } + } return true; } render () { - let { contractsStore, ballotStore, votingType, children } = this.props; - let ballotClass = this.hideCard() ? "ballots-i display-none" : "ballots-i"; + let { contractsStore, votingType, children, isSearchPattern } = this.props; + let ballotClass = (this.showCard() && (this.isCreatorPattern() || isSearchPattern)) ? "ballots-i" : "ballots-i display-none"; let threshold switch(votingType) { case "votingToChangeKeys": @@ -224,6 +237,9 @@ export class BallotCard extends React.Component { case "votingToChangeProxy": threshold = contractsStore.proxyBallotThreshold break; + default: + threshold = contractsStore.keysBallotThreshold + break; } return (
diff --git a/src/components/BallotKeysCard.jsx b/src/components/BallotKeysCard.jsx index 26098e5..af9e8be 100644 --- a/src/components/BallotKeysCard.jsx +++ b/src/components/BallotKeysCard.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { observable, action, computed, autorun } from "mobx"; +import { observable, action } from "mobx"; import { inject, observer } from "mobx-react"; import { BallotCard } from './BallotCard'; @@ -81,36 +81,21 @@ export class BallotKeysCard extends React.Component { this.getBallotType(); } - componentDidMount() { - this.interval = setInterval(() => { - this.calcTimeToFinish() - }, 1000) - } - - componentWillUnmount() { - window.clearInterval(this.interval); - } - - hideCard = () => { + isSearchPattern = () => { let { commonStore } = this.props; - let hideCard = commonStore.isActiveFilter && this.isFinalized; if (commonStore.searchTerm) { - if (commonStore.searchTerm.length == 0) return hideCard; - if (String(this.affectedKey).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - if (String(this.affectedKeyTypeDisplayName).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - if (String(this.ballotTypeDisplayName).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - } else { - return hideCard; + const isAffectedKeyPattern = String(this.affectedKey).toLowerCase().includes(commonStore.searchTerm) + const isAffectedKeyTypeDisplayNamePattern = String(this.affectedKeyTypeDisplayName).toLowerCase().includes(commonStore.searchTerm) + const isBallotTypeDisplayNamePattern = String(this.ballotTypeDisplayName).toLowerCase().includes(commonStore.searchTerm) + return (isAffectedKeyPattern || isAffectedKeyTypeDisplayNamePattern || isBallotTypeDisplayNamePattern); } - return true; } render () { - let { contractsStore, id } = this.props; - let ballotClass = this.hideCard() ? "ballots-i display-none" : "ballots-i"; + let { id } = this.props; return ( - +

Action

diff --git a/src/components/BallotMinThresholdCard.jsx b/src/components/BallotMinThresholdCard.jsx index d658e30..ec2029e 100644 --- a/src/components/BallotMinThresholdCard.jsx +++ b/src/components/BallotMinThresholdCard.jsx @@ -1,14 +1,8 @@ import React from 'react'; -import moment from 'moment'; -import { observable, action, computed } from "mobx"; +import { observable, action } from "mobx"; import { inject, observer } from "mobx-react"; -import { toAscii } from "../helpers"; -import { constants } from "../constants"; -import swal from 'sweetalert2'; import { BallotCard } from './BallotCard'; -const ACCEPT = 1; -const REJECT = 2; @inject("commonStore", "contractsStore", "routing") @observer export class BallotMinThresholdCard extends React.Component { @@ -26,25 +20,19 @@ export class BallotMinThresholdCard extends React.Component { this.getProposedValue(this.props.id); } - hideCard = () => { + isSearchPattern = () => { let { commonStore } = this.props; - let hideCard = commonStore.isActiveFilter && this.isFinalized; if (commonStore.searchTerm) { - if (commonStore.searchTerm.length == 0) return hideCard; - if (String(this.proposedValue).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - if (String(this.creator).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - } else { - return hideCard; + const isProposedValuePattern = String(this.proposedValue).toLowerCase().includes(commonStore.searchTerm) + return (isProposedValuePattern); } - return true; } render () { - let { contractsStore, id } = this.props; - let ballotClass = this.hideCard() ? "ballots-i display-none" : "ballots-i"; + let { id } = this.props; return ( - +

Proposed min threshold

@@ -54,71 +42,6 @@ export class BallotMinThresholdCard extends React.Component {
- /*
-
-
-
-

Name

-
-
-

{this.creator}

-

{this.startTime}

-
-
-
-
-

Proposed min threshold

-
-
-

{this.proposedValue}

-
-
-
-
-

Time

-
-
-

{this.timeToFinish}

-

To close

-
-
-
-
-
- -
-

No

-

Votes: {this.votesAgainstNumber}

-

{this.votesAgainstPercents}%

-
-
-
-
-
-
-
-

Yes

-

Votes: {this.votesForNumber}

-

{this.votesForPercents}%

-
-
-
-
- -
-
-
- Minimum {contractsStore.minThresholdBallotThreshold} from {contractsStore.validatorsLength} validators is required to pass the proposal -
-
-
-
- -

{constants.CARD_FINALIZE_DESCRIPTION}

-
-
Consensus Ballot ID: {this.props.id}
-
-
*/ ); } } diff --git a/src/components/BallotProxyCard.jsx b/src/components/BallotProxyCard.jsx index 2c70137..835148e 100644 --- a/src/components/BallotProxyCard.jsx +++ b/src/components/BallotProxyCard.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { observable, action, computed } from "mobx"; +import { observable, action } from "mobx"; import { inject, observer } from "mobx-react"; import { BallotCard } from './BallotCard'; @@ -29,25 +29,20 @@ export class BallotProxyCard extends React.Component { this.getContractType(); } - hideCard = () => { + isSearchPattern = () => { let { commonStore } = this.props; - let hideCard = commonStore.isActiveFilter && this.isFinalized; if (commonStore.searchTerm) { - if (commonStore.searchTerm.length == 0) return hideCard; - if (String(this.proposedAddress).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - if (String(this.contractType).toLowerCase().includes(commonStore.searchTerm)) return (hideCard && false); - } else { - return hideCard; + 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 { contractsStore, ballotStore, id } = this.props; - let ballotClass = this.hideCard() ? "ballots-i display-none" : "ballots-i"; + const { ballotStore, id } = this.props; return ( - +

Contract type

@@ -66,78 +61,5 @@ export class BallotProxyCard extends React.Component {
); - /*
-
-
-
-

Name

-
-
-

{this.creator}

-

{this.startTime}

-
-
-
-
-

Contract type

-
-
-

{ballotStore.ProxyBallotType[this.contractType]}

-
-
-
-
-

Proposed contract address

-
-
-

{this.proposedAddress}

-
-
-
-
-

Time

-
-
-

{this.timeToFinish}

-

To close

-
-
-
-
-
- -
-

No

-

Votes: {this.votesAgainstNumber}

-

{this.votesAgainstPercents}%

-
-
-
-
-
-
-
-

Yes

-

Votes: {this.votesForNumber}

-

{this.votesForPercents}%

-
-
-
-
- -
-
-
- Minimum {contractsStore.proxyBallotThreshold} from {contractsStore.validatorsLength} validators is required to pass the proposal -
-
-
-
- -

{constants.CARD_FINALIZE_DESCRIPTION}

-
-
Proxy Ballot ID: {this.props.id}
-
-
*/ } }