diff --git a/nevo_frontend/app/pools/[id]/page.tsx b/nevo_frontend/app/pools/[id]/page.tsx index 9594828..0d151b4 100644 --- a/nevo_frontend/app/pools/[id]/page.tsx +++ b/nevo_frontend/app/pools/[id]/page.tsx @@ -11,7 +11,7 @@ import { toast } from '@/components/Toast'; import { usePoolsStore } from '@/src/store/poolsStore'; import type { Pool } from '@/src/store/poolsStore'; import { useWalletStore } from '@/src/store/walletStore'; -import { closePool, submitSignedXdr } from '@/lib/api-client'; +import { closePool, submitSignedXdr, withdrawPool } from '@/lib/api-client'; import { signTransaction } from '@stellar/freighter-api'; // Testnet XLM native contract address (same as api-client) @@ -62,8 +62,34 @@ export default function PoolDetailPage() { const [withdrawStep, setWithdrawStep] = useState('idle'); const handleWithdraw = async () => { - // TODO: Implement withdrawal - toast('Withdrawal not implemented yet', 'info'); + if (!pool || !publicKey) return; + try { + setWithdrawStep('creating'); + const { unsignedXdr } = await withdrawPool(pool.id); + + setWithdrawStep('signing'); + const signedResult = await signTransaction(unsignedXdr, { + networkPassphrase: + process.env.NEXT_PUBLIC_NETWORK_PASSPHRASE || + 'Test SDF Network ; September 2015', + }); + + if (signedResult.error) { + throw new Error(signedResult.error); + } + + setWithdrawStep('submitting'); + await submitSignedXdr(signedResult.signedTxXdr); + toast('Withdrawal successful'); + + await fetchPool(Number(pool.id)); + } catch (err: unknown) { + const error = err as Error; + toast(error.message || 'Failed to withdraw funds', 'error'); + console.error(error); + } finally { + setWithdrawStep('idle'); + } }; const withdrawLabel = () => { diff --git a/nevo_frontend/lib/api-client.ts b/nevo_frontend/lib/api-client.ts index c2df148..c7448c1 100644 --- a/nevo_frontend/lib/api-client.ts +++ b/nevo_frontend/lib/api-client.ts @@ -592,6 +592,18 @@ export async function closePool( ); } +export async function withdrawPool( + poolId: string | number +): Promise<{ unsignedXdr: string }> { + return apiClient.post<{ unsignedXdr: string }>( + `/pools/${poolId}/withdraw`, + undefined, + { + requireAuth: true, + } + ); +} + export function verifyAuthSignature( publicKey: string, nonce: string,