-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSwitchChain.tsx
46 lines (39 loc) · 1.11 KB
/
SwitchChain.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { CHAIN_NAME } from '@zodiac/chains'
import { SecondaryButton, Warning } from '@zodiac/ui'
import type { PropsWithChildren } from 'react'
import type { ChainId } from 'ser-kit'
import { Section } from './Section'
type SwitchChainProps = PropsWithChildren<{
chainId: ChainId
onSwitch?: () => void
onDisconnect?: () => void
}>
export const SwitchChain = ({
chainId,
children,
onSwitch,
onDisconnect,
}: SwitchChainProps) => {
const chainName = CHAIN_NAME[chainId] || `#${chainId}`
return (
<Section>
{children}
<Warning title="Chain mismatch">
The connected wallet belongs to a different chain. To use it you need to
switch back to <span className="font-semibold">{chainName}</span>
</Warning>
<Section.Actions>
{onSwitch && (
<SecondaryButton fluid onClick={onSwitch}>
Switch wallet to {chainName}
</SecondaryButton>
)}
{onDisconnect && (
<SecondaryButton fluid onClick={onDisconnect}>
Disconnect
</SecondaryButton>
)}
</Section.Actions>
</Section>
)
}