diff --git a/.github/workflows/nextjs.yml b/.github/workflows/nextjs.yml index cdba1fe..c617b80 100644 --- a/.github/workflows/nextjs.yml +++ b/.github/workflows/nextjs.yml @@ -53,14 +53,14 @@ jobs: with: node-version: "16" cache: ${{ steps.detect-package-manager.outputs.manager }} - #- name: Setup Pages - # uses: actions/configure-pages@v3 - # with: - # Automatically inject basePath in your Next.js configuration file and disable - # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized). - # - # You may remove this line if you want to manage the configuration yourself. - #static_site_generator: next + - name: Setup Pages + uses: actions/configure-pages@v3 + with: + # Automatically inject basePath in your Next.js configuration file and disable + # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized). + + # You may remove this line if you want to manage the configuration yourself. + static_site_generator: next - name: Restore cache uses: actions/cache@v3 with: @@ -79,8 +79,9 @@ jobs: NEXT_PUBLIC_WC_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_WC_PROJECT_ID }} NEXT_PUBLIC_INFURA_API_KEY: ${{ secrets.NEXT_PUBLIC_INFURA_API_KEY }} run: ${{ steps.detect-package-manager.outputs.runner }} next build - #- name: Static HTML export with Next.js - # run: ${{ steps.detect-package-manager.outputs.runner }} next export + # # "next export" is no longer needed when "output: export" is configured in next.config.js + #- name: Static HTML export with Next.js + # run: ${{ steps.detect-package-manager.outputs.runner }} next export - name: Upload artifact uses: actions/upload-pages-artifact@v2 with: diff --git a/next.config.js b/next.config.js index aa1351e..a35bfad 100644 --- a/next.config.js +++ b/next.config.js @@ -1,7 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { output: "export", - basePath: "/test-wagmi-safe-privy", }; module.exports = nextConfig; diff --git a/src/app/page.tsx b/src/app/page.tsx index be2eb91..1891daa 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,23 +1,38 @@ "use client"; +import { useIsContractWallet } from "@/components/hooks/isContractWallet"; import { + storageABI, useStorageRetrieve, useStorageStore, - storageABI, } from "@/generated/wagmi"; -import { Button, Flex, FormControl, Input, Text } from "@chakra-ui/react"; +import { resolveSafeTx } from "@/utils/safe"; +import { safeDecodeLogs } from "@/utils/safeDecodeLogs"; +import { + Button, + Flex, + FormControl, + Input, + Text, + useToast, +} from "@chakra-ui/react"; import { usePrivyWagmi } from "@privy-io/wagmi-connector"; import { useCallback, useEffect, useState } from "react"; import { decodeEventLog } from "viem"; -import { useWaitForTransaction } from "wagmi"; +import { useNetwork, useWaitForTransaction } from "wagmi"; import { WriteContractResult } from "wagmi/actions"; export default function Home() { - const { ready, wallet } = usePrivyWagmi(); + const { ready, wallet: activeWallet, setActiveWallet } = usePrivyWagmi(); + const { chain } = useNetwork(); + + const toast = useToast(); const [newVal, setNewVal] = useState(); const [curVal, setCurVal] = useState(); const [tx, setTx] = useState(); + const isContractWallet = useIsContractWallet(); + const { data, error, status } = useStorageRetrieve(); const { writeAsync } = useStorageStore(); const { data: receipt, isError, isLoading } = useWaitForTransaction(tx); @@ -31,38 +46,45 @@ export default function Home() { useEffect(() => { if (!receipt) return; - const numberChangedEvent = receipt.logs - .map((log) => - decodeEventLog({ - abi: storageABI, - ...log, - }) - ) - .find((e) => (e.eventName = "NumberChanged")); + const numberChangedEvent = safeDecodeLogs(receipt, storageABI).find( + (e) => e?.eventName == "NumberChanged" + ); if (!numberChangedEvent) { console.warn("couldnt find numberchanged event"); return; } console.log(numberChangedEvent); + toast({ + status: "success", + title: "Number updated", + description: `to ${numberChangedEvent.args._new}`, + }); setCurVal(Number(numberChangedEvent.args._new)); - }, [receipt]); + }, [receipt, toast]); const onSubmit = useCallback(async () => { - if (newVal === undefined) return; + if (!activeWallet || !chain || newVal === undefined) return; try { const writeResult = await writeAsync({ args: [BigInt(newVal || 0n)], }); console.info(writeResult); - setTx(writeResult); + if (isContractWallet) { + //try to resolve the underlying transaction + const resolvedTx = await resolveSafeTx(chain.id, writeResult.hash); + if (!resolvedTx) throw new Error("couldn resolve safe tx"); + setTx({ hash: resolvedTx }); + } else { + setTx(writeResult); + } } catch (e: any) { console.error(e); } - }, [newVal, writeAsync]); + }, [activeWallet, chain, newVal, writeAsync, isContractWallet]); - if (!wallet) return Pls connect; + if (!activeWallet) return Pls connect; return (
diff --git a/src/components/LoginButton.tsx b/src/components/LoginButton.tsx index e0c8d8c..45862a5 100644 --- a/src/components/LoginButton.tsx +++ b/src/components/LoginButton.tsx @@ -5,23 +5,23 @@ import { usePrivyWagmi } from "@privy-io/wagmi-connector"; import { useDisconnect } from "wagmi"; export const LoginButton = () => { - const { wallet } = usePrivyWagmi(); + const { wallet: activeWallet } = usePrivyWagmi(); const { connectWallet, ready, authenticated, logout } = usePrivy(); const { disconnect } = useDisconnect(); //const { wallets } = useWallets(); - if (wallet) { + if (activeWallet) { return ( - {wallet.address} + {activeWallet.address}