Skip to content

Commit

Permalink
FEAT: added blink chaining logic + RPC url from env
Browse files Browse the repository at this point in the history
  • Loading branch information
anisharaz committed Aug 23, 2024
1 parent 47426f7 commit 5ec907f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
22 changes: 22 additions & 0 deletions app/api/blink/[blinkid]/confirm/route.ts
Original file line number Diff line number Diff line change
@@ -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);
}
14 changes: 8 additions & 6 deletions app/api/blink/[blinkid]/route.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
});
Expand Down
8 changes: 6 additions & 2 deletions lib/solana.ts
Original file line number Diff line number Diff line change
@@ -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}`
);
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5ec907f

Please sign in to comment.