From 04b7ff77498488b8e6d3e5b4e0b90568b751fee7 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 9 Jan 2023 12:41:02 -0800 Subject: [PATCH] new abi, better prop inputs, better ux for stuff --- src/abi/main.json | 19 ++++++++++++ src/index.js | 27 +++++++++------- src/template/Sections.jsx | 65 ++++++++++++++++++++++++++++----------- 3 files changed, 82 insertions(+), 29 deletions(-) diff --git a/src/abi/main.json b/src/abi/main.json index 427259f..6d0babe 100644 --- a/src/abi/main.json +++ b/src/abi/main.json @@ -390,6 +390,25 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "unaboomersMinted", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "unaboomersRadicalized", diff --git a/src/index.js b/src/index.js index a38d94d..79cf7ff 100644 --- a/src/index.js +++ b/src/index.js @@ -37,24 +37,29 @@ const wagmiClient = createClient({ webSocketProvider }); +let chainId; +let contractAddress; + +if (process.env.CHAIN == '5') { + chainId = 5; + contractAddress = '0x31205d753eC2784160F70E6E6177581c7721bD0E'; +} else if (process.env.CHAIN == '1') { + chainId = 1; + contractAddress = ''; +} else { + chainId = 1337; + contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'; +} + ReactDOM.createRoot(document.getElementById("root")).render( - +
- +
); - - -// goerli -// 5 -// 0x31205d753ec2784160f70e6e6177581c7721bd0e - -// local -// 1337 -// 0x5FbDB2315678afecb367f032d93F642f64180aa3 \ No newline at end of file diff --git a/src/template/Sections.jsx b/src/template/Sections.jsx index f7e96f7..ae43ad4 100644 --- a/src/template/Sections.jsx +++ b/src/template/Sections.jsx @@ -124,7 +124,7 @@ class GameMap extends React.Component {

Metaverse Map

{this.props.unaboomersRadicalized} / {this.props.unaboomerMaxSupply} Unaboomers radicalized and ready to terrorize the metaverse.
- {this.props.unaboomerMaxSupply - this.props.unaboomerMaxSurvivorCount} potential Unaboomers remain.
+ {this.props.unaboomerMaxSupply - this.props.unaboomerMaxSurvivorCount - this.props.unaboomersRadicalized} potential Unaboomers remain.
This round will end and the project will fully start when {this.props.unaboomerMaxSurvivorCount} or less Unaboomers remain standing.

