-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathCommitButton.tsx
33 lines (30 loc) · 980 Bytes
/
CommitButton.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
import { Button, ButtonProps } from '@pancakeswap/uikit'
import { useSwitchNetworkLoading } from 'hooks/useSwitchNetworkLoading'
import { useSetAtom } from 'jotai'
import { useActiveChainId } from 'hooks/useActiveChainId'
import { hideWrongNetworkModalAtom } from './NetworkModal'
import Trans from './Trans'
const wrongNetworkProps: ButtonProps = {
variant: 'danger',
disabled: false,
children: <Trans>Wrong Network</Trans>,
}
export const CommitButton = (props: ButtonProps) => {
const { isWrongNetwork } = useActiveChainId()
const [switchNetworkLoading] = useSwitchNetworkLoading()
const setHideWrongNetwork = useSetAtom(hideWrongNetworkModalAtom)
return (
<Button
{...props}
onClick={(e) => {
if (isWrongNetwork) {
setHideWrongNetwork(false)
} else {
props.onClick?.(e)
}
}}
{...(switchNetworkLoading && { disabled: true })}
{...(isWrongNetwork && wrongNetworkProps)}
/>
)
}