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 33824db
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
54 changes: 27 additions & 27 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
module.exports = {
extends: [
"plugin:react-hooks/recommended",
"plugin:@next/next/recommended",
"plugin:storybook/recommended"
],
plugins: ['react', 'react-hooks'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
},
env: {
browser: true,
node: true,
es6: true,
},
globals: {
page: true,
browser: true,
context: true,
jestPuppeteer: true,
},
rules: {
'react-hooks/rules-of-hooks': 'error',
},
ignorePatterns: ['next.config.js'],
};
module.exports = {
extends: [
'plugin:react-hooks/recommended',
'plugin:@next/next/recommended',
'plugin:storybook/recommended',
],
plugins: ['react', 'react-hooks'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
},
env: {
browser: true,
node: true,
es6: true,
},
globals: {
page: true,
browser: true,
context: true,
jestPuppeteer: true,
},
rules: {
'react-hooks/rules-of-hooks': 'error',
},
ignorePatterns: ['next.config.js'],
};
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';
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();
const usdBalance = getUsdValue(balance, stxPrice);

if (!usdBalance) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/signers/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const SIGNER_KEY_MAP: Record<string, { poolOperator: string; name: string
'0x03815f036a90512671911fd66cca53dd88d421beaa3253083635f267dc614ee888': {
poolOperator: 'SMNDR0TBKJRFGGD87M5AAKYFG4BM7W87YVM5QZJP',
name: 'Nansen',
}
},
};
export const mobileBorderCss = {
'.has-horizontal-scroll &:before': {
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';

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, {
enabled: !!blockBurnTime,
});
const { data: currentStxPrice } = useSuspenseStxPrice();
const { data: currentStxPrice } = useStxPrice();
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';

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 = (
blockBurnTime?: string,
options?: Partial<UseQueryOptions<any, unknown, any, string[]>>
) => {
const blockBurnTimeDate = blockBurnTime?.split('T')[0];
return useSuspenseQuery({
return useQuery({
queryKey: ['stx-price', blockBurnTimeDate ? blockBurnTime.split('T')[0] : 'current'],
queryFn: getHistoricalStxPrice,
staleTime: blockBurnTime ? Infinity : ONE_HOUR * 3,
Expand Down

0 comments on commit 33824db

Please sign in to comment.