Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech322/bonasi mint #132

Merged
merged 6 commits into from
Oct 8, 2024
Merged
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
4,815 changes: 0 additions & 4,815 deletions package-lock.json

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
"@pushprotocol/uiweb": "^1.3.8",
"@stackso/js-core": "^0.3.1",
"@vercel/analytics": "^1.0.1",
"@zoralabs/protocol-deployments": "^0.1.8",
"@zoralabs/universal-minter": "^0.2.16",
"@zoralabs/zorb": "^0.1.0",
"@zoralabs/protocol-deployments": "^0.2.2",
"@zoralabs/protocol-sdk": "^0.9.0",
"axios": "^1.2.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "5.0.0",
"firebase": "10.3.0",
"framer-motion": "^9.0.2",
"joi": "^17.12.0",
Expand Down Expand Up @@ -59,6 +58,7 @@
"eslint-config-next": "14.2.4",
"eslint-config-prettier": "^8.5.0",
"postcss": "^8",
"prettier": "3.3.3",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
Expand Down
40 changes: 35 additions & 5 deletions src/components/CollectDropButton/CollectDropButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
const CollectDropButton = ({ className = "" }: { className?: string }) => (
<button type="button" className={`${className} bg-darkgray py-[3px] w-full`} disabled>
Collect
</button>
)
import { toast } from "react-toastify"
import { Address } from "viem"
import useCollectDrop from "@/hooks/useCollectDrop"

const CollectDropButton = ({
className = "",
address,
tokenId,
chainId,
}: {
className?: string
address: Address
tokenId: number
chainId: number
}) => {
const { collect, loading } = useCollectDrop()

const handleClick = async () => {
const response = await collect(address, tokenId, chainId)
if (!response) return
toast.success("Collected!")
}

return (
<button
type="button"
onTouchStart={handleClick}
onClick={handleClick}
className={`${className} bg-darkgray py-[3px] w-full`}
sweetmantech marked this conversation as resolved.
Show resolved Hide resolved
disabled={loading}
>
{loading ? `Collecting...` : "Collect"}
</button>
)
}

