Skip to content

Commit 28ae1da

Browse files
committed
fix: useWebhooksQuery handles missing project gracefully
1 parent 5c9d16b commit 28ae1da

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

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

Lines changed: 2 additions & 2 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 { useWebhooksMaybeQuery } from '../../webhooks/model/queries';
18+
import { useWebhooksQuery } from '../../webhooks/model/queries';
1919
import { WebhookTiers, calculateExpectedPrice } from '../utils/calculating';
2020

2121
export const PricingDiagram: FC<{ isDisabled?: boolean }> = ({ isDisabled = false }) => {
@@ -243,7 +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 { data: webhooks = [], isLoading, error } = useWebhooksMaybeQuery(Network.MAINNET);
246+
const { data: webhooks = [], isLoading, error } = useWebhooksQuery(Network.MAINNET);
247247

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

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,25 @@ export function mapWebhooksStatsToChartPoints(
4949
return items;
5050
}
5151

52-
export function useWebhooksMaybeQuery(network: Network) {
53-
const project = useMaybeProject();
54-
const query = useWebhooksQuery(network);
55-
56-
if (!project) {
57-
return { data: [], isLoading: false, error: null };
58-
}
59-
60-
return query;
61-
}
62-
6352
/**
6453
* Fetch all webhooks for a project
54+
* Returns empty array if no project selected
6555
* Returns error state if webhooks feature is not available (501 error)
6656
*/
6757
export function useWebhooksQuery(network: Network) {
68-
const projectId = useProjectId();
58+
const project = useMaybeProject();
6959

7060
return useQuery({
71-
queryKey: WEBHOOKS_KEYS.list(projectId || undefined, network),
61+
queryKey: WEBHOOKS_KEYS.list(project?.id, network),
7262
queryFn: async () => {
73-
if (!projectId) return [];
63+
if (!project) return [];
7464
const response = await rtTonApiClient.webhooks.getWebhooks({
75-
project_id: projectId.toString(),
65+
project_id: project.id.toString(),
7666
network
7767
});
7868
return response.data.webhooks.toSorted((a, b) => b.id - a.id);
7969
},
80-
enabled: !!projectId,
70+
enabled: !!project,
8171
staleTime: 5 * 60 * 1000, // 5 minutes
8272
retry: (failureCount, error) => {
8373
// Don't retry on 501 - feature is not available

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default ({ mode }) => {
5353
],
5454
server: {
5555
host: '127.0.0.1',
56-
port: 5173,
56+
port: 5201,
5757
watch: {
5858
usePolling: true
5959
},

0 commit comments

Comments
 (0)