Skip to content

Commit

Permalink
Add new actions for eating and praying to the $SPAM God
Browse files Browse the repository at this point in the history
  • Loading branch information
backmeupplz committed Dec 21, 2023
1 parent e6ae1e2 commit b64c3cb
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/components/Mint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function () {
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
const [actionSuccess, setActionSuccess] = useState(false)
const { isConnected } = useAccount()
const signer = useEthersSigner()

Expand All @@ -36,6 +37,44 @@ export default function () {
}
}

async function eatSpam() {
setLoading(true)
setActionSuccess(false)
try {
if (!signer) {
throw new Error('No signer')
}
const contract = Spam__factory.connect(env.VITE_CONTRACT, signer)
const tx = await contract.eatSpam()
await tx.wait()
setActionSuccess(true)
} catch (error) {
console.error(error)
setError(error instanceof Error ? error.message : `${error}`)
} finally {
setLoading(false)
}
}

async function prayToSpamGod() {
setLoading(true)
setActionSuccess(false)
try {
if (!signer) {
throw new Error('No signer')
}
const contract = Spam__factory.connect(env.VITE_CONTRACT, signer)
const tx = await contract.prayToSpamGod()
await tx.wait()
setActionSuccess(true)
} catch (error) {
console.error(error)
setError(error instanceof Error ? error.message : `${error}`)
} finally {
setLoading(false)
}
}

return (
<>
<input
Expand All @@ -62,6 +101,20 @@ export default function () {
{loading ? ' 🤔' : ''}The mint $SPAM button
</button>
)}
<button
class="btn btn-primary btn-wide btn-lg"
onClick={eatSpam}
disabled={loading}
>
{loading ? ' 🤔' : ''}Eat some $SPAM
</button>
<button
class="btn btn-primary btn-wide btn-lg"
onClick={prayToSpamGod}
disabled={loading}
>
{loading ? ' 🤔' : ''}Pray to the $SPAM God 🙏
</button>
{success && (
<div role="alert" class="alert alert-success break-all">
<span role="img" aria-label="success">
Expand All @@ -70,6 +123,14 @@ export default function () {
You now have +{amount} $SPAM.
</div>
)}
{actionSuccess && (
<div role="alert" class="alert alert-success break-all">
<span role="img" aria-label="success">
🎉
</span>{' '}
You did something with $SPAM successfully!
</div>
)}
{error && (
<div role="alert" class="alert alert-error break-all">
{error}
Expand Down

0 comments on commit b64c3cb

Please sign in to comment.