-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9520b93
commit c7e3d84
Showing
24 changed files
with
68 additions
and
146 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 |
---|---|---|
@@ -1,17 +1,7 @@ | ||
import { QueryFunction } from '@tanstack/react-query' | ||
import { logQuery } from '@/shared/lib/logging' | ||
import { assertChainValidity } from '../lib/validation' | ||
import { ChainQuery } from '@/shared/model/query' | ||
import useStore from '@/store/useStore' | ||
import { ChainQueryKeyType } from '../model' | ||
|
||
export const queryOneWayMarketNames: QueryFunction< | ||
string[], | ||
ChainQueryKeyType<'markets'> | ||
> = async ({ queryKey }) => { | ||
logQuery(queryKey) | ||
const [, chainId, , ] = queryKey | ||
assertChainValidity({ chainId }) | ||
|
||
export const queryOneWayMarketNames = async ({}: ChainQuery): Promise<string[]> => { | ||
const {api} = useStore.getState() | ||
return api!.oneWayfactory.getMarketList() | ||
} |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './lib' | ||
export * from './types' |
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
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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { createQueryHook } from '@/shared/lib/queries' | ||
import { getOneWayMarketNames } from '../model/query-options' | ||
import { oneWayMarketNames } from '../model' | ||
|
||
export const useOneWayMarketNames = createQueryHook(getOneWayMarketNames); | ||
export const { useQuery: useOneWayMarketNames } = oneWayMarketNames; |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import { queryOptions } from '@tanstack/react-query' | ||
import { REFRESH_INTERVAL } from '@/constants' | ||
import { checkChainValidity } from '../lib/validation' | ||
import { queryOneWayMarketNames } from '../api/markets-api' | ||
import { chainKeys } from './query-keys' | ||
import { ChainQueryParams } from '../types' | ||
import { queryOneWayMarketNames } from '@/entities/chain/api/markets-api' | ||
import { chainValidationSuite } from '@/entities/chain/model/validation' | ||
import { ChainParams, queryFactory } from '@/shared/model/query' | ||
|
||
export const getOneWayMarketNames = (params: ChainQueryParams, condition = true) => | ||
queryOptions({ | ||
queryKey: chainKeys.markets(params), | ||
queryFn: queryOneWayMarketNames, | ||
staleTime: REFRESH_INTERVAL['5m'], | ||
enabled: condition && checkChainValidity(params), | ||
}) | ||
export const oneWayMarketNames = queryFactory({ | ||
queryKey: ({ chainId }: ChainParams) => ['chain', { chainId }, 'markets'] as const, | ||
queryFn: queryOneWayMarketNames, | ||
staleTime: '5m', | ||
validationSuite: chainValidationSuite | ||
}) |
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
This file was deleted.
Oops, something went wrong.
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 { TokenQuery } from '@/entities/token/index' | ||
import useStore from '@/store/useStore' | ||
|
||
export const queryTokenUsdRate = async ({ tokenAddress}: TokenQuery): Promise<number> => { | ||
const { api } = useStore.getState() | ||
return await api!.getUsdRate(tokenAddress) | ||
} |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
import { tokenUsdRate } from '@/entities/token/model' | ||
import { useQueryMapping } from '@/shared/lib/queries' | ||
import { ChainParams } from '@/shared/model/query' | ||
|
||
export const { | ||
getQueryData: getTokenUsdRateQueryData, | ||
useQuery: useTokenUsdRate, | ||
getQueryOptions: getTokenUsdRateQueryOptions | ||
} = tokenUsdRate | ||
|
||
export const useTokenUsdRates = ({ chainId, tokenAddresses = [] }: ChainParams & { tokenAddresses?: string[] }) => | ||
useQueryMapping( | ||
tokenAddresses.map((tokenAddress) => getTokenUsdRateQueryOptions({ chainId, tokenAddress })), | ||
tokenAddresses | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
export * from './query-keys' | ||
export * from './query-options' | ||
export * from './validation' | ||
export { tokenUsdRate } from './token-query' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
import { TokenParams } from '@/entities/token' | ||
import { queryTokenUsdRate } from '@/entities/token/api' | ||
import { tokenValidationSuite } from '@/entities/token/model' | ||
import { queryFactory, rootKeys } from '@/shared/model/query' | ||
|
||
const root = ({ chainId, tokenAddress }: TokenParams) => [...rootKeys.chain({chainId}), 'token', { tokenAddress }] as const | ||
|
||
export const tokenUsdRate = queryFactory({ | ||
queryKey: (params: TokenParams) => [...root(params), 'usdRate'] as const, | ||
queryFn: queryTokenUsdRate, | ||
staleTime: '5m', | ||
validationSuite: tokenValidationSuite, | ||
}) |
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
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 |
---|---|---|
@@ -1,12 +1,5 @@ | ||
import { ChainQueryParams } from '@/entities/chain/types' | ||
import type { ExtractQueryKeyType } from '@/shared/types/api' | ||
import { tokenKeys } from '@/entities/token/model' | ||
import { FieldsOf } from '@/shared/lib/validation' | ||
import { ChainQuery } from '@/shared/model/query' | ||
|
||
export type TokenQueryParams = ChainQueryParams & { | ||
tokenAddress?: string | ||
} | ||
|
||
export type CombinedTokenParams = TokenQueryParams | ||
|
||
export type TokenKey = keyof typeof tokenKeys | ||
export type TokenQueryKeyType<K extends TokenKey = TokenKey> = ExtractQueryKeyType<typeof tokenKeys, K> | ||
export type TokenQuery = ChainQuery & { tokenAddress: string }; | ||
export type TokenParams = FieldsOf<TokenQuery>; |
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