export default CollectDropButton
8 changes: 4 additions & 4 deletions src/components/Core/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ function Icon({
size <= 20
? styles.sizes.mini
: size < 25
? styles.sizes.small
: size < 40
? styles.sizes.medium
: styles.sizes.large
? styles.sizes.small
: size < 40
? styles.sizes.medium
: styles.sizes.large
}
${!noHighlights && styles?.variants?.[variant]?.highlight}
${className}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Core/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function TextArea({
className={`text-gray_1 w-full border-[2px] !border-gray_1 bg-black
focus:ring-0 focus:border-gray_1
${className || ""} ${
hookToForm && fieldError && fieldError?.message ? clasNameError : ""
}`}
hookToForm && fieldError && fieldError?.message ? clasNameError : ""
}`}
{...(!hookToForm && {
value,
onChange,
Expand Down
9 changes: 8 additions & 1 deletion src/components/Pages/Web3Page/BonsaiSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import CollectDropButton from "@/components/CollectDropButton"
import DropCollect from "@/components/DropCollect"
import { BONSAI_DROP_ADDRESS, IS_TESTNET } from "@/lib/consts"
import data from "@/lib/zora-drops"
import { Address } from "viem"
import { base, baseSepolia } from "viem/chains"

const BonsaiSection = ({ isPopup }) => (
<DropCollect
Expand All @@ -9,7 +12,11 @@ const BonsaiSection = ({ isPopup }) => (
isPopup={isPopup}
animationUrl={data[12].ipfs}
>
<CollectDropButton />
<CollectDropButton
chainId={IS_TESTNET ? baseSepolia.id : base.id}
tokenId={3}
address={BONSAI_DROP_ADDRESS as Address}
/>
</DropCollect>
)

Expand Down
65 changes: 65 additions & 0 deletions src/hooks/useCollectDrop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import handleTxError from "@/lib/handleTxError"
import { useState } from "react"
import { Address } from "viem"
import getCollectorClient from "@/lib/zora/getCollectorClient"
import getToken from "@/lib/zora/getToken"
import usePrivySendTransaction from "./usePrivySendTransaction"
import useConnectedWallet from "./useConnectedWallet"
import usePreparePrivyWallet from "./usePreparePrivyWallet"

const useCollectDrop = () => {
const { prepare } = usePreparePrivyWallet()
const { connectedWallet } = useConnectedWallet()
const { sendTransaction } = usePrivySendTransaction()
const [loading, setLoading] = useState(false)

const collect = async (dropAddress: Address, tokenId: number, chainId: number) => {
try {
if (!(await prepare(chainId))) return false
setLoading(true)

const { token }: any = await getToken(dropAddress, "1155", tokenId, chainId)
const { salesConfig } = token
const { mintFee } = salesConfig
sweetmantech marked this conversation as resolved.
Show resolved Hide resolved

const collectorClient = getCollectorClient(chainId)
const { parameters } = await collectorClient.mint({
tokenContract: dropAddress,
mintType: "1155",
quantityToMint: 1,
minterAccount: connectedWallet as Address,
tokenId,
})

const { abi, functionName, args, address: minter } = parameters

const response = await sendTransaction(
minter,
chainId,
abi,
functionName,
args,
mintFee,
"HENO.WEB3",
"COLLECT",
)
const { error } = response as any
sweetmantech marked this conversation as resolved.
Show resolved Hide resolved
if (error) {
setLoading(false)
return false
}
setLoading(false)
return response
} catch (error) {
handleTxError(error)
return { error }
}
sweetmantech marked this conversation as resolved.
Show resolved Hide resolved
}
sweetmantech marked this conversation as resolved.
Show resolved Hide resolved

return {
collect,
loading,
}
}

export default useCollectDrop
4 changes: 2 additions & 2 deletions src/hooks/usePreparePrivyWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import useConnectedWallet from "./useConnectedWallet"

const usePreparePrivyWallet = () => {
const { ready, user, login, authenticated } = usePrivy()
const { wallet } = useConnectedWallet() as any
const { wallet, connectedWallet } = useConnectedWallet() as any

const prepare = async (chainId: any = CHAIN_ID) => {
if (!user && ready && !authenticated) {
if (!user && ready && !authenticated && !connectedWallet) {
login()
return false
}
Expand Down
19 changes: 19 additions & 0 deletions src/lib/consts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,22 @@ export const COLLECTIONS = [
type: "ERC1155",
},
]

export const zoraUniversalMinterAddress = {
1: "0x308E190d70c7d1C6Ed569554bCe73Dc3F4ad359A",
5: "0x1Eb7Bf3a08784D7cB08CC2AE1448012C0c02bDa2",
10: "0x97eb05B8db496B12244BCcf17CF377d00a99b67a",
420: "0x39C51a7957651ea176733F19125BD9c253894D6F",
424: "0xF82286760a953D2Bad7D6F2F0da458Ac20f955D3",
999: "0xD9bC36841C259f07924e73cF08d5a2c92d53639B",
8453: "0x308E190d70c7d1C6Ed569554bCe73Dc3F4ad359A",
42161: "0xC6899816663891D7493939d74d83cb7f2BBcBB16",
58008: "0xE9BaDfb9a1658cDF67D8c4631a7f22610C013319",
81457: "0xC6899816663891D7493939d74d83cb7f2BBcBB16",
84531: "0x418B87c2C9579d27FC3D66605545AB9889737E60",
421614: "0x308E190d70c7d1C6Ed569554bCe73Dc3F4ad359A",
7777777: "0xF482C51346f3c77673dc619F243Eb8B09E9A954E",
11155111: "0x0ef82DaB14798E63F1B99479Ba689e3f6A6fEb6C",
168587773: "0xa718BD919eeA529ac75EEf2cf33363AF211f09f4",
999999999: "0xD662FB0fB00261C039441EF49Dbab154d7c533bD",
}
sweetmantech marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions src/lib/zora/getCollectorClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createCollectorClient } from "@zoralabs/protocol-sdk"
import { getPublicClient } from "../clients"

const getCollectorClient = (chainId: number) => {
const publicClient = getPublicClient(chainId) as any
const collectorClient = createCollectorClient({
chainId,
publicClient,
})

return collectorClient
}

export default getCollectorClient
27 changes: 27 additions & 0 deletions src/lib/zora/getToken.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Address } from "viem"
import getCollectorClient from "./getCollectorClient"

const getToken = async (
collectionAddress: Address,
mintType: any,
tokenId: any,
chainId: number,
) => {
const collectorClient = getCollectorClient(chainId)

const tokenInfo: any = {
tokenContract: collectionAddress,
mintType,
}

if (mintType === "1155") tokenInfo.tokenId = tokenId

const { token, prepareMint } = await collectorClient.getToken(tokenInfo)

return {
token,
prepareMint,
}
}
sweetmantech marked this conversation as resolved.
Show resolved Hide resolved

export default getToken
2 changes: 1 addition & 1 deletion src/lib/zora/getUniversalMinter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { zoraUniversalMinterAddress } from "@zoralabs/universal-minter"
import { zoraUniversalMinterAddress } from "@/lib/consts"

const getUniversalMinter = (chainId) =>
zoraUniversalMinterAddress[chainId as keyof typeof zoraUniversalMinterAddress]
Expand Down
14 changes: 12 additions & 2 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ body {
background-color: black;
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell,
Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
font-family:
-apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Oxygen,
Ubuntu,
Cantarell,
Fira Sans,
Droid Sans,
Helvetica Neue,
sans-serif;
}

body::-webkit-scrollbar {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2020",
"lib": [
"dom",
"dom.iterable",
Expand Down
Loading
Loading