{this.props.unaboomersRadicalized > 0 && ( @@ -174,7 +174,7 @@ function Section3(props) { sendBombPreviewAmount: 1, unaboomerPrice: 0, bombPrice: ethers.utils.parseEther('.01'), - unaboomerBalance: 0, + unaboomersMinted: 0, bombBalance: 0, unaboomersRadicalized: 0, bombsAssembled: 0, @@ -186,7 +186,8 @@ function Section3(props) { unaboomerMaxSupply: 0, unaboomerMaxSurvivorCount: 0, unaboomerMaxMintPerWallet: 0, - readWTF: false + readWTF: false, + balancesFetched: false }); function handleStateChange(obj) { setOptions(preState => ({...preState , ...obj})); @@ -238,7 +239,7 @@ function Section3(props) { contracts: [ { ...defOpt, - functionName: 'unaboomerBalance', + functionName: 'unaboomersMinted', args: [address] }, { @@ -271,13 +272,14 @@ function Section3(props) { cacheTime: 6_000, onSuccess(data) { handleStateChange({ - unaboomerBalance: Number(data[0]), + unaboomersMinted: Number(data[0]), bombBalance: Number(data[1]), unaboomersRadicalized: Number(data[2]), bombsAssembled: Number(data[3]), bombsExploded: Number(data[4]), unaboomersKilled: Number(data[5]), - leaderboardPointer: Number(data[6]) + leaderboardPointer: Number(data[6]), + balancesFetched: true }); } }); @@ -312,7 +314,7 @@ function Section3(props) { const radicalizeBoomersPrepare = usePrepareContractWrite({ address: contractAddress, abi: MainABI, - enabled: isConnected, + enabled: isConnected && options.unaboomersMinted < options.unaboomerMaxMintPerWallet && options.unaboomerAmount > 0 && options.balancesFetched, functionName: 'radicalizeBoomers', args: [options.unaboomerAmount], overrides: { @@ -320,11 +322,16 @@ function Section3(props) { value: BigNumber.from((options.unaboomerPrice * options.unaboomerAmount).toString()) } }); - const radicalizeBoomersWrite = useContractWrite(radicalizeBoomersPrepare.config); + const radicalizeBoomersWrite = useContractWrite({ + ...radicalizeBoomersPrepare.config, + onError(data) { + if (data.message.startsWith('user rejected transaction')) NotificationManager.info(`tx cancelled`, 'ok', 4000); + } + }); const assembleBombsPrepare = usePrepareContractWrite({ address: contractAddress, abi: MainABI, - enabled: isConnected, + enabled: isConnected && options.bombAmount > 0, functionName: 'assembleBombs', args: [options.bombAmount], overrides: { @@ -332,16 +339,26 @@ function Section3(props) { value: BigNumber.from((options.bombPrice * options.bombAmount).toString()) } }); - const assembleBombsWrite = useContractWrite(assembleBombsPrepare.config); + const assembleBombsWrite = useContractWrite({ + ...assembleBombsPrepare.config, + onError(data) { + if (data.message.startsWith('user rejected transaction')) NotificationManager.info(`tx cancelled`, 'ok', 4000); + } + }); const sendBombsPrepare = usePrepareContractWrite({ address: contractAddress, abi: MainABI, enabled: isConnected && options.bombBalance > 0, - staleTime: 2_000, functionName: 'sendBombs', + cacheTime: 1000, args: [options.sendBombAmount] }); - const sendBombsWrite = useContractWrite(sendBombsPrepare.config); + const sendBombsWrite = useContractWrite({ + ...sendBombsPrepare.config, + onError(data) { + if (data.message.startsWith('user rejected transaction')) NotificationManager.info(`tx cancelled`, 'ok', 4000); + } + }); useWaitForTransaction({ hash: sendBombsWrite.data?.hash, enabled: sendBombsWrite.status === 'success', @@ -431,24 +448,30 @@ function Section3(props) {

Radicalize a Boomer

Radicalizing a boomer will mint ERC-721 BOOMR tokens with images of a pixel art Web3 Unaboomers.

-

You have {options.unaboomerBalance} / {options.unaboomerMaxMintPerWallet} BOOMR

+

You have {options.unaboomersMinted} / {options.unaboomerMaxMintPerWallet} BOOMR

- {options.unaboomerBalance < options.unaboomerMaxMintPerWallet && options.unaboomersKilled + options.unaboomersRadicalized < options.unaboomerMaxSupply && ( + {options.unaboomersMinted < options.unaboomerMaxMintPerWallet && options.unaboomersKilled + options.unaboomersRadicalized < options.unaboomerMaxSupply && ( <>

- radicalizeBoomersWrite.write?.()}> + { + radicalizeBoomersWrite.write?.(); + handleStateChange({ + unaboomerAmount: 1, + unaboomerPreviewAmount: 1 + }) + }}> {radicalizeBoomersWrite.isLoading && <>minting {options.unaboomerAmount}} {radicalizeBoomersWrite.isIdle && <>mint {options.unaboomerPreviewAmount} ({ethers.utils.formatEther((options.unaboomerPrice * options.unaboomerPreviewAmount).toString())} Ξ)} {radicalizeBoomersWrite.isSuccess && <>sent} {radicalizeBoomersWrite.isError && <>error}

- handleStateChange({unaboomerAmount: v})} onChange={(v) => { + handleStateChange({unaboomerAmount: v})} onChange={(v) => { handleStateChange({unaboomerPreviewAmount: v}); radicalizeBoomersWrite.reset(); }} /> - ) || options.unaboomerBalance < options.unaboomerMaxMintPerWallet && options.unaboomersKilled + options.unaboomersRadicalized < options.unaboomerMaxSupply && ( + ) || options.unaboomersMinted == options.unaboomerMaxMintPerWallet && options.unaboomersKilled + options.unaboomersRadicalized < options.unaboomerMaxSupply && (

max per wallet reached

) || (

max supply reached

@@ -479,7 +502,13 @@ function Section3(props) { {options.bombBalance > 0 && (<>

- sendBombsWrite.write?.()}> + { + sendBombsWrite.write?.(); + handleStateChange({ + sendBombAmount: 1, + sendBombPreviewAmount: 1 + }); + }}> {sendBombsWrite.isLoading && <>sending {options.sendBombAmount}} {sendBombsWrite.isIdle && <>send {options.sendBombPreviewAmount} (~0 Ξ)} {sendBombsWrite.isSuccess && <>sent}