import { usePageData, usePageMutation } from '@/lib/page/usePageData'; import { useInject } from '@/lib/di/hooks/useInject'; import { LEAGUE_WALLET_SERVICE_TOKEN } from '@/lib/di/tokens'; export function useLeagueWalletPageData(leagueId: string) { const leagueWalletService = useInject(LEAGUE_WALLET_SERVICE_TOKEN); const queryResult = usePageData({ queryKey: ['leagueWallet', leagueId], queryFn: () => leagueWalletService.getWalletForLeague(leagueId), enabled: !!leagueId, }); return queryResult; } export function useLeagueWalletWithdrawal(leagueId: string, data: any, refetch: () => void) { const leagueWalletService = useInject(LEAGUE_WALLET_SERVICE_TOKEN); const withdrawMutation = usePageMutation( async ({ amount }: { amount: number }) => { if (!data) throw new Error('Wallet data not available'); const result = await leagueWalletService.withdraw( leagueId, amount, data.currency, 'season-2', // Current active season 'bank-account-***1234' ); if (!result.success) { throw new Error(result.message || 'Withdrawal failed'); } return result; }, { onSuccess: () => { // Refetch wallet data after successful withdrawal refetch(); }, } ); return withdrawMutation; }