import { createLazyFileRoute } from "@tanstack/react-router"; import { useState } from "react"; import type { Numbers } from "web3"; import { useStore } from "../store"; import { getFormInputValue, toastError, tryWithToast } from "../utils"; import { padToken, web3 } from "../web3"; export const Route = createLazyFileRoute("/pad-token")({ component: PadTokenPage, }); function PadTokenPage() { const connectedAccount = useStore((state) => state.connectedAccount); const [balance, setBalance] = useState("(nothingness)"); const onBalanceOfFormSubmit: React.FormEventHandler = async ( event ) => { event.preventDefault(); const address = getFormInputValue( event.target as HTMLFormElement, "address" ).trim(); if (!address) { toastError("Balance Of", "Enter an address."); return; } await tryWithToast("Balance Of", async () => { const balanceBN: Numbers = await padToken.methods .balanceOf(address) .call(); setBalance(web3.utils.fromWei(balanceBN, "ether")); }); }; const onMintFormSubmit: React.FormEventHandler = async ( event ) => { event.preventDefault(); if (!connectedAccount) { toastError("Mint", "Connect your wallet first."); return; } const to = getFormInputValue(event.target as HTMLFormElement, "to").trim(); if (!to) { toastError("Mint", "Enter a target address."); return; } const amount = getFormInputValue( event.target as HTMLFormElement, "amount" ).trim(); if (!amount) { toastError("Mint", "Enter an amount."); return; } await tryWithToast("Mint", async () => { await padToken.methods .mint(to, web3.utils.toWei(amount, "ether")) .send({ from: connectedAccount }); }); }; return (

Balance Of

Balance: {balance} PAD

Mint

); }