Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions nevo_frontend/app/pools/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -62,8 +62,34 @@ export default function PoolDetailPage() {
const [withdrawStep, setWithdrawStep] = useState<WithdrawStep>('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 = () => {
Expand Down
12 changes: 12 additions & 0 deletions nevo_frontend/lib/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading