@@ -14,7 +14,7 @@ import { parseDate } from "chrono-node";
14
14
import { GPUS_PER_NODE } from "../constants.ts" ;
15
15
import type { Quote } from "../Quote.tsx" ;
16
16
import QuoteDisplay from "../Quote.tsx" ;
17
- import { useCallback , useEffect , useState } from "react" ;
17
+ import { useCallback , useEffect , useRef , useState } from "react" ;
18
18
import { Text } from "ink" ;
19
19
import ConfirmInput from "../ConfirmInput.tsx" ;
20
20
import React from "react" ;
@@ -277,6 +277,7 @@ function BuyOrder(
277
277
const [ value , setValue ] = useState ( "" ) ;
278
278
const { exit } = useApp ( ) ;
279
279
const [ order , setOrder ] = useState < Order | null > ( null ) ;
280
+ const intervalRef = useRef < ReturnType < typeof setInterval > | null > ( null ) ;
280
281
281
282
async function submitOrder ( ) {
282
283
const endsAt = roundEndDate ( props . endsAt ) ;
@@ -313,33 +314,32 @@ function BuyOrder(
313
314
} , [ exit ] ) ;
314
315
315
316
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 ( ) => {
323
319
if ( ! order ) {
324
320
return ;
325
321
}
326
322
327
- const o = await getOrder ( order ! . id ) ;
323
+ const o = await getOrder ( order . id ) ;
328
324
setOrder ( o ) ;
329
325
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
+ }
331
331
exit ( ) ;
332
- return ;
333
332
}
334
333
} , 200 ) ;
335
334
}
336
335
337
336
return ( ) => {
338
- if ( interval ) {
339
- clearInterval ( interval ) ;
337
+ if ( intervalRef . current ) {
338
+ clearInterval ( intervalRef . current ) ;
339
+ intervalRef . current = null ;
340
340
}
341
341
} ;
342
- } , [ isLoading , exit , value , order ] ) ;
342
+ } , [ isLoading , order ] ) ;
343
343
344
344
return (
345
345
< Box gap = { 1 } flexDirection = "column" >
0 commit comments