-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GSW-624] feat: Add react-query common file
- Loading branch information
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
|
||
export const useForceRefetchQuery = () => { | ||
const client = useQueryClient(); | ||
|
||
return client.invalidateQueries.bind(client); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './request'; | ||
export * from './types'; | ||
export * from './queries'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { TokenListResponse } from "@repositories/token"; | ||
import { UseQueryOptions, useQuery } from "@tanstack/react-query"; | ||
import { getTokenPrices, getTokens } from "./request"; | ||
import { QUERY_KEY } from "./types"; | ||
|
||
export const useGetTokensList = ( | ||
option?: UseQueryOptions<TokenListResponse, Error> | ||
) => { | ||
return useQuery<TokenListResponse, Error>({ | ||
queryKey: [QUERY_KEY.tokens], | ||
queryFn: getTokens, | ||
enabled: false, | ||
option, | ||
}); | ||
}; | ||
|
||
export const useGetTokenPrices = ( | ||
option?: UseQueryOptions<TokenListResponse, Error> | ||
) => { | ||
return useQuery<TokenListResponse, Error>({ | ||
queryKey: [QUERY_KEY.tokenPrices], | ||
queryFn: getTokenPrices, | ||
option, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { AxiosClient } from "@common/clients/network-client/axios-client"; | ||
import { TokenListResponse, TokenPriceListResponse } from "@repositories/token"; | ||
|
||
const API_URL = process.env.NEXT_PUBLIC_API_URL; | ||
|
||
const request = new AxiosClient(API_URL); | ||
|
||
export const getTokens = async (): Promise<TokenListResponse> => { | ||
const response = await request.get<TokenListResponse>({ | ||
url: "/tokens", | ||
}); | ||
if (response.data.tokens === null) { | ||
return { tokens: [] }; | ||
} | ||
return response.data; | ||
}; | ||
|
||
export const getTokenPrices = async (): Promise<TokenPriceListResponse> => { | ||
const response = await request.get<TokenPriceListResponse>({ | ||
url: "/token_prices", | ||
}); | ||
return response.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface IExampleTypeRequest {} | ||
export interface IExampleTypeResponse {} | ||
|
||
export enum QUERY_KEY { | ||
tokens = "tokens", | ||
tokenPrices = "token_prices", | ||
} |