-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SwitchChain component to playground
- Loading branch information
1 parent
9a59af0
commit cda9ce7
Showing
2 changed files
with
25 additions
and
0 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
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,23 @@ | ||
<script lang="ts"> | ||
import { useChainId } from '$lib/hooks/useChainId.svelte.js' | ||
import { useSwitchChain } from '$lib/hooks/useSwitchChain.svelte.js' | ||
const chainId = $derived.by(useChainId()) | ||
const { chains, switchChain, error } = $derived.by(useSwitchChain()) | ||
</script> | ||
|
||
<h2>Switch Chain</h2> | ||
|
||
{#each chains as chain} | ||
<button | ||
disabled={chainId === chain.id} | ||
onclick={() => switchChain({ chainId: chain.id })} | ||
type="button" | ||
> | ||
{chain.name} | ||
</button> | ||
{/each} | ||
|
||
{#if error} | ||
{error.message} | ||
{/if} |