Skip to content
Open
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
10 changes: 10 additions & 0 deletions app/api/wallet-set/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@

import { NextRequest, NextResponse } from "next/server";
import { circleDeveloperSdk } from "@/lib/circle/developer-controlled-wallets-client";
import { createClient } from "@/lib/supabase/server";

export async function POST(req: NextRequest) {
try {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();

if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

const { entityName } = await req.json();

if (!entityName.trim()) {
Expand Down
50 changes: 26 additions & 24 deletions app/api/wallet/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ const DB_CHAIN_TO_SDK: Record<string, SupportedChain> = {

export async function POST(req: NextRequest) {
try {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();

if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

const { walletSetId, blockchain } = await req.json();

if (!walletSetId || !blockchain) {
Expand Down Expand Up @@ -63,31 +72,24 @@ export async function POST(req: NextRequest) {

// After creating the wallet, register the gateway signer
try {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();

if (user) {
const { data: eoaWallet } = await supabase
.from("wallets")
.select("address")
.eq("user_id", user.id)
.eq("blockchain", blockchain)
.eq("type", "gateway_signer")
.single();
const { data: eoaWallet } = await supabase
.from("wallets")
.select("address")
.eq("user_id", user.id)
.eq("blockchain", blockchain)
.eq("type", "gateway_signer")
.single();

if (eoaWallet) {
console.log(
`Will add EOA delegate ${eoaWallet.address} for depositor ${response.data.wallets[0].address}`
);
await initiateDepositFromCustodialWallet(
response.data.wallets[0].id as string,
DB_CHAIN_TO_SDK[blockchain],
BigInt(0),
eoaWallet.address as any
);
}
if (eoaWallet) {
console.log(
`Will add EOA delegate ${eoaWallet.address} for depositor ${response.data.wallets[0].address}`
);
await initiateDepositFromCustodialWallet(
response.data.wallets[0].id as string,
DB_CHAIN_TO_SDK[blockchain],
BigInt(0),
eoaWallet.address as any
);
}
} catch (error) {
console.error("Failed to register delegate for gateway:", error);
Expand Down