diff --git a/app/api/blink/[blinkid]/confirm/route.ts b/app/api/blink/[blinkid]/confirm/route.ts new file mode 100644 index 0000000..7697923 --- /dev/null +++ b/app/api/blink/[blinkid]/confirm/route.ts @@ -0,0 +1,22 @@ +import prisma from "@/lib/db"; +import { NextAction } from "@dialectlabs/blinks"; +import { ACTIONS_CORS_HEADERS } from "@solana/actions"; +import { NextResponse } from "next/server"; + +export async function POST( + req: Request, + { params }: { params: { blinkid: string } } +) { + const blink = await prisma.blinks.findFirst({ + where: { + id: params.blinkid, + }, + }); + const { signature, account } = await req.json(); + console.log({ signature, account }); + // @ts-ignore + const payload: NextAction = blink?.data!; + payload.type = "completed"; + payload.disabled = true; + return NextResponse.json(payload, ACTIONS_CORS_HEADERS); +} diff --git a/app/api/blink/[blinkid]/route.ts b/app/api/blink/[blinkid]/route.ts index 8bb64e4..5e0efda 100644 --- a/app/api/blink/[blinkid]/route.ts +++ b/app/api/blink/[blinkid]/route.ts @@ -1,10 +1,6 @@ import prisma from "@/lib/db"; -import { - ActionGetResponse, - ActionPostResponse, - ACTIONS_CORS_HEADERS, - createPostResponse, -} from "@solana/actions"; +import { ACTIONS_CORS_HEADERS, createPostResponse } from "@solana/actions"; +import { ActionPostResponse, ActionGetResponse } from "@dialectlabs/blinks"; import { Connection, LAMPORTS_PER_SOL, @@ -95,6 +91,12 @@ export async function POST( message: `Send ${amount} SOL to ${myaccount.toBase58()}`, }, }); + payload.links = { + next: { + type: "post", + href: `/api/blink/${params.blinkid}/confirm`, + }, + }; return NextResponse.json(payload, { headers: ACTIONS_CORS_HEADERS, }); diff --git a/lib/solana.ts b/lib/solana.ts index 2014fc9..47217af 100644 --- a/lib/solana.ts +++ b/lib/solana.ts @@ -1,3 +1,7 @@ -import { clusterApiUrl, Connection } from "@solana/web3.js"; +import { Connection } from "@solana/web3.js"; -export const conn = new Connection(clusterApiUrl("devnet")); +export const conn = new Connection( + `https://${ + process.env.RPC_NET === "mainnet" ? "mainnet" : "devnet" + }.helius-rpc.com/?api-key=${process.env.RPC_URL_KEY}` +); diff --git a/package-lock.json b/package-lock.json index bb20367..52ea981 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@auth/prisma-adapter": "^2.4.2", "@aws-sdk/client-s3": "^3.627.0", "@aws-sdk/s3-presigned-post": "^3.627.0", - "@dialectlabs/blinks": "^0.7.0", + "@dialectlabs/blinks": "^0.8.0", "@radix-ui/react-avatar": "^1.1.0", "@radix-ui/react-hover-card": "^1.1.1", "@radix-ui/react-slot": "^1.1.0", @@ -3387,9 +3387,9 @@ } }, "node_modules/@dialectlabs/blinks": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@dialectlabs/blinks/-/blinks-0.7.0.tgz", - "integrity": "sha512-MiUyrDXZJk2Jypz2WV2v7agi6iosiCX7tkUXEwppRaiNBeklWqLU2fPxTx+eKGeoxltHUW++m0f+t0w/SLlRCQ==", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@dialectlabs/blinks/-/blinks-0.8.0.tgz", + "integrity": "sha512-aA0qetB1U6BRUj0RHWIHYn3INw09svNHFSyS23iMwRfBL2Nvtp/FVjPU8s5KF+BqA5gOYof+6VC7zby4RUaDIQ==", "license": "Apache-2.0", "dependencies": { "clsx": "^2.1.1" diff --git a/package.json b/package.json index 346c64e..c2a93cc 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@auth/prisma-adapter": "^2.4.2", "@aws-sdk/client-s3": "^3.627.0", "@aws-sdk/s3-presigned-post": "^3.627.0", - "@dialectlabs/blinks": "^0.7.0", + "@dialectlabs/blinks": "^0.8.0", "@radix-ui/react-avatar": "^1.1.0", "@radix-ui/react-hover-card": "^1.1.1", "@radix-ui/react-slot": "^1.1.0",