@@ -278,6 +278,7 @@ function BuyOrder(
278278 const { exit } = useApp ( ) ;
279279 const [ order , setOrder ] = useState < Order | null > ( null ) ;
280280 const intervalRef = useRef < ReturnType < typeof setInterval > | null > ( null ) ;
281+ const [ loadingMsg , setLoadingMsg ] = useState < string | null > ( "Placing order..." ) ;
281282
282283 async function submitOrder ( ) {
283284 const endsAt = roundEndDate ( props . endsAt ) ;
@@ -302,7 +303,6 @@ function BuyOrder(
302303 } ) ;
303304 setOrder ( order ) ;
304305 }
305-
306306 const handleSubmit = useCallback ( ( submitValue : boolean ) => {
307307 if ( submitValue === false ) {
308308 setIsLoading ( false ) ;
@@ -311,7 +311,7 @@ function BuyOrder(
311311 }
312312
313313 submitOrder ( ) ;
314- } , [ exit ] ) ;
314+ } , [ exit , setIsLoading ] ) ;
315315
316316 useEffect ( ( ) => {
317317 if ( isLoading && intervalRef . current == null ) {
@@ -321,15 +321,23 @@ function BuyOrder(
321321 }
322322
323323 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+ }
324332 setOrder ( o ) ;
325333
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 ;
332337 }
338+ exit ( ) ;
339+ return
340+
333341 } , 200 ) ;
334342 }
335343
@@ -339,7 +347,7 @@ function BuyOrder(
339347 intervalRef . current = null ;
340348 }
341349 } ;
342- } , [ isLoading , order ] ) ;
350+ } , [ isLoading , order , exit , setOrder ] ) ;
343351
344352 return (
345353 < Box gap = { 1 } flexDirection = "column" >
@@ -362,7 +370,7 @@ function BuyOrder(
362370 < Box gap = { 1 } >
363371 { ( ! order || order . status === "pending" ) && < Spinner type = "dots" /> }
364372 { order && order . status === "open" && < Text color = { "yellow" } > •</ Text > }
365- { ! order && < Text > Placing order... </ Text > }
373+ { ! order && < Text > { loadingMsg } </ Text > }
366374 { order && (
367375 < Box gap = { 1 } >
368376 < Text > Order placed: { order . id } </ Text >
0 commit comments