Skip to content

Commit

Permalink
Merge pull request #5 from damianmarti/update-home-containers-after-d…
Browse files Browse the repository at this point in the history
…eploy

Update home containers after deploy a new one
  • Loading branch information
damianmarti authored Apr 28, 2024
2 parents e4cb6b0 + ffae4a2 commit c36df66
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter } from "next/navigation";
import type { NextPage } from "next";
import { gql, useQuery } from "urql";
import { parseEther } from "viem";
import { useAccount } from "wagmi";
import { useAccount, useWaitForTransaction } from "wagmi";
import { KudzuContainer } from "~~/components/KudzuContainer";
import { Address, AddressInput } from "~~/components/scaffold-eth";
import { useScaffoldContractRead, useScaffoldContractWrite } from "~~/hooks/scaffold-eth";
Expand Down Expand Up @@ -59,11 +59,28 @@ const Home: NextPage = () => {
},
});

const { writeAsync: deployContainer } = useScaffoldContractWrite({
const [loadingCointainers, setLoadingContainers] = useState(false);

const { writeAsync: deployContainer, data: deployData } = useScaffoldContractWrite({
contractName: "BasedKudzuContainerForSaleFactory",
functionName: "create",
args: [connectedAddress],
value: parseEther("0.00005"),
onSuccess: () => {
setLoadingContainers(true);
},
});

useWaitForTransaction({
hash: deployData?.hash,
onSuccess: async data => {
const log = data?.logs[3];
if (log && log.topics[2]) {
const contractAddress = `0x${log.topics[2].substring(26)}`;
containersData?.containers?.items?.push({ contract: contractAddress });
}
setLoadingContainers(false);
},
});

const router = useRouter();
Expand Down Expand Up @@ -161,7 +178,7 @@ const Home: NextPage = () => {
>
🧫 deploy a kudzu container smart contract
</button>

{loadingCointainers && <p>Loading new container...</p>}
{connectedAddress && containerRender}
</div>
<div className="divider p-12"></div>
Expand Down

0 comments on commit c36df66

Please sign in to comment.