-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate mint for project page (#74)
* 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
1 parent
f739ca3
commit 0f48ee2
Showing
7 changed files
with
227 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.