From 0a7d0dd5a4998294d10d159e72a90d20aec435ae Mon Sep 17 00:00:00 2001 From: lanhaoxiang Date: Fri, 15 May 2020 16:35:24 +0800 Subject: [PATCH] fix: fix account subscribe limit error when loading trust nodes --- .eslintrc | 52 ++-- .vscode/settings.json | 2 + app/components/Account/AccountsList.jsx | 365 ++++++++++++++---------- package.json | 3 +- 4 files changed, 240 insertions(+), 182 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.eslintrc b/.eslintrc index 5ec2210..5fa169e 100755 --- a/.eslintrc +++ b/.eslintrc @@ -1,30 +1,28 @@ { - "plugins": [ - "react", "json" - ], - "extends": ["plugin:react/recommended"], - "parser": "babel-eslint", - "env": { - "browser": true, - "node": true, - "es6": true - }, - "parserOptions": { - "ecmaFeatures": { - "blockBindings": true, - "forOf": true, - "jsx": true - } - }, - "rules": { - "no-unused-vars": ["error", { "vars": "all", "args": "after-used" }], - "comma-dangle": 0, - "indent": ["error", 4, {SwitchCase: 1}], - "quotes": [2, "double", "avoid-escape"], - "semi": [2, "always"], - "camelcase": [0], - "no-console": [0], - "object-curly-spacing": [0], - "react/prop-types": [0] + "plugins": ["react", "json"], + "extends": ["plugin:react/recommended"], + "parser": "babel-eslint", + "env": { + "browser": true, + "node": true, + "es6": true + }, + "parserOptions": { + "ecmaFeatures": { + "blockBindings": true, + "forOf": true, + "jsx": true } + }, + "rules": { + "no-unused-vars": ["error", { "vars": "all", "args": "after-used" }], + "comma-dangle": 0, + "indent": ["error", 4, { "SwitchCase": 1 }], + "quotes": [2, "double", "avoid-escape"], + "semi": [2, "always"], + "camelcase": [0], + "no-console": [0], + "object-curly-spacing": [0], + "react/prop-types": [0] + } } diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/app/components/Account/AccountsList.jsx b/app/components/Account/AccountsList.jsx index 48585a0..cdf7ead 100755 --- a/app/components/Account/AccountsList.jsx +++ b/app/components/Account/AccountsList.jsx @@ -2,16 +2,19 @@ import React from "react"; import AccountSelector from "./AccountSelector"; import Translate from "react-translate-component"; import AccountImage from "./AccountImage"; -import {ChainStore} from "gxbjs/es"; +import { ChainStore } from "gxbjs/es"; import ChainTypes from "../Utility/ChainTypes"; import FormattedAsset from "../Utility/FormattedAsset"; import BindToChainState from "../Utility/BindToChainState"; -import LinkToAccountById from "../Blockchain/LinkToAccountById"; import counterpart from "counterpart"; import { Link } from "react-router/es"; function getWitnessOrCommittee(type, acct) { - let url = "", votes = 0, account, commission_rate = 0, new_votes = 0; + let url = "", + votes = 0, + account, + commission_rate = 0, + new_votes = 0; if (type === "witness") { account = ChainStore.getWitnessById(acct.get("id")); } else if (type === "committee") { @@ -20,12 +23,14 @@ function getWitnessOrCommittee(type, acct) { url = account ? account.get("url") : url; votes = account ? account.get("total_votes") : votes; new_votes = account ? account.get("total_vote_weights") : new_votes; - commission_rate = account ? account.get("commission_rate") / 10 : commission_rate; + commission_rate = account + ? account.get("commission_rate") / 10 + : commission_rate; return { url, votes, commission_rate, - new_votes + new_votes, }; } @@ -33,11 +38,14 @@ class AccountItemRow extends React.Component { static propTypes = { account: React.PropTypes.object.isRequired, onAction: React.PropTypes.func.isRequired, - showNewVotes: React.PropTypes.bool.isRequired + showNewVotes: React.PropTypes.bool.isRequired, }; shouldComponentUpdate(nextProps) { - return nextProps.account !== this.props.account || nextProps.showNewVotes !== this.props.showNewVotes; + return ( + nextProps.account !== this.props.account || + nextProps.showNewVotes !== this.props.showNewVotes + ); } onAction(item_id) { @@ -45,37 +53,62 @@ class AccountItemRow extends React.Component { } render() { - let {account, type} = this.props; + let { account, type } = this.props; let name = account.get("name"); let item_id = account.get("id"); - let { url, votes, commission_rate, new_votes} = getWitnessOrCommittee(type, account); - let link = url && url.length > 0 && url.indexOf("http") === -1 ? "http://" + url : url; + let { url, votes, commission_rate, new_votes } = getWitnessOrCommittee( + type, + account + ); + let link = + url && url.length > 0 && url.indexOf("http") === -1 + ? "http://" + url + : url; return ( - - - - - - {url.length < 45 ? url : url.substr(0, 45) + "..."} - {commission_rate}% - -
- -
- - - - - - ); + + + + + + + {name} + + + + + {url.length < 45 ? url : url.substr(0, 45) + "..."} + + + {commission_rate}% + +
+ +
+ + + + + + ); } } class AccountsList extends React.Component { - static propTypes = { items: ChainTypes.ChainObjectsList, onStakingCreate: React.PropTypes.func.isRequired, @@ -89,7 +122,7 @@ class AccountsList extends React.Component { static defaultProps = { action: "remove", - withSelector: true + withSelector: true, }; constructor(props) { @@ -98,156 +131,180 @@ class AccountsList extends React.Component { selected_item: null, item_name_input: "", error: null, - showNewVotes: true + showNewVotes: true, }; this.onItemChange = this.onItemChange.bind(this); this.onItemAccountChange = this.onItemAccountChange.bind(this); } onItemChange(item_name_input) { - this.setState({item_name_input}); + this.setState({ item_name_input }); } onItemAccountChange(selected_item) { - this.setState({selected_item, error: null}); + this.setState({ selected_item, error: null }); if (selected_item && this.props.validateAccount) { let res = this.props.validateAccount(selected_item); if (res === null) return; - if (typeof(res) === "string") this.setState({error: res}); - else res.then(error => this.setState({error: error})); + if (typeof res === "string") this.setState({ error: res }); + else res.then((error) => this.setState({ error: error })); } } render() { if (!this.props.items) return null; - let item_rows = this.props.items.filter(i => { - if (!i) return false; - let nodes = [ - "aaron", - "caitlin", - "kairos", - "sakura", - "taffy", - "miner1", - "miner2", - "miner3", - "miner4", - "miner5", - "miner6", - "miner7", - "miner8", - "miner9", - "miner10", - "miner11", - "hrrs", - "dennis1", - "david12", - "marks-lee", - "robin-green" - ]; - let tmp = false; - for (let k = 0; k < nodes.length; k++) { - if (i.get("name") === nodes[k]) { - tmp = true; - break; - } - } - return !tmp; - }) - .sort((a, b) => { - // let {votes: a_votes} = getWitnessOrCommittee(this.props.type, a); - // let {votes: b_votes} = getWitnessOrCommittee(this.props.type, b); - - // if (a_votes !== b_votes) { - // return b_votes - a_votes; - // } - // else if (a.get("name") > b.get("name")) { - // return 1; - // } - // else if (a.get("name") < b.get("name")) { - // return -1; - // } else { - // return 0; - // } - let { - commission_rate: a_commission_rate, - new_votes: a_new_votes - } = getWitnessOrCommittee(this.props.type, a); - let { - commission_rate: b_commission_rate, - new_votes: b_new_votes - } = getWitnessOrCommittee(this.props.type, b); - - if (a_commission_rate === b_commission_rate) { - return a_new_votes - b_new_votes; - } else { - return b_commission_rate - a_commission_rate; - } - }) - .map(i => { - return ( - - ); - }); + let item_rows = this.props.items + .filter((i) => { + if (!i) return false; + let nodes = [ + "aaron", + "caitlin", + "kairos", + "sakura", + "taffy", + "miner1", + "miner2", + "miner3", + "miner4", + "miner5", + "miner6", + "miner7", + "miner8", + "miner9", + "miner10", + "miner11", + "hrrs", + "dennis1", + "david12", + "marks-lee", + "robin-green", + ]; + let tmp = false; + for (let k = 0; k < nodes.length; k++) { + if (i.get("name") === nodes[k]) { + tmp = true; + break; + } + } + return !tmp; + }) + .sort((a, b) => { + // let {votes: a_votes} = getWitnessOrCommittee(this.props.type, a); + // let {votes: b_votes} = getWitnessOrCommittee(this.props.type, b); + + // if (a_votes !== b_votes) { + // return b_votes - a_votes; + // } + // else if (a.get("name") > b.get("name")) { + // return 1; + // } + // else if (a.get("name") < b.get("name")) { + // return -1; + // } else { + // return 0; + // } + let { + commission_rate: a_commission_rate, + new_votes: a_new_votes, + } = getWitnessOrCommittee(this.props.type, a); + let { + commission_rate: b_commission_rate, + new_votes: b_new_votes, + } = getWitnessOrCommittee(this.props.type, b); + + if (a_commission_rate === b_commission_rate) { + return a_new_votes - b_new_votes; + } else { + return b_commission_rate - a_commission_rate; + } + }) + .map((i) => { + return ( + + ); + }); let error = this.state.error; - if (!error && this.state.selected_item && this.props.items.indexOf(this.state.selected_item) !== -1) { + if ( + !error && + this.state.selected_item && + this.props.items.indexOf(this.state.selected_item) !== -1 + ) { error = counterpart.translate("account.votes.already"); } let cw = ["10%", "20%", "20%", "15%", "25%", "10%"]; return ( -
- {this.props.withSelector ? - : null} - {this.props.title && item_rows.length ?

{this.props.title}

: null} - {item_rows.length ? ( - - - - - - - - - - - - - {item_rows} - -
- - { this.setState({ showNewVotes: !this.state.showNewVotes }); }}> - ({this.state.showNewVotes ? : }) - -
) : null} -
- ); +
+ {this.props.withSelector ? ( + + ) : null} + {this.props.title && item_rows.length ? ( +

{this.props.title}

+ ) : null} + {item_rows.length ? ( + + + + + + + + + + + + {item_rows} +
+ + + + + + + + { + this.setState({ showNewVotes: !this.state.showNewVotes }); + }} + > + ( + {this.state.showNewVotes ? ( + + ) : ( + + )} + ) + + + +
+ ) : null} +
+ ); } - } -export default BindToChainState(AccountsList, {keep_updating: true}); +export default BindToChainState(AccountsList, { keep_updating: true }); diff --git a/package.json b/package.json index 3d53107..5eee8dd 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gxb-light", - "version": "1.4.0", + "version": "1.4.1", "description": "Advanced wallet interface for the GXChain.", "homepage": "https://github.com/gxchain/gxchain-light", "contributors": [ @@ -173,6 +173,7 @@ }, "mac": { "icon": "resources/icons/icon.icns", + "identity": "Apple Development: Minqiang Huang (X65PTKT3H4)", "category": "public.app-category.utilities" }, "win": {