Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
techeng322 committed Oct 8, 2024
1 parent 0255b8e commit a3c9791
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 6 deletions.
38 changes: 33 additions & 5 deletions src/components/CollectDropButton/CollectDropButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
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,
chainId,
}: {
className?: string
address: Address
chainId: number
}) => {
const { collect, loading } = useCollectDrop()

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

return (
<button
type="button"
onTouchStart={handleClick}
onClick={handleClick}
className={`${className} bg-darkgray py-[3px] w-full`}
disabled={true}
>
{loading ? `Collecting...` : "Collect"}
</button>
)
}

export default CollectDropButton
8 changes: 7 additions & 1 deletion src/components/Pages/Web3Page/BonasiSection.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 BonasiSection = ({ isPopup }) => (
<DropCollect
Expand All @@ -9,7 +12,10 @@ const BonasiSection = ({ isPopup }) => (
isPopup={isPopup}
animationUrl={data[12].ipfs}
>
<CollectDropButton />
<CollectDropButton
chainId={IS_TESTNET ? baseSepolia.id : base.id}
address={BONSAI_DROP_ADDRESS as Address}
/>
</DropCollect>
)

Expand Down
79 changes: 79 additions & 0 deletions src/hooks/useCollectDrop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { HYDROPLANING_DROP_ADDRESS, ZORA_FEE, HYDROPLANING_REWARDS_RECIPIENT } from "@/lib/consts"
import handleTxError from "@/lib/handleTxError"
import { useState } from "react"
import { BigNumber } from "ethers"
import getEncodedMinterArgs from "@/lib/zora/getEncodedMinterArgs"
import {
zoraCreator1155ImplABI,
zoraCreatorFixedPriceSaleStrategyAddress,
} from "@zoralabs/protocol-deployments"
import get1155SaleStatus from "@/lib/get1155SaleStatus"
import { Address } from "viem"
import usePrivySendTransaction from "./usePrivySendTransaction"
import useConnectedWallet from "./useConnectedWallet"
import usePreparePrivyWallet from "./usePreparePrivyWallet"
import getCollectorClient from "@/lib/zora/getCollectorClient"
import getToken from "@/lib/zora/getToken"

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
if (!connectedWallet) return false

setLoading(true)

const { token } = await getToken(dropAddress, '1155', tokenId, chainId)

console.log("ZIAD", token)

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

// const response = await sendTransaction(
// HYDROPLANING_DROP_ADDRESS,
// chainId,
// zoraCreator1155ImplABI,
// "mint",
// [
// zoraCreatorFixedPriceSaleStrategyAddress[chainId],
// 1,
// 1,
// [HYDROPLANING_REWARDS_RECIPIENT],
// minterArguments,
// ],
// totalFee,
// "HENO.WEB3",
// "COLLECT",
// )
// const { error } = response as any
// if (error) {
// setLoading(false)
// return false
// }
setLoading(false)
return true
} catch (error) {
handleTxError(error)
return { error }
}
}

return {
collect,
loading,
}
}

export default useCollectDrop
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 { getPublicClient } from "../clients"
import { createCollectorClient } from '@zoralabs/protocol-sdk'

const getCollectorClient = (chainId: number) => {
const publicClient = getPublicClient(chainId)
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 getCollectorClient from './getCollectorClient'
import { Address } from 'viem'

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,
}
}

export default getToken

0 comments on commit a3c9791

Please sign in to comment.