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

Zomkeez: Update web3.js #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
63 changes: 14 additions & 49 deletions src/mint/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ const getMethodWithCustomName = (methodName) => {
}

const getMintTx = ({ numberOfTokens }) => {
const customMintMethod = getMethodWithCustomName('mint')
if (customMintMethod)
return customMintMethod(numberOfTokens)

console.log("Using hardcoded mint method detection")
const methodNameVariants = ['mint', 'publicMint', 'mintNFTs', 'mintPublic', 'mintSale']
const name = methodNameVariants.find(n => findMethodByName(n) !== undefined)
if (!name) {
alert("Buildship widget doesn't know how to mint from your contract. Contact https://buildship.xyz in Discord to resolve this.")
return undefined

const isZLactive = NFTContract.methods.zomkeezListActive().call()

if (isZLactive) {
return NFTContract.methods.mintZomkeezList(numberOfTokens);
} else {
return NFTContract.methods.mint(numberOfTokens);
}
return NFTContract.methods[findMethodByName(name)](numberOfTokens);
}

const getDefaultMintPrice = () => {
Expand All @@ -53,34 +49,12 @@ const getDefaultMintPrice = () => {
}

export const getMintPrice = async () => {
const matches = Object.keys(NFTContract.methods).filter(key =>
!key.includes("()") && (key.toLowerCase().includes('price') || key.toLowerCase().includes('cost'))
)
switch (matches.length) {
// Use auto-detection only when sure
// Otherwise this code might accidentally use presale price instead of public minting price
case 1:
console.log("Using price method auto-detection")
return NFTContract.methods[matches[0]]().call()
case 0:
const defaultMintPrice = getDefaultMintPrice()
if (defaultMintPrice === undefined) {
alert("Buildship widget doesn't know how to fetch price from your contract. Contact https://buildship.xyz in Discord to resolve this.")
}
return defaultMintPrice
default:
console.log("Using hardcoded price detection")
const methodNameVariants = ['price', 'cost', 'public_sale_price', 'getPrice']
const name = methodNameVariants.find(n => findMethodByName(n) !== undefined)
if (!name) {
const defaultMintPrice = getDefaultMintPrice()
console.log("defaultMintPrice", defaultMintPrice)
if (defaultMintPrice === undefined) {
alert("Buildship widget doesn't know how to fetch price from your contract. Contact https://buildship.xyz in Discord to resolve this.")
}
return defaultMintPrice
}
return NFTContract.methods[findMethodByName(name)]().call();
const isZLactive = NFTContract.methods.zomkeezListActive().call()

if (isZLactive) {
return NFTContract.methods.zomkeezListPrice().call();
} else {
return NFTContract.methods.tokenPrice().call();
}
}

Expand Down Expand Up @@ -109,16 +83,7 @@ export const getMaxSupply = async () => {
if (!NFTContract)
return undefined

const customMaxSupplyMethod = getMethodWithCustomName('maxSupply')
if (customMaxSupplyMethod)
return await customMaxSupplyMethod().call()

if (NFTContract.methods.maxSupply)
return await NFTContract.methods.maxSupply().call()
if (NFTContract.methods.MAX_SUPPLY)
return await NFTContract.methods.MAX_SUPPLY().call()
alert("Widget doesn't know how to fetch maxSupply from your contract. Contact https://buildship.xyz to resolve this.")
return undefined
return await NFTContract.methods.MAX_SUPPLY().call();
}

export const getDefaultMaxTokensPerMint = () => {
Expand Down