diff --git a/nevo_frontend/app/pools/new/page.tsx b/nevo_frontend/app/pools/new/page.tsx index 5613b38..1d77110 100644 --- a/nevo_frontend/app/pools/new/page.tsx +++ b/nevo_frontend/app/pools/new/page.tsx @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; import ProtectedRoute from '@/components/ProtectedRoute'; -import { createPool, submitSignedXdr } from '@/lib/api-client'; +import { createPool, submitSignedXdr, ApiError } from '@/lib/api-client'; import { signTransaction } from '@stellar/freighter-api'; import { contractService } from '@/lib/contract-service'; import { useWalletStore } from '@/src/store/walletStore'; @@ -291,9 +291,10 @@ function CreatePoolPageContent() { ); } - // First call createPool API (handle validation errors here) + // First call createPool API to get poolId and unsignedXdr (handle validation errors here) + let createPoolResult; try { - await createPool({ + createPoolResult = await createPool({ title: form.title, description: form.description, category: form.category, @@ -332,17 +333,9 @@ function CreatePoolPageContent() { throw err; } - const goalInStroops = BigInt( - Math.round(parseFloat(form.goalAmount) * 1e7) - ); - const xdr = await contractService.buildCreatePoolTransaction( - publicKey, - form.title, - form.description, - goalInStroops - ); + // Call Freighter's signTransaction with unsignedXdr setSubmitStep('signing'); - const signedResult = await signTransaction(xdr, { + const signedResult = await signTransaction(createPoolResult.unsignedXdr, { networkPassphrase: process.env.NEXT_PUBLIC_NETWORK_PASSPHRASE || 'Test SDF Network ; September 2015', @@ -357,26 +350,11 @@ function CreatePoolPageContent() { } throw new Error(signedResult.error); } + + // Submit signed XDR setSubmitStep('submitting'); await submitSignedXdr(signedResult.signedTxXdr); - // Save pool metadata to the backend database - // New pool ID = current pool count + 1 (contract auto-increments) - const poolCount = await contractService.getPoolCount(); - // Fall back to a unique prefixed ID if RPC is unavailable; - // the backend sync service will reconcile on-chain data later. - const contractPoolId = - poolCount >= 0 ? String(poolCount + 1) : `local-${Date.now()}`; - await createPool({ - contractPoolId, - creatorWallet: publicKey, - goal: goalInStroops.toString(), - title: form.title, - description: form.description, - category: form.category, - imageUrl: form.imageUrl || undefined, - }); - setSubmitted(true); } catch (error) { const err = error as Error;