Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2132 - Fetch Balance object on sorting accounts (Explorer Page) #2518

Merged
merged 5 commits into from
Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions app/components/Explorer/Accounts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Accounts extends React.Component {

this._searchAccounts = debounce(this._searchAccounts, 200);
this.handleRowsChange = this.handleRowsChange.bind(this);

this.balanceObjects = [];
}

shouldComponentUpdate(nextProps, nextState) {
Expand Down Expand Up @@ -73,6 +75,19 @@ class Accounts extends React.Component {
this.forceUpdate();
}

_ensureBalanceObject(object_id) {
if (object_id && typeof object_id === "string") {
if (!this.balanceObjects[object_id]) {
this.balanceObjects[object_id] = parseFloat(
ChainStore.getObject(object_id).get("balance")
);
}
}
if (!this.balanceObjects[object_id]) {
this.balanceObjects[object_id] = 0;
}
}

render() {
let {searchAccounts} = this.props;
let {searchTerm} = this.state;
Expand Down Expand Up @@ -155,11 +170,14 @@ class Accounts extends React.Component {
dataIndex: "accountBalance",
key: "accountBalance",
sorter: (a, b) => {
a.accountBalance = parseFloat(a.accountBalance);
b.accountBalance = parseFloat(b.accountBalance);
return a.accountBalance > b.accountBalance
this._ensureBalanceObject(a.accountBalance);
this._ensureBalanceObject(b.accountBalance);

return this.balanceObjects[a.accountBalance] >
this.balanceObjects[b.accountBalance]
? 1
: a.accountBalance < b.accountBalance
: this.balanceObjects[a.accountBalance] <
this.balanceObjects[b.accountBalance]
? -1
: 0;
},
Expand All @@ -177,14 +195,17 @@ class Accounts extends React.Component {
},
{
title: <Translate component="span" content="account.percent" />,
dataIndex: "accountPercentages",
key: "accountPercentages",
dataIndex: "accountBalance",
startailcoon marked this conversation as resolved.
Show resolved Hide resolved
key: "accountBalancePercentage",
sorter: (a, b) => {
a.accountPercentages = parseFloat(a.accountPercentages);
b.accountPercentages = parseFloat(b.accountPercentages);
return a.accountPercentages > b.accountPercentages
this._ensureBalanceObject(a.accountBalance);
this._ensureBalanceObject(b.accountBalance);

return this.balanceObjects[a.accountBalance] >
this.balanceObjects[b.accountBalance]
? 1
: a.accountPercentages < b.accountPercentages
: this.balanceObjects[a.accountBalance] <
this.balanceObjects[b.accountBalance]
? -1
: 0;
},
Expand Down Expand Up @@ -241,8 +262,7 @@ class Accounts extends React.Component {
accountContacts: AccountStore.getState()
.accountContacts,
accountName: name,
accountBalance: balance,
accountPercentages: balance
accountBalance: balance
});
});
}
Expand Down Expand Up @@ -296,7 +316,8 @@ class Accounts extends React.Component {
marginLeft: "24px"
}}
>
{this.state.searchTerm.length == 0 ? (
{this.state.searchTerm &&
this.state.searchTerm.length == 0 ? (
<Translate content="account.start_typing_to_search" />
) : null}
</div>
Expand Down