From a6ac5fad1a6bf5ed411c54645bf4856c9eccb0b1 Mon Sep 17 00:00:00 2001 From: thesn10 <38666407+thesn10@users.noreply.github.com> Date: Thu, 25 Jun 2026 19:17:00 +0200 Subject: [PATCH] feat: create_order instruction (SOL canonical currency) --- app/src/app/listing/[pk]/page.tsx | 51 +++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/app/src/app/listing/[pk]/page.tsx b/app/src/app/listing/[pk]/page.tsx index acfa81c..052d462 100644 --- a/app/src/app/listing/[pk]/page.tsx +++ b/app/src/app/listing/[pk]/page.tsx @@ -1,19 +1,30 @@ 'use client' -import { use } from 'react' +import { use, useState } from 'react' import { useRouter } from 'next/navigation' import { useWallet, useKitTransactionSigner } from '@solana/connector/react' import { ListingDetail } from '@/components/ListingDetail' import { useTx } from '@/hooks/useTx' -import { getCloseListingInstruction } from '@solisting/sdk' +import { useListing } from '@/hooks/useListing' +import { + getCloseListingInstruction, + getCreateOrderInstructionAsync, + findOrderPda, + deriveEscrowId, +} from '@solisting/sdk' +import { DESCRO_PROGRAM_ADDRESS } from '@descro/sdk' import type { Address } from '@solisting/sdk' +const SYSTEM_PROGRAM = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'> + export default function ListingPage({ params }: { params: Promise<{ pk: string }> }) { const { pk } = use(params) const router = useRouter() const { account } = useWallet() const { signer } = useKitTransactionSigner() const sendTx = useTx() + const { data: listing } = useListing(pk as Address) + const [orderLoading, setOrderLoading] = useState(false) async function handleClose() { if (!signer) return @@ -22,13 +33,47 @@ export default function ListingPage({ params }: { params: Promise<{ pk: string } router.push('/listings') } + async function handlePlaceOrder() { + if (!signer || !account || !listing) return + setOrderLoading(true) + try { + const orderId = BigInt(Date.now()) + const [orderPda] = await findOrderPda(pk as Address, account as Address, orderId) + const escrowId = deriveEscrowId(orderPda) + + const ix = await getCreateOrderInstructionAsync({ + buyer: signer, + seller: listing.data.seller, + listingAccount: pk as Address, + canonicalOracle: SYSTEM_PROGRAM, + targetOracle: SYSTEM_PROGRAM, + descroProgram: DESCRO_PROGRAM_ADDRESS, + orderId, + escrowId, + resolver: account as Address, + paymentCurrency: { __kind: 'Sol' }, + expectedAmount: listing.data.price, + maxSlippageBps: 0, + }) + await sendTx( + [ix as never], + [['listing', pk], ['orders', pk]], + 'create_order', + ) + } catch (err) { + console.error('create_order failed:', err) + } finally { + setOrderLoading(false) + } + } + return ( router.push(`/listing/create?edit=${pk}`)} onClose={handleClose} - onPlaceOrder={() => {}} + onPlaceOrder={orderLoading ? undefined : handlePlaceOrder} /> ) }