-
-
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 #30 from elimu-ai/17-add-sponsorship
feat(frontend): add sponsorship
- Loading branch information
Showing
6 changed files
with
136 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function ErrorIndicator({ description }: any) { | ||
return ( | ||
<div className="p-8 bg-orange-800 border-orange-400 border-4 rounded-lg"> | ||
<p>Error: <code>{description}</code></p> | ||
<p className="mt-4">See browser console for more details</p> | ||
</div> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,112 @@ | ||
import LoadingIndicator from "@/components/LoadingIndicator"; | ||
import MainFooter from "@/components/MainFooter"; | ||
import MainHeader from "@/components/MainHeader"; | ||
import Head from "next/head"; | ||
import { useAccount, useSimulateContract, useWriteContract } from "wagmi"; | ||
import { abi } from "../../../../backend/ignition/deployments/chain-84532/artifacts/SponsorshipQueueModule#SponsorshipQueue.json"; | ||
import deployed_addresses from "../../../../backend/ignition/deployments/chain-84532/deployed_addresses.json"; | ||
import { Address, parseEther } from "viem"; | ||
import ErrorIndicator from "@/components/ErrorIndicator"; | ||
|
||
export default function AddSponsorship() { | ||
console.debug("AddSponsorship"); | ||
|
||
const { address, isConnecting, isReconnecting } = useAccount(); | ||
console.debug("address:", address); | ||
console.debug("isConnecting:", isConnecting); | ||
console.debug("isReconnecting:", isReconnecting); | ||
|
||
if (isConnecting || isReconnecting) { | ||
return <LoadingIndicator /> | ||
} | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Sponsors 🫶🏽</title> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" /> | ||
<link href="https://fonts.googleapis.com/css2?family=Londrina+Solid:wght@100;300;400;900&display=swap" rel="stylesheet" /> | ||
</Head> | ||
<MainHeader /> | ||
<main | ||
className={`flex flex-col items-center px-4 sm:px-8 md:px-16 lg:px-32 xl:px-64`} | ||
> | ||
<h1 className="relative flex place-items-center text-4xl"> | ||
Become a Sponsor <span className="animate-pulse">💜</span> | ||
</h1> | ||
|
||
<div className="mt-8"> | ||
Your sponsorship will cover the estimated cost for<br /> | ||
delivering education to one out-of-school child. | ||
</div> | ||
|
||
<div className="mt-8"> | ||
{!address ? ( | ||
<button disabled={true} className="p-8 text-2xl text-zinc-400 bg-zinc-300 rounded-lg"> | ||
<div className="text-6xl rotate-12 mb-4">☝🏽</div> | ||
Connect wallet first | ||
</button> | ||
) : ( | ||
<SimulateContractButton /> | ||
)} | ||
</div> | ||
</main> | ||
<MainFooter /> | ||
</> | ||
); | ||
} | ||
|
||
export function SimulateContractButton() { | ||
console.debug("SimulateContractButton"); | ||
|
||
const deploymentAddress: Address = deployed_addresses["SponsorshipQueueModule#SponsorshipQueue"] as `0x${string}`; | ||
console.debug("deploymentAddress:", deploymentAddress); | ||
|
||
const { isPending, isError, error, isSuccess } = useSimulateContract({ | ||
abi, | ||
address: deploymentAddress, | ||
functionName: "addSponsorship", | ||
value: parseEther("0.002") | ||
}) | ||
console.debug("isPending:", isPending); | ||
console.debug("isError:", isError); | ||
console.debug("error:", error); | ||
console.debug("isSuccess:", isSuccess); | ||
|
||
if (isPending) { | ||
return <button disabled={true} className="p-8 text-2xl bg-purple-200 dark:bg-purple-950 rounded-lg border-purple-400 border-r-4 border-b-4 hover:border-r-8 hover:border-b-8 hover:-translate-y-1"> | ||
<LoadingIndicator /> Simulating... | ||
</button> | ||
} | ||
|
||
if (isError) { | ||
return <ErrorIndicator description={error.name} /> | ||
} | ||
|
||
return <WriteContractButton /> | ||
} | ||
|
||
export function WriteContractButton() { | ||
console.debug("WriteContractButton"); | ||
|
||
const deploymentAddress: Address = deployed_addresses["SponsorshipQueueModule#SponsorshipQueue"] as `0x${string}`; | ||
console.debug("deploymentAddress:", deploymentAddress); | ||
|
||
const { writeContract } = useWriteContract(); | ||
return ( | ||
<button | ||
className="p-8 text-2xl bg-purple-200 dark:bg-purple-950 rounded-lg border-purple-400 border-r-4 border-b-4 hover:border-r-8 hover:border-b-8 hover:-translate-y-1" | ||
onClick={() => | ||
writeContract({ | ||
abi, | ||
address: deploymentAddress, | ||
functionName: "addSponsorship", | ||
value: parseEther("0.002") | ||
}) | ||
} | ||
> | ||
Send 0.02 ETH | ||
</button> | ||
) | ||
} |