diff --git a/.eslintignore b/.eslintignore index 6b6100d90..0c71ecf61 100644 --- a/.eslintignore +++ b/.eslintignore @@ -11,3 +11,6 @@ # TradingView library /public/charting_library + +# ignore vite build files +.vite diff --git a/.gitignore b/.gitignore index e70d7e0d4..eab5603e8 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,9 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +# Vite +.vite + #editors .idea .vscode diff --git a/.prettierignore b/.prettierignore index fd7d73fea..87c42b181 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,5 +12,8 @@ # ignore chart library dependency /public/charting_library +# ignore vite build files +.vite + # ignore change log, it is auto-formatted by semantic release CHANGELOG.md diff --git a/src/components/Dialog/Dialog.tsx b/src/components/Dialog/Dialog.tsx index d365b03e1..f7d44a873 100644 --- a/src/components/Dialog/Dialog.tsx +++ b/src/components/Dialog/Dialog.tsx @@ -40,7 +40,6 @@ export default function Dialog({ ); return ( - ({ - isValidating: false, + const chainId = chain?.chain_id ?? ''; + const { data, isFetching, error } = useQuery({ + enabled: !!chainId, + queryKey: ['useChainAddress', chainId], + queryFn: async (): Promise => { + return getChainInfo(chainId).then((chainInfo) => chainInfo.bech32Address); + }, + // if the request was declined, don't keep re-requesting it + retry: false, }); - useMemo(() => { - if (chainId) { - setChainState({ isValidating: true }); - getChainInfo(chainId) - .then((chainInfo) => { - setChainState({ - data: chainInfo.bech32Address, - isValidating: false, - }); - }) - .catch((error) => { - setChainState({ isValidating: false, error }); - }); - } - }, [chainId]); - return { data, isValidating, error }; + return { data, isValidating: isFetching, error: error || undefined }; } async function getIbcLcdClient( diff --git a/src/lib/web3/hooks/useIndexer.ts b/src/lib/web3/hooks/useIndexer.ts index 9a249572e..31a2ea2e1 100644 --- a/src/lib/web3/hooks/useIndexer.ts +++ b/src/lib/web3/hooks/useIndexer.ts @@ -486,18 +486,18 @@ export function useIndexerStreamOfDualDataSet< ) as StaleWhileRevalidateState<[DataSet, DataSet]>; } -// add higher-level function to fetch multiple pages of data as "one request" -export async function fetchDataFromIndexer( +// add higher-level functions to fetch multiple pages of data as "one request" +async function fetchDataFromIndexer( baseURL: URL | string, IndexerClass: typeof IndexerStreamAccumulateSingleDataSet, opts?: AccumulatorOptions & StreamOptions ): Promise>; -export async function fetchDataFromIndexer( +async function fetchDataFromIndexer( baseURL: URL | string, IndexerClass: typeof IndexerStreamAccumulateDualDataSet, opts?: AccumulatorOptions & StreamOptions ): Promise[]>; -export async function fetchDataFromIndexer( +async function fetchDataFromIndexer( baseURL: URL | string, IndexerClass: | typeof IndexerStreamAccumulateSingleDataSet @@ -526,3 +526,17 @@ export async function fetchDataFromIndexer( stream.accumulateUpdates = accumulateUpdatesUsingMutation; }); } + +export function fetchSingleDataSetFromIndexer( + url: URL | string, + opts?: AccumulatorOptions & StreamOptions +): Promise> { + return fetchDataFromIndexer(url, IndexerStreamAccumulateSingleDataSet, opts); +} + +export function fetchDualDataSetFromIndexer( + url: URL | string, + opts?: AccumulatorOptions & StreamOptions +): Promise[]> { + return fetchDataFromIndexer(url, IndexerStreamAccumulateDualDataSet, opts); +} diff --git a/src/lib/web3/hooks/useTickLiquidity.ts b/src/lib/web3/hooks/useTickLiquidity.ts index 8b6241987..7a580089f 100644 --- a/src/lib/web3/hooks/useTickLiquidity.ts +++ b/src/lib/web3/hooks/useTickLiquidity.ts @@ -20,9 +20,11 @@ export function useTokenPairMapLiquidity([tokenIdA, tokenIdB]: [ data?: [ReserveDataSet, ReserveDataSet]; error?: unknown; } { + const encodedA = tokenIdA && encodeURIComponent(tokenIdA); + const encodedB = tokenIdB && encodeURIComponent(tokenIdB); // stream data from indexer return useIndexerStreamOfDualDataSet( - tokenIdA && tokenIdB && `/liquidity/pair/${tokenIdA}/${tokenIdB}`, + encodedA && encodedB && `/liquidity/pair/${encodedA}/${encodedB}`, { // remove entries of value 0 from the accumulated map, they are not used mapEntryRemovalValue: 0, diff --git a/src/lib/web3/hooks/useUserReserves.ts b/src/lib/web3/hooks/useUserReserves.ts index 336411c6c..2207c2a01 100644 --- a/src/lib/web3/hooks/useUserReserves.ts +++ b/src/lib/web3/hooks/useUserReserves.ts @@ -246,7 +246,7 @@ function useUserDepositsTotalShares( for (const userPoolTotalShare of userPoolTotalShares || []) { // make map here const poolID = getDexSharePoolID(userPoolTotalShare.balance); - if (poolID) { + if (poolID !== undefined) { totalSharesByPoolID.set(poolID, userPoolTotalShare); } } @@ -281,7 +281,9 @@ function useUserDepositsTotalShares( return userDepositsWithPoolID?.map(({ deposit, metadata }) => { const poolID = metadata?.ID.toNumber(); const totalShares = - totalSharesByPoolID.get(poolID || -1)?.totalShares ?? '0'; + poolID !== undefined + ? totalSharesByPoolID.get(poolID)?.totalShares ?? '0' + : '0'; return { deposit, totalShares, diff --git a/src/pages/Orderbook/OrderbookChart.tsx b/src/pages/Orderbook/OrderbookChart.tsx index e50c24e29..86bbb23ea 100644 --- a/src/pages/Orderbook/OrderbookChart.tsx +++ b/src/pages/Orderbook/OrderbookChart.tsx @@ -146,7 +146,9 @@ export default function OrderBookChart({ searchParams?: PaginationRequestQuery & BlockRangeRequestQuery ) => { const url = new URL( - `${REACT_APP__INDEXER_API}/timeseries/price/${symbolA}/${symbolB}${ + `${REACT_APP__INDEXER_API}/timeseries/price/${encodeURIComponent( + symbolA + )}/${encodeURIComponent(symbolB)}${ resolutionMap[`${resolution}`] ? `/${resolutionMap[`${resolution}`]}` : ''