Files
gridpilot.gg/apps/website/hooks/league/useLeagueWalletPageData.ts
Marc Mintel 09632d004d
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
code quality
2026-01-26 22:16:33 +01:00

57 lines
2.0 KiB
TypeScript

'use client';
import { usePageData } from '@/lib/page/usePageData';
import { useInject } from '@/lib/di/hooks/useInject';
import { LEAGUE_WALLET_SERVICE_TOKEN } from '@/lib/di/tokens';
import { LeagueWalletViewModel } from '@/lib/view-models/LeagueWalletViewModel';
import { WalletTransactionViewModel } from '@/lib/view-models/WalletTransactionViewModel';
import { useLeagueWalletWithdrawalWithBlockers } from './useLeagueWalletWithdrawalWithBlockers';
export function useLeagueWalletPageData(leagueId: string) {
const leagueWalletService = useInject(LEAGUE_WALLET_SERVICE_TOKEN);
const queryResult = usePageData({
queryKey: ['leagueWallet', leagueId],
queryFn: async () => {
const dto = await leagueWalletService.getWalletForLeague(leagueId);
// Transform DTO to ViewData at client boundary
const transactions = dto.transactions.map(t => ({
id: t.id,
type: t.type as "sponsorship" | "withdrawal" | "prize" | "deposit",
description: t.description,
amount: t.amount,
fee: 0,
netAmount: t.amount,
date: t.date,
status: t.status as "completed" | "pending" | "failed",
}));
return new LeagueWalletViewModel({
leagueId,
balance: dto.balance,
formattedBalance: '',
totalRevenue: dto.balance, // Fallback
formattedTotalRevenue: '',
totalFees: 0,
formattedTotalFees: '',
totalWithdrawals: 0,
pendingPayouts: 0,
formattedPendingPayouts: '',
currency: dto.currency,
transactions,
canWithdraw: true,
withdrawalBlockReason: undefined,
});
},
enabled: !!leagueId,
});
return queryResult;
}
/**
* @deprecated Use useLeagueWalletWithdrawalWithBlockers instead
* This wrapper maintains backward compatibility while using the new blocker-aware hook
*/
export function useLeagueWalletWithdrawal(leagueId: string, data: LeagueWalletViewModel | null, refetch: () => void) {
return useLeagueWalletWithdrawalWithBlockers(leagueId, data, refetch);
}