Skip to content

Commit d50fe19

Browse files
committed
refactor: enhance webhooks query handling and component imports
- Introduced useWebhooksMaybeQuery to conditionally fetch webhooks based on project existence, improving flexibility in the WebhooksPricingSection. - Updated imports in WebhooksPricingSection to include the new query function, ensuring consistent data handling. - Removed unused Button import in LiteserversTiersSection for cleaner code. These changes collectively improve the efficiency and maintainability of the pricing components.
1 parent be8a681 commit d50fe19

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/features/tonapi/pricing/ui/LiteserversTiersSection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
useDisclosure,
99
Spinner,
1010
Center,
11-
Badge,
12-
Button
11+
Badge
1312
} from '@chakra-ui/react';
1413
import { useNavigate } from 'react-router-dom';
1514
import { SimpleTierCard } from './SimpleTierCard';

src/features/tonapi/pricing/ui/WebhooksPricingSection.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Spinner
1616
} from '@chakra-ui/react';
1717
import { UsdCurrencyAmount, Network } from 'src/shared';
18-
import { useWebhooksQuery } from '../../webhooks/model/queries';
18+
import { useWebhooksMaybeQuery, useWebhooksQuery } from '../../webhooks/model/queries';
1919
import { WebhookTiers, calculateExpectedPrice } from '../utils/calculating';
2020

2121
export const PricingDiagram: FC<{ isDisabled?: boolean }> = ({ isDisabled = false }) => {
@@ -243,13 +243,7 @@ export const WebhooksPricingSection: FC<WebhooksPricingSectionProps> = ({
243243
}) => {
244244
// Hooks must be called unconditionally at top level (React hooks rules)
245245
const navigate = useNavigate();
246-
const {
247-
data: webhooks = [],
248-
isLoading,
249-
error
250-
} = displayOnly
251-
? { data: [], isLoading: false, error: null }
252-
: useWebhooksQuery(Network.MAINNET);
246+
const { data: webhooks = [], isLoading, error } = useWebhooksMaybeQuery(Network.MAINNET);
253247

254248
// Display-only mode: render static content without using data-fetching result
255249
if (displayOnly) {

src/features/tonapi/webhooks/model/queries.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2-
import { useProjectId } from 'src/shared/contexts/ProjectContext';
2+
import { useMaybeProject, useProjectId } from 'src/shared/contexts/ProjectContext';
33
import {
44
rtTonApiClient,
55
RTWebhookAccountTxSubscriptions
@@ -49,6 +49,14 @@ export function mapWebhooksStatsToChartPoints(
4949
return items;
5050
}
5151

52+
export function useWebhooksMaybeQuery(network: Network) {
53+
const project = useMaybeProject();
54+
if (project) {
55+
return useWebhooksQuery(network);
56+
}
57+
return { data: [], isLoading: false, error: null };
58+
}
59+
5260
/**
5361
* Fetch all webhooks for a project
5462
* Returns error state if webhooks feature is not available (501 error)

0 commit comments

Comments
 (0)