@@ -34,11 +34,10 @@ const handlePortfolioData = (portfolio_arr) => {
34
34
} ;
35
35
/* TODO:
36
36
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
42
41
*/
43
42
class Portfolio extends React . PureComponent {
44
43
constructor ( props ) {
@@ -101,9 +100,9 @@ class Portfolio extends React.PureComponent {
101
100
this . state = {
102
101
columns,
103
102
currency,
104
- data_source : [ ] ,
105
- error : '' ,
106
- has_no_contract : false ,
103
+ data_source : [ ] ,
104
+ error : '' ,
105
+ is_loading : true ,
107
106
} ;
108
107
}
109
108
@@ -127,7 +126,9 @@ class Portfolio extends React.PureComponent {
127
126
}
128
127
129
128
transactionResponseHandler ( response ) {
130
- // handle error
129
+ if ( getPropertyValue ( response , 'error' ) ) {
130
+ this . setState ( { error : response . error . message } ) ;
131
+ }
131
132
if ( response . transaction . action === 'buy' ) {
132
133
BinarySocket . send ( { portfolio : 1 } ) . then ( ( res ) => {
133
134
this . updatePortfolio ( res ) ;
@@ -138,7 +139,9 @@ class Portfolio extends React.PureComponent {
138
139
}
139
140
140
141
updateIndicative ( response ) {
141
- // handle error here
142
+ if ( getPropertyValue ( response , 'error' ) ) {
143
+ return ;
144
+ }
142
145
let data_source = this . state . data_source . slice ( ) ;
143
146
const proposal = response . proposal_open_contract ;
144
147
// force to sell the expired contract, in order to remove from portfolio
@@ -165,41 +168,43 @@ class Portfolio extends React.PureComponent {
165
168
}
166
169
167
170
updateOAuthApps = ( response ) => {
168
- console . log ( response ) ;
169
171
const oauth_apps = buildOauthApps ( response ) ;
170
172
console . log ( 'oauth_apps: ' , oauth_apps ) ;
171
173
// GetAppDetails.addTooltip(oauth_apps);
172
174
} ;
173
175
174
176
updatePortfolio ( response ) {
177
+ this . setState ( { is_loading : false } ) ;
175
178
if ( getPropertyValue ( response , 'error' ) ) {
176
- console . log ( 'error: ' , response ) ;
177
179
this . setState ( { error : response . error . message } ) ;
178
180
return ;
179
181
}
180
- if ( response . portfolio . contracts && response . portfolio . contracts . length > 0 ) {
182
+ if ( response . portfolio . contracts && response . portfolio . contracts . length !== 0 ) {
181
183
const data_source = handlePortfolioData ( response . portfolio . contracts ) ;
182
184
183
185
this . setState ( { data_source } ) ;
184
186
BinarySocket . send (
185
187
{ proposal_open_contract : 1 , subscribe : 1 } ,
186
188
{ callback : this . updateIndicative }
187
189
) ;
188
- } else {
189
- // empty portfolio
190
190
}
191
191
}
192
192
193
193
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
+ }
194
200
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 >
203
208
) ;
204
209
}
205
210
} ;
0 commit comments