'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); }