From c4a84c9f0f3f2c5db3bb1a54e08bb3d33249435b Mon Sep 17 00:00:00 2001 From: Jen <60794961+jennyg0@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:54:32 -0400 Subject: [PATCH] updates --- .../src/components/SendTransaction.svelte | 56 ++++--- .../src/components/WriteContract.svelte | 33 ++-- .../src/components/BlockNumber.svelte | 24 ++- .../src/components/EstimateGas.svelte | 4 +- .../src/components/FindBalance.svelte | 45 ++++-- .../src/components/NetworkSwitcher.svelte | 39 +++-- .../src/components/ReadContracts.svelte | 2 +- .../src/components/ReadTokenBalance.svelte | 4 +- .../src/components/ReadTokenSupply.svelte | 3 +- .../src/components/SendTransaction.svelte | 44 +++--- .../src/components/SignMessage.svelte | 3 +- .../src/components/SignTypedData.svelte | 4 +- .../src/components/Token.svelte | 83 +++++++--- .../src/components/WatchContractEvents.svelte | 42 ++--- .../WatchPendingTransactions.svelte | 29 +++- .../src/components/WriteContract.svelte | 12 +- .../components/WriteContractPrepared.svelte | 146 +++++++++--------- .../src/utils/contracts.ts | 4 +- .../svelte/vite-wagmi-web3modal/src/wagmi.ts | 5 +- .../vite-wagmi/src/components/Connect.svelte | 16 +- .../src/components/EstimateGas.svelte | 4 +- .../src/components/NetworkSwitcher.svelte | 1 - .../vite-wagmi/src/components/Token.svelte | 2 +- .../components/WriteContractPrepared.svelte | 3 +- templates/svelte/vite-wagmi/src/wagmi.ts | 5 +- 25 files changed, 378 insertions(+), 235 deletions(-) diff --git a/templates/svelte/vite-ethers/src/components/SendTransaction.svelte b/templates/svelte/vite-ethers/src/components/SendTransaction.svelte index eb4db20..d57f540 100644 --- a/templates/svelte/vite-ethers/src/components/SendTransaction.svelte +++ b/templates/svelte/vite-ethers/src/components/SendTransaction.svelte @@ -1,33 +1,45 @@
- {blockNumber?.toString()} + {#if blockNumber !== null} + {blockNumber.toString()} + {:else} + Loading... + {/if}
diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/EstimateGas.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/EstimateGas.svelte index b6fbb59..263c2c4 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/EstimateGas.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/EstimateGas.svelte @@ -55,12 +55,12 @@
+ + -
{balance?.formatted || ""}
- {#if error} -
Error: {error?.message}
+
{$formattedBalance}
+ {#if $error} +
Error: {$error?.message}
{/if} diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/NetworkSwitcher.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/NetworkSwitcher.svelte index 2569e84..67613ae 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/NetworkSwitcher.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/NetworkSwitcher.svelte @@ -1,27 +1,42 @@ -
- Connected to {network.chain?.name ?? network.chain?.id} - {#if network.chain?.unsupported} - (unsupported) - {/if} + Connected to {currentChain?.name ?? currentChain?.id}

Switch to: - {#each network.chains as item (item.id)} - {/each} diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/ReadContracts.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/ReadContracts.svelte index 208d1e3..5bf3add 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/ReadContracts.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/ReadContracts.svelte @@ -9,7 +9,7 @@ $: ({ account } = $wagmiStore); const { state: asyncState, execute: fetchContracts } = useAsync(async () => { - return await readContracts({ + return await readContracts(wagmiConfig, { contracts: [ { ...daiContractConfig, diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/ReadTokenBalance.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/ReadTokenBalance.svelte index 4b31bc7..314511e 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/ReadTokenBalance.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/ReadTokenBalance.svelte @@ -1,7 +1,7 @@ + + + + +
-
- - -
- {#if inProgress} -
Fetching token...
- {:else if token} -
{stringify(token, null, 4)}
- {:else if error} -
Error: {error?.message}
+ {#if $inProgress} + Fetching token... + {:else if $token} +
{JSON.stringify($token, (key, value) => typeof value === 'bigint' ? value.toString() : value, 4)}
+ {:else if $error} + Error: {$error.message} {/if}
diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/WatchContractEvents.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/WatchContractEvents.svelte index eb03cb1..35acc66 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/WatchContractEvents.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/WatchContractEvents.svelte @@ -1,29 +1,35 @@
- {events.length} DAI `Transfer`s logged - - {events + {$events.length} DAI `Transfer`s logged +
+    {$events
+      .slice() 
       .reverse()
-      .map((log) => stringify(log))
-      .join("\n\n\n\n")}
+      .map((log) => JSON.stringify(log, null, 2)) 
+      .join('\n\n\n\n')}
+    
diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/WatchPendingTransactions.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/WatchPendingTransactions.svelte index d2e10fe..badb3d4 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/WatchPendingTransactions.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/WatchPendingTransactions.svelte @@ -1,17 +1,32 @@
- {transactionHashes.length} transaction hashes - - {transactionHashes.reverse().join("\n")} + {$reversedTransactionHashes.length} transaction hashes +
{$reversedTransactionHashes.join('\n')}
diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/WriteContract.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/WriteContract.svelte index 9341f41..88e083c 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/WriteContract.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/WriteContract.svelte @@ -4,22 +4,22 @@ import { stringify } from "../utils/formatters"; import { writeContract as wagmiWriteContract, - waitForTransaction, + waitForTransactionReceipt, } from "@wagmi/core"; + import { wagmiConfig } from "../wagmi"; let amount: string | null = null; const { state: transactionState, execute: writeContract } = useAsync( async () => { - // random address for testing, replace with contract address that you want to allow to spend your tokens const spender = "0xa1cf087DB965Ab02Fb3CFaCe1f5c63935815f044"; - const result = await wagmiWriteContract({ + const result = await wagmiWriteContract(wagmiConfig, { ...daiContractConfig, functionName: "approve", args: [spender, BigInt(amount!)], }); - waitForReceipt(result.hash); + waitForReceipt(result); return result; } ); @@ -27,7 +27,7 @@ const { state: receiptState, execute: waitForReceipt } = useAsync( async (transactionHash) => { - return await waitForTransaction({ hash: transactionHash }); + return await waitForTransactionReceipt(wagmiConfig, { hash: transactionHash }); } ); $: ({ @@ -47,7 +47,7 @@ {#if inProgress}
Transaction pending...
{:else if transaction} -
Transaction Hash: {transaction?.hash}
+
Transaction Hash: {transaction}
Transaction Receipt: {#if receiptInProgress} diff --git a/templates/svelte/vite-wagmi-web3modal/src/components/WriteContractPrepared.svelte b/templates/svelte/vite-wagmi-web3modal/src/components/WriteContractPrepared.svelte index 2ed2cb2..4b3e3c1 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/components/WriteContractPrepared.svelte +++ b/templates/svelte/vite-wagmi-web3modal/src/components/WriteContractPrepared.svelte @@ -1,86 +1,92 @@ -
-
- - -
+
+ + +
- {#if inProgress} -
Transaction pending...
- {:else if transaction} -
-
Transaction Hash: {transaction?.hash}
-
- Transaction Receipt: - {#if receiptInProgress} - pending... - {/if} -
{stringify(receipt, null, 2)}
-
-
+
+ {#if $simulateError} + Simulation Error: {$simulateError.message} {/if} - - {#if prepareError} -
Preparing Transaction Error: {prepareError?.message}
+ {#if $isPending} + Check wallet... {/if} - {#if error} -
Error: {error?.message}
+ {#if $transactionHash} +
Transaction Hash: {$transactionHash}
+ {#if $receipt} +
+ Transaction Receipt:
{JSON.stringify($receipt, null, 2)}
+
+ {/if} {/if} - {#if receiptError} -
Receipt Error: {receiptError?.message}
+ {#if $error} + Error: {$error.message} {/if}
diff --git a/templates/svelte/vite-wagmi-web3modal/src/utils/contracts.ts b/templates/svelte/vite-wagmi-web3modal/src/utils/contracts.ts index 5e2952e..6c1020b 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/utils/contracts.ts +++ b/templates/svelte/vite-wagmi-web3modal/src/utils/contracts.ts @@ -1,6 +1,6 @@ -import { erc20ABI } from "@wagmi/core"; +import { erc20Abi } from "viem"; export const daiContractConfig = { address: "0x604F0416e788779edB06c1A74a75FAad38384C6E", // zkSync Era Sepolia Testnet DAI token address - abi: erc20ABI, + abi: erc20Abi, } as const; diff --git a/templates/svelte/vite-wagmi-web3modal/src/wagmi.ts b/templates/svelte/vite-wagmi-web3modal/src/wagmi.ts index 2906e43..ca443a2 100644 --- a/templates/svelte/vite-wagmi-web3modal/src/wagmi.ts +++ b/templates/svelte/vite-wagmi-web3modal/src/wagmi.ts @@ -49,11 +49,13 @@ export const chains: Chain[] = [ export const defaultChain = import.meta.env.MODE === "development" ? zksyncSepoliaTestnet : zksync; export const wagmiConfig = createConfig({ - chains: [zksync, zksyncSepoliaTestnet], + chains: chains.length > 0 ? (chains as [Chain, ...Chain[]]) : [defaultChain], connectors: [injected(), coinbaseWallet(), metaMask()], transports: { [zksync.id]: http(), [zksyncSepoliaTestnet.id]: http(), + 270: http(), + 260: http(), }, }) @@ -86,7 +88,6 @@ export function createWagmiStore() { account: getAccount(wagmiConfig), }); - function setField( field: K, value: WagmiStore[K] diff --git a/templates/svelte/vite-wagmi/src/components/Connect.svelte b/templates/svelte/vite-wagmi/src/components/Connect.svelte index 924cfe9..9849bd7 100644 --- a/templates/svelte/vite-wagmi/src/components/Connect.svelte +++ b/templates/svelte/vite-wagmi/src/components/Connect.svelte @@ -1,25 +1,15 @@ diff --git a/templates/svelte/vite-wagmi/src/components/EstimateGas.svelte b/templates/svelte/vite-wagmi/src/components/EstimateGas.svelte index b6fbb59..263c2c4 100644 --- a/templates/svelte/vite-wagmi/src/components/EstimateGas.svelte +++ b/templates/svelte/vite-wagmi/src/components/EstimateGas.svelte @@ -55,12 +55,12 @@
diff --git a/templates/svelte/vite-wagmi/src/wagmi.ts b/templates/svelte/vite-wagmi/src/wagmi.ts index bd889f1..cb5257d 100644 --- a/templates/svelte/vite-wagmi/src/wagmi.ts +++ b/templates/svelte/vite-wagmi/src/wagmi.ts @@ -45,14 +45,17 @@ export const chains: Chain[] = [ ] : []), ]; + export const defaultChain = import.meta.env.MODE === "development" ? zksyncSepoliaTestnet : zksync; export const wagmiConfig = createConfig({ - chains: [zksync, zksyncSepoliaTestnet], + chains: chains.length > 0 ? (chains as [Chain, ...Chain[]]) : [defaultChain], connectors: [injected(), coinbaseWallet(), metaMask()], transports: { [zksync.id]: http(), [zksyncSepoliaTestnet.id]: http(), + 270: http(), + 260: http(), }, })