-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from SweetmanTech/sweets/heno
Sweets/heno
- Loading branch information
Showing
16 changed files
with
10,944 additions
and
5,028 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
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,75 @@ | ||
import { useEffect, useState } from "react"; | ||
import { BigNumber } from "ethers"; | ||
import { useAccount, useNetwork, useSwitchNetwork } from "wagmi"; | ||
import { zoraCreatorFixedPriceSaleStrategyAddress } from "@zoralabs/protocol-deployments"; | ||
import getNFTsForContract from "../lib/alchemy/getNFTsForContract"; | ||
import getFormattedDrops from "../lib/getFormattedDrops"; | ||
import useUniversalMinter from "./useUniversalMinter"; | ||
import getCalldatas from "../lib/getCalldatas"; | ||
import { ZORA_FEE } from "../lib/consts"; | ||
import { useZoraFixedPriceSaleStrategy } from ".."; | ||
|
||
const useCollection = (collectionAddress: string, chainId: number) => { | ||
const [drops, setDrops] = useState([] as any); | ||
const { mintBatchWithoutFees } = useUniversalMinter(chainId); | ||
const { address } = useAccount(); | ||
const { chain } = useNetwork(); | ||
const defaultMinter = | ||
zoraCreatorFixedPriceSaleStrategyAddress[ | ||
chainId as keyof typeof zoraCreatorFixedPriceSaleStrategyAddress | ||
]; | ||
const { sale } = useZoraFixedPriceSaleStrategy(defaultMinter); | ||
const { switchNetwork } = useSwitchNetwork(); | ||
|
||
const getValues = async () => { | ||
const pricesPromises = drops.map((_: any, index: number) => { | ||
const tokenId = BigNumber.from(index + 1); | ||
return sale(collectionAddress, tokenId.toString()); | ||
}); | ||
const prices = await Promise.all(pricesPromises); | ||
const values = prices.map((price) => | ||
price.pricePerToken.add(ZORA_FEE).toString() | ||
); | ||
return values; | ||
}; | ||
|
||
const collectAll = async (minter = defaultMinter) => { | ||
if (chain?.id !== chainId) { | ||
switchNetwork?.(chainId); | ||
return false; | ||
} | ||
const targets = Array(drops.length).fill(collectionAddress); | ||
const calldatas = getCalldatas( | ||
drops.length, | ||
minter, | ||
address as string, | ||
address as string | ||
); | ||
const values = await getValues(); | ||
const totalValue = values.reduce( | ||
(total, value) => total.add(BigNumber.from(value)), | ||
BigNumber.from(0) | ||
); | ||
const response = await mintBatchWithoutFees( | ||
targets, | ||
calldatas, | ||
values, | ||
totalValue | ||
); | ||
return response; | ||
}; | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
const response = await getNFTsForContract(collectionAddress, chainId); | ||
const formattedDrops = getFormattedDrops(response.nfts, chainId); | ||
setDrops(formattedDrops); | ||
}; | ||
|
||
init(); | ||
}, [collectionAddress, chainId]); | ||
|
||
return { drops, collectAll }; | ||
}; | ||
|
||
export default useCollection; |
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,45 @@ | ||
import { Contract } from "ethers"; | ||
import { useMemo } from "react"; | ||
import { base } from "viem/chains"; | ||
import { zoraUniversalMinterAddress } from "@zoralabs/universal-minter"; | ||
import abi from "../lib/abi/ZoraUniversalMinter.json"; | ||
import { useEthersSigner } from "./useEthersSigner"; | ||
|
||
const useUniversalMinter = (chainId: number = base.id) => { | ||
const universalMinter = | ||
zoraUniversalMinterAddress[ | ||
chainId as keyof typeof zoraUniversalMinterAddress | ||
]; | ||
const signer = useEthersSigner(); | ||
|
||
const universalMinterContract = useMemo( | ||
() => new Contract(universalMinter, abi, signer), | ||
[universalMinter, signer] | ||
); | ||
|
||
const mintBatchWithoutFees = async ( | ||
targets: any[], | ||
calldatas: any[], | ||
values: any[], | ||
value: any | ||
) => { | ||
try { | ||
const tx = await universalMinterContract.mintBatchWithoutFees( | ||
targets, | ||
calldatas, | ||
values, | ||
{ | ||
value, | ||
} | ||
); | ||
const receipt = await tx.wait(); | ||
return receipt; | ||
} catch (error) { | ||
return { error }; | ||
} | ||
}; | ||
|
||
return { mintBatchWithoutFees }; | ||
}; | ||
|
||
export default useUniversalMinter; |
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
Oops, something went wrong.