1
- "use client" ;
2
-
1
+ import { env } from "@/lib/env" ;
3
2
import { Tx , TxSchema } from "@/types/txs" ;
4
3
import {
5
4
keepPreviousData ,
8
7
} from "@tanstack/react-query" ;
9
8
import { z } from "zod" ;
10
9
11
- //TODO - use an envfile
12
- const API_URL = "http://localhost:4000/api/v1" ;
13
-
14
10
export const useTxs = ( operationName ?: string , tags ?: Map < string , string > ) => {
15
11
const tagsObj = tags ? Object . fromEntries ( tags . entries ( ) ) : undefined ;
16
12
@@ -25,7 +21,9 @@ export const useTxs = (operationName?: string, tags?: Map<string, string>) => {
25
21
return useQuery < Readonly < Array < Tx > > > ( {
26
22
queryKey : [ "txs" , { operationName, tags : tagsObj } ] ,
27
23
queryFn : ( ) =>
28
- fetch ( `${ API_URL } /txs${ params . size ? `?${ params . toString ( ) } ` : "" } ` )
24
+ fetch (
25
+ `${ env . NEXT_PUBLIC_API_URL } /txs${ params . size ? `?${ params . toString ( ) } ` : "" } ` ,
26
+ )
29
27
. then ( ( res ) => res . json ( ) )
30
28
. then ( ( { txs } ) => z . array ( TxSchema ) . parse ( txs ) ) ,
31
29
placeholderData : keepPreviousData ,
@@ -38,7 +36,7 @@ export const useTx = (id: string) => {
38
36
return useQuery < Readonly < Array < Tx > > > ( {
39
37
queryKey : [ "tx" , id ] ,
40
38
queryFn : ( ) =>
41
- fetch ( `${ API_URL } /txs?traceID=${ id } ` )
39
+ fetch ( `${ env . NEXT_PUBLIC_API_URL } /txs?traceID=${ id } ` )
42
40
. then ( ( res ) => res . json ( ) )
43
41
. then ( ( { txs } ) => z . array ( TxSchema ) . parse ( txs ) ) ,
44
42
placeholderData : ( ) => {
0 commit comments