@@ -278,6 +278,7 @@ function BuyOrder(
278
278
const { exit } = useApp ( ) ;
279
279
const [ order , setOrder ] = useState < Order | null > ( null ) ;
280
280
const intervalRef = useRef < ReturnType < typeof setInterval > | null > ( null ) ;
281
+ const [ loadingMsg , setLoadingMsg ] = useState < string | null > ( "Placing order..." ) ;
281
282
282
283
async function submitOrder ( ) {
283
284
const endsAt = roundEndDate ( props . endsAt ) ;
@@ -302,7 +303,6 @@ function BuyOrder(
302
303
} ) ;
303
304
setOrder ( order ) ;
304
305
}
305
-
306
306
const handleSubmit = useCallback ( ( submitValue : boolean ) => {
307
307
if ( submitValue === false ) {
308
308
setIsLoading ( false ) ;
@@ -311,7 +311,7 @@ function BuyOrder(
311
311
}
312
312
313
313
submitOrder ( ) ;
314
- } , [ exit ] ) ;
314
+ } , [ exit , setIsLoading ] ) ;
315
315
316
316
useEffect ( ( ) => {
317
317
if ( isLoading && intervalRef . current == null ) {
@@ -321,15 +321,23 @@ function BuyOrder(
321
321
}
322
322
323
323
const o = await getOrder ( order . id ) ;
324
+ if ( ! o ) {
325
+ setLoadingMsg ( "Can't find order. This could be a network issue, try ctrl-c and running 'sf orders ls' to see if it was placed." ) ;
326
+ return
327
+ }
328
+ if ( o . status === "pending" ) {
329
+ setLoadingMsg ( "Pending..." ) ;
330
+ return
331
+ }
324
332
setOrder ( o ) ;
325
333
326
- if ( o && o . status !== "pending" ) {
327
- if ( intervalRef . current ) {
328
- clearInterval ( intervalRef . current ) ;
329
- intervalRef . current = null ;
330
- }
331
- exit ( ) ;
334
+ if ( intervalRef . current ) {
335
+ clearInterval ( intervalRef . current ) ;
336
+ intervalRef . current = null ;
332
337
}
338
+ exit ( ) ;
339
+ return
340
+
333
341
} , 200 ) ;
334
342
}
335
343
@@ -339,7 +347,7 @@ function BuyOrder(
339
347
intervalRef . current = null ;
340
348
}
341
349
} ;
342
- } , [ isLoading , order ] ) ;
350
+ } , [ isLoading , order , exit , setOrder ] ) ;
343
351
344
352
return (
345
353
< Box gap = { 1 } flexDirection = "column" >
@@ -362,7 +370,7 @@ function BuyOrder(
362
370
< Box gap = { 1 } >
363
371
{ ( ! order || order . status === "pending" ) && < Spinner type = "dots" /> }
364
372
{ order && order . status === "open" && < Text color = { "yellow" } > •</ Text > }
365
- { ! order && < Text > Placing order... </ Text > }
373
+ { ! order && < Text > { loadingMsg } </ Text > }
366
374
{ order && (
367
375
< Box gap = { 1 } >
368
376
< Text > Order placed: { order . id } </ Text >
0 commit comments