Skip to content

Commit

Permalink
feat: add SwitchChain component to playground
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteAtATime committed Oct 31, 2024
1 parent 9a59af0 commit cda9ce7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import Connect from './_components/Connect.svelte'
import Connections from './_components/Connections.svelte'
import ReadContract from './_components/ReadContract.svelte'
import SwitchAccount from './_components/SwitchAccount.svelte'
import SwitchChain from './_components/SwitchChain.svelte'
</script>

<Account />
<Balance />
<BlockNumber />
<Connect />
<SwitchAccount />
<SwitchChain />
<Connections />
<ReadContract />
23 changes: 23 additions & 0 deletions packages/svelte/src/routes/_components/SwitchChain.svelte
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}

0 comments on commit cda9ce7

Please sign in to comment.