Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 4d8d411

Browse files
committed
handle empty portfolio
1 parent b2f6c54 commit 4d8d411

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/javascript/app_2/pages/portfolio/portfolio.jsx

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ const handlePortfolioData = (portfolio_arr) => {
3434
};
3535
/* TODO:
3636
1. Move socket connections to DAO
37-
2. Handle errors
38-
3. Handle empty portfolio
39-
5. Selling both in transactionHandler and updateIndicative?
40-
6. Make tooltip appdetails tooltip
41-
7. Add styling
37+
2. Selling both in transactionHandler and updateIndicative?
38+
3. Make tooltip appdetails tooltip
39+
4. Add styling
40+
5. Translations
4241
*/
4342
class Portfolio extends React.PureComponent {
4443
constructor(props) {
@@ -101,9 +100,9 @@ class Portfolio extends React.PureComponent {
101100
this.state = {
102101
columns,
103102
currency,
104-
data_source : [],
105-
error : '',
106-
has_no_contract: false,
103+
data_source: [],
104+
error : '',
105+
is_loading : true,
107106
};
108107
}
109108

@@ -127,7 +126,9 @@ class Portfolio extends React.PureComponent {
127126
}
128127

129128
transactionResponseHandler(response) {
130-
// handle error
129+
if (getPropertyValue(response, 'error')) {
130+
this.setState({ error: response.error.message });
131+
}
131132
if (response.transaction.action === 'buy') {
132133
BinarySocket.send({ portfolio: 1 }).then((res) => {
133134
this.updatePortfolio(res);
@@ -138,7 +139,9 @@ class Portfolio extends React.PureComponent {
138139
}
139140

140141
updateIndicative(response) {
141-
// handle error here
142+
if (getPropertyValue(response, 'error')) {
143+
return;
144+
}
142145
let data_source = this.state.data_source.slice();
143146
const proposal = response.proposal_open_contract;
144147
// force to sell the expired contract, in order to remove from portfolio
@@ -165,41 +168,43 @@ class Portfolio extends React.PureComponent {
165168
}
166169

167170
updateOAuthApps = (response) => {
168-
console.log(response);
169171
const oauth_apps = buildOauthApps(response);
170172
console.log('oauth_apps: ', oauth_apps);
171173
// GetAppDetails.addTooltip(oauth_apps);
172174
};
173175

174176
updatePortfolio(response) {
177+
this.setState({ is_loading: false });
175178
if (getPropertyValue(response, 'error')) {
176-
console.log('error: ', response);
177179
this.setState({ error: response.error.message });
178180
return;
179181
}
180-
if (response.portfolio.contracts && response.portfolio.contracts.length > 0) {
182+
if (response.portfolio.contracts && response.portfolio.contracts.length !== 0) {
181183
const data_source = handlePortfolioData(response.portfolio.contracts);
182184

183185
this.setState({ data_source });
184186
BinarySocket.send(
185187
{ proposal_open_contract: 1, subscribe: 1 },
186188
{ callback: this.updateIndicative }
187189
);
188-
} else {
189-
// empty portfolio
190190
}
191191
}
192192

193193
render() {
194+
if (this.state.is_loading) {
195+
return <div>Loading...</div>;
196+
}
197+
if (this.state.error) {
198+
return <div>{this.state.error}</div>;
199+
}
194200
return (
195-
<div>
196-
{this.state.error && <div>{this.state.error}</div>}
197-
<DataTable
198-
{...this.props}
199-
data_source={this.state.data_source}
200-
columns={this.state.columns}
201-
/>
202-
</div>
201+
this.state.data_source.length > 0 ?
202+
<DataTable
203+
{...this.props}
204+
data_source={this.state.data_source}
205+
columns={this.state.columns}
206+
/>
207+
: <div>No open positions.</div>
203208
);
204209
}
205210
};

0 commit comments

Comments
 (0)