Skip to content
148 changes: 148 additions & 0 deletions apps/dashboard/src/@/api/universal-bridge/developer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"use server";
import { getAuthToken } from "app/api/lib/getAuthToken";

const UB_BASE_URL = process.env.NEXT_PUBLIC_THIRDWEB_BRIDGE_HOST;

type Webhook = {
url: string;
label: string;
active: boolean;
createdAt: string;
id: string;
secret: string;
version?: number; // TODO (UB) make this mandatory after migration
};

export async function getWebhooks(props: {
clientId: string;
}) {
const authToken = await getAuthToken();
const res = await fetch(`${UB_BASE_URL}/v1/developer/webhooks`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-client-id-override": props.clientId,
Authorization: `Bearer ${authToken}`,
},
});

if (!res.ok) {
const text = await res.text();
throw new Error(text);
}

const json = await res.json();
return json.data as Array<Webhook>;
}

export async function createWebhook(props: {
clientId: string;
version?: number;
url: string;
label: string;
secret?: string;
}) {
const authToken = await getAuthToken();
const res = await fetch(`${UB_BASE_URL}/v1/developer/webhooks`, {
method: "POST",
body: JSON.stringify({
url: props.url,
label: props.label,
version: props.version,
secret: props.secret,
}),
headers: {
"Content-Type": "application/json",
"x-client-id-override": props.clientId,
Authorization: `Bearer ${authToken}`,
},
});

if (!res.ok) {
const text = await res.text();
throw new Error(text);
}

return;
}

export async function deleteWebhook(props: {
clientId: string;
webhookId: string;
}) {
const authToken = await getAuthToken();
const res = await fetch(
`${UB_BASE_URL}/v1/developer/webhooks/${props.webhookId}`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
"x-client-id-override": props.clientId,
Authorization: `Bearer ${authToken}`,
},
},
);

if (!res.ok) {
const text = await res.text();
throw new Error(text);
}

return;
}

export type Fee = {
feeRecipient: string;
feeBps: number;
createdAt: string;
updatedAt: string;
};

export async function getFees(props: {
clientId: string;
}) {
const authToken = await getAuthToken();
const res = await fetch(`${UB_BASE_URL}/v1/developer/fees`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-client-id-override": props.clientId,
Authorization: `Bearer ${authToken}`,
},
});

if (!res.ok) {
const text = await res.text();
throw new Error(text);
}

const json = await res.json();
return json.data as Fee;
}

export async function updateFee(props: {
clientId: string;
feeRecipient: string;
feeBps: number;
}) {
const authToken = await getAuthToken();
const res = await fetch(`${UB_BASE_URL}/v1/developer/fees`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"x-client-id-override": props.clientId,
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify({
feeRecipient: props.feeRecipient,
feeBps: props.feeBps,
}),
});

if (!res.ok) {
const text = await res.text();
throw new Error(text);
}

return;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getProject } from "@/api/projects";
import { getTeamBySlug } from "@/api/team";
import { getFees } from "@/api/universal-bridge/developer";
import { redirect } from "next/navigation";
import { PayConfig } from "../../../../../../../components/pay/PayConfig";

Expand All @@ -24,5 +25,32 @@ export default async function Page(props: {
redirect(`/team/${team_slug}`);
}

return <PayConfig project={project} teamId={team.id} teamSlug={team_slug} />;
let fees = await getFees({
clientId: project.publishableKey,
}).catch(() => {
return {
feeRecipient: "",
feeBps: 0,
createdAt: "",
updatedAt: "",
};
});

if (!fees) {
fees = {
feeRecipient: "",
feeBps: 0,
createdAt: "",
updatedAt: "",
};
}

return (
<PayConfig
project={project}
teamId={team.id}
teamSlug={team_slug}
fees={fees}
/>
);
}
Loading
Loading