Skip to content

Commit

Permalink
feat: integrate mint for project page (#74)
Browse files Browse the repository at this point in the history
* feat: setup get project hook

* feat: populate data in project page

* feat: add mint project checkout functionality

* feat: add toast when minting
  • Loading branch information
marcuspang authored Aug 2, 2023
1 parent f739ca3 commit 0f48ee2
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 90 deletions.
19 changes: 19 additions & 0 deletions hooks/useGetProject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Project } from "@/types/mongo";
import { useQuery } from "wagmi";

async function getProject(id: string): Promise<Project | undefined> {
try {
return fetch(`${process.env.BACKEND_URL}/projects/${id}`).then((res) =>
res.json()
);
} catch (e) {
console.error(e);
return undefined;
}
}

export function useGetProject(id?: string) {
return useQuery(["project", id], () => getProject(id!), {
enabled: Boolean(id)
});
}
21 changes: 21 additions & 0 deletions hooks/useGetUser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { AuthContext } from "@/components/AuthProvider";
import { User } from "@/types/mongo";
import { useContext } from "react";
import { useQuery } from "wagmi";

async function getCurrentUser(userId: string): Promise<User | undefined> {
try {
return fetch(`${process.env.BACKEND_URL}/users/${userId}`).then((res) =>
res.json()
);
} catch (e) {
console.error(e);
return;
}
}

export function useGetUser(userId?: string) {
const { idToken } = useContext(AuthContext);

return useQuery(["users"], () => getCurrentUser(userId!), { enabled: Boolean(userId) });
}
1 change: 0 additions & 1 deletion pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export default function AdminPage() {
const { address, status } = useAccount();
const { chain } = useNetwork();
const { data: onChainProjects } = useRadarEditionsGetEditions({
account: address,
address: isTestnet() ? GOERLI_CONTRACT_ADDRESS : MAINNET_CONTRACT_ADDRESS,
chainId: chain?.id,
enabled: Boolean(chain),
Expand Down
8 changes: 3 additions & 5 deletions pages/api/get-checkout-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ export default async function handler(
title: "RADAR Editions - Create Project",
// description: "Describe your project *with Markdown!*",
// imageUrl: "https://unsplash.it/240/240",
// successCallbackUrl: "string",
// cancelCallbackUrl: "string",
// walletAddress: "string",
// email: "string",
successCallbackUrl: "https://radarlaunch.app",
cancelCallbackUrl: "https://radarlaunch.app",
sendEmailOnCreation: true,
quantity: 1,
// quantity: 1,
metadata: {},
mintMethod: {
name: "createEdition",
Expand Down
63 changes: 63 additions & 0 deletions pages/api/get-mint-checkout-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { GOERLI_CONTRACT_ID, MAINNET_CONTRACT_ID } from "@/constants/paper";
import isTestnet from "@/lib/utils/isTestnet";
import { NextApiRequest, NextApiResponse } from "next";

interface Response {
checkoutLinkIntentUrl: string;
transactionId: string;
estimatedPrice: { value: string; currency: string };
}

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Response | string>
) {
if (req.method !== "POST") {
return res.status(404).send("Not found");
}
try {
const { editionId, value } = req.body;
console.log({ editionId, value });
const options = {
method: "POST",
headers: {
accept: "application/json",
"content-type": "application/json",
Authorization: "Bearer " + process.env.PAPER_API_KEY,
},
body: JSON.stringify({
contractId: isTestnet() ? GOERLI_CONTRACT_ID : MAINNET_CONTRACT_ID,
title: "RADAR Editions - Mint Project",
// description: "Describe your project *with Markdown!*",
// imageUrl: "https://unsplash.it/240/240",
successCallbackUrl: "https://radarlaunch.app",
cancelCallbackUrl: "https://radarlaunch.app",
sendEmailOnCreation: true,
quantity: 1,
metadata: {},
mintMethod: {
name: "mintEdition",
args: {
editionId,
buyer: "$WALLET",
amount: "$QUANTITY",
data: "0x0000000000000000000000000000000000000000000000000000000000000000",
},
payment: { currency: "ETH", value },
},
// contractArgs: "string",
feeBearer: "BUYER",
sendEmailOnTransferSucceeded: true,
}),
};

const response = await fetch(
"https://withpaper.com/api/2022-08-12/checkout-link-intent",
options
).then((response) => response.json());
return res.status(200).send(response);
} catch (e) {
console.log(e);
return res.status(400).send("Error has occured");
}
}
Loading

0 comments on commit 0f48ee2

Please sign in to comment.