Skip to content

Commit

Permalink
fix: remove stxprice suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Dec 13, 2024
1 parent c0214dd commit 6b45176
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/app/address/[principal]/StxBalance/BalanceItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as React from 'react';

import { useSuspenseStxPrice } from '../../../../common/queries/useCurrentPrices';
import { useStxPrice } from '../../../../common/queries/useCurrentPrices';

Check warning on line 5 in src/app/address/[principal]/StxBalance/BalanceItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/StxBalance/BalanceItem.tsx#L5

Added line #L5 was not covered by tests
import {
formatStacksAmount,
getLocaleDecimalSeparator,
Expand All @@ -13,7 +13,7 @@ import { Text } from '../../../../ui/Text';
import { ExplorerErrorBoundary } from '../../../_components/ErrorBoundary';

function UsdBalanceBase({ balance }: { balance: number }) {
const { data: stxPrice } = useSuspenseStxPrice();
const { data: stxPrice } = useStxPrice();

Check warning on line 16 in src/app/address/[principal]/StxBalance/BalanceItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/StxBalance/BalanceItem.tsx#L16

Added line #L16 was not covered by tests
const usdBalance = getUsdValue(balance, stxPrice);

if (!usdBalance) {
Expand Down
6 changes: 3 additions & 3 deletions src/common/components/StxPriceButton/useStxPriceForTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import { MempoolTransaction, Transaction } from '@stacks/stacks-blockchain-api-types';

import { useSuspenseStxPrice } from '../../queries/useCurrentPrices';
import { useStxPrice } from '../../queries/useCurrentPrices';

Check warning on line 5 in src/common/components/StxPriceButton/useStxPriceForTx.ts

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPriceButton/useStxPriceForTx.ts#L5

Added line #L5 was not covered by tests

export const useStxPriceForTx = (tx: Transaction | MempoolTransaction) => {
const hasBlockHeight = 'block_height' in tx;
const blockBurnTime = hasBlockHeight
? tx.parent_burn_block_time_iso || tx.burn_block_time_iso
: undefined;
const { data: historicalStxPrice } = useSuspenseStxPrice(blockBurnTime, {
const { data: historicalStxPrice } = useStxPrice(blockBurnTime, {

Check warning on line 12 in src/common/components/StxPriceButton/useStxPriceForTx.ts

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPriceButton/useStxPriceForTx.ts#L12

Added line #L12 was not covered by tests
enabled: !!blockBurnTime,
});
const { data: currentStxPrice } = useSuspenseStxPrice();
const { data: currentStxPrice } = useStxPrice();

Check warning on line 15 in src/common/components/StxPriceButton/useStxPriceForTx.ts

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPriceButton/useStxPriceForTx.ts#L15

Added line #L15 was not covered by tests
return { historicalStxPrice, currentStxPrice };
};
11 changes: 8 additions & 3 deletions src/common/queries/useCurrentPrices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use client';

import { QueryFunctionContext, UseQueryOptions, useSuspenseQuery } from '@tanstack/react-query';
import {
QueryFunctionContext,
UseQueryOptions,
useQuery,
useSuspenseQuery,
} from '@tanstack/react-query';

Check warning on line 8 in src/common/queries/useCurrentPrices.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useCurrentPrices.ts#L8

Added line #L8 was not covered by tests

import { ONE_HOUR } from './query-stale-time';

Expand All @@ -11,12 +16,12 @@ const getHistoricalStxPrice = async ({ queryKey }: QueryFunctionContext) => {
.then(data => data?.price || 0);
};

export const useSuspenseStxPrice = (
export const useStxPrice = (

Check warning on line 19 in src/common/queries/useCurrentPrices.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useCurrentPrices.ts#L19

Added line #L19 was not covered by tests
blockBurnTime?: string,
options?: Partial<UseQueryOptions<any, unknown, any, string[]>>
) => {
const blockBurnTimeDate = blockBurnTime?.split('T')[0];
return useSuspenseQuery({
return useQuery({

Check warning on line 24 in src/common/queries/useCurrentPrices.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useCurrentPrices.ts#L24

Added line #L24 was not covered by tests
queryKey: ['stx-price', blockBurnTimeDate ? blockBurnTime.split('T')[0] : 'current'],
queryFn: getHistoricalStxPrice,
staleTime: blockBurnTime ? Infinity : ONE_HOUR * 3,
Expand Down

0 comments on commit 6b45176

Please sign in to comment.