@@ -14,7 +14,7 @@ import { parseDate } from "chrono-node";
1414import { GPUS_PER_NODE } from "../constants.ts" ;
1515import type { Quote } from "../Quote.tsx" ;
1616import QuoteDisplay from "../Quote.tsx" ;
17- import { useCallback , useEffect , useState } from "react" ;
17+ import { useCallback , useEffect , useRef , useState } from "react" ;
1818import { Text } from "ink" ;
1919import ConfirmInput from "../ConfirmInput.tsx" ;
2020import React from "react" ;
@@ -277,6 +277,7 @@ function BuyOrder(
277277 const [ value , setValue ] = useState ( "" ) ;
278278 const { exit } = useApp ( ) ;
279279 const [ order , setOrder ] = useState < Order | null > ( null ) ;
280+ const intervalRef = useRef < ReturnType < typeof setInterval > | null > ( null ) ;
280281
281282 async function submitOrder ( ) {
282283 const endsAt = roundEndDate ( props . endsAt ) ;
@@ -313,33 +314,32 @@ function BuyOrder(
313314 } , [ exit ] ) ;
314315
315316 useEffect ( ( ) => {
316- let interval : ReturnType < typeof setInterval > | null = null ;
317- if ( isLoading ) {
318- interval = setInterval ( async ( ) => {
319- if ( ! isLoading ) {
320- exit ( ) ;
321- }
322-
317+ if ( isLoading && intervalRef . current == null ) {
318+ intervalRef . current = setInterval ( async ( ) => {
323319 if ( ! order ) {
324320 return ;
325321 }
326322
327- const o = await getOrder ( order ! . id ) ;
323+ const o = await getOrder ( order . id ) ;
328324 setOrder ( o ) ;
329325
330- if ( o && o . status != "pending" ) {
326+ if ( o && o . status !== "pending" ) {
327+ if ( intervalRef . current ) {
328+ clearInterval ( intervalRef . current ) ;
329+ intervalRef . current = null ;
330+ }
331331 exit ( ) ;
332- return ;
333332 }
334333 } , 200 ) ;
335334 }
336335
337336 return ( ) => {
338- if ( interval ) {
339- clearInterval ( interval ) ;
337+ if ( intervalRef . current ) {
338+ clearInterval ( intervalRef . current ) ;
339+ intervalRef . current = null ;
340340 }
341341 } ;
342- } , [ isLoading , exit , value , order ] ) ;
342+ } , [ isLoading , order ] ) ;
343343
344344 return (
345345 < Box gap = { 1 } flexDirection = "column" >
0 commit comments