11import React from "react" ;
22import styled from "styled-components" ;
3- import { useAccount , useNetwork , useSwitchNetwork } from "wagmi" ;
3+ import { useToggle } from "react-use" ;
4+ import { useAccount , useNetwork } from "wagmi" ;
45import { arbitrumGoerli } from "wagmi/chains" ;
56import { useWeb3Modal } from "@web3modal/react" ;
67import { shortenAddress } from "utils/shortenAddress" ;
78import { Button } from "@kleros/ui-components-library" ;
8- import { DEFAULT_CHAIN , SUPPORTED_CHAINS } from "consts/chains" ;
9+ import { DEFAULT_CHAIN } from "consts/chains" ;
10+ import SwitchChainModal from "./SwitchChainModal" ;
11+
12+ const StyledContainer = styled . div `
13+ width: fit-content;
14+ height: 34px;
15+ padding: 16px;
16+ gap: 0.5rem;
17+ border-radius: 300px;
18+ background-color: ${ ( { theme } ) => theme . whiteLowOpacity } ;
19+ display: flex;
20+ align-items: center;
21+ > label {
22+ color: ${ ( { theme } ) => theme . primaryText } ;
23+ }
24+ :before {
25+ content: "";
26+ width: 8px;
27+ height: 8px;
28+ border-radius: 50%;
29+ background-color: ${ ( { theme } ) => theme . success } ;
30+ }
31+ ` ;
32+
33+ const StyledSwitchChainButton = styled ( Button ) `
34+ width: fit-content;
35+ height: 34px;
36+ ` ;
937
1038const AccountDisplay : React . FC = ( ) => {
1139 return (
@@ -27,49 +55,15 @@ export const AddressDisplay: React.FC = () => {
2755} ;
2856
2957export const SwitchChainButton : React . FC = ( ) => {
30- const { switchNetwork, isLoading } = useSwitchNetwork ( ) ;
31- const handleSwitch = ( ) => {
32- if ( ! switchNetwork ) {
33- console . error ( "Cannot switch network. Please do it manually." ) ;
34- return ;
35- }
36- try {
37- switchNetwork ( DEFAULT_CHAIN ) ;
38- } catch ( err ) {
39- console . error ( err ) ;
40- }
41- } ;
58+ const [ isSwitchChainModalOpen , toggleIsSwitchChainModalOpen ] = useToggle ( false ) ;
4259 return (
43- < Button
44- isLoading = { isLoading }
45- disabled = { isLoading }
46- text = { `Switch to ${ SUPPORTED_CHAINS [ DEFAULT_CHAIN ] . chainName } ` }
47- onClick = { handleSwitch }
48- />
60+ < >
61+ < StyledSwitchChainButton text = { `Switch chain` } onClick = { toggleIsSwitchChainModalOpen } />
62+ { isSwitchChainModalOpen && < SwitchChainModal toggle = { toggleIsSwitchChainModalOpen } /> }
63+ </ >
4964 ) ;
5065} ;
5166
52- const StyledContainer = styled . div `
53- width: fit-content;
54- height: 34px;
55- padding: 16px;
56- gap: 0.5rem;
57- border-radius: 300px;
58- background-color: ${ ( { theme } ) => theme . whiteLowOpacity } ;
59- display: flex;
60- align-items: center;
61- > label {
62- color: ${ ( { theme } ) => theme . primaryText } ;
63- }
64- :before {
65- content: "";
66- width: 8px;
67- height: 8px;
68- border-radius: 50%;
69- background-color: ${ ( { theme } ) => theme . success } ;
70- }
71- ` ;
72-
7367const ConnectButton : React . FC = ( ) => {
7468 const { chain } = useNetwork ( ) ;
7569 const { isConnected } = useAccount ( ) ;
0 commit comments