-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChainSelector.tsx
More file actions
119 lines (97 loc) · 3.14 KB
/
ChainSelector.tsx
File metadata and controls
119 lines (97 loc) · 3.14 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { useMediaQuery } from '@react-hookz/web';
import { useAppKitNetwork } from '@reown/appkit/react';
import styled from 'styled-components';
import ChainIcon from 'src/domains/chains/components/ChainIcon';
import { Definition } from 'src/domains/chains/utils/definitions';
import supportedChains from 'src/domains/chains/utils/supportedChains';
import useChain from 'src/domains/chains/utils/useChain';
import BIcon from 'src/domains/misc/components/BIcon';
import Button from 'src/domains/misc/components/Button';
import SelectBox from 'src/domains/misc/components/SelectBox';
import { BOTTOM_MENU_BREAKPOINT, BREAKPOINTS } from 'src/domains/misc/consts/consts';
import { typography } from 'src/domains/styling/utils/tokens';
import vars from 'src/domains/styling/utils/vars';
const CHAIN_SELECTOR_WIDTH = 246;
const { testnet, mainnet } = supportedChains;
const ChainSelector = () => {
const chainConfig = useChain();
const isLargeScreen = useMediaQuery(`(min-width: ${BREAKPOINTS.sm})`);
const { switchNetwork } = useAppKitNetwork();
const renderOption = (chain: Definition) => ({
onClick: () => void switchNetwork(chain),
text:
(
<Option>
<ChainIcon size={20} chainId={chain.id} />
<p>{chain.name}</p>
{chainConfig?.id === chain.id && <BIcon size={20} icon="CheckmarkRegular" />}
</Option>
),
});
return (
<StyledSelectBox
align="start"
sections={[
{ title: 'Mainnet', options: mainnet.map(renderOption) },
{ title: 'Testnet', options: testnet.map(renderOption) },
]}
>
<StyledButton variant="secondary">
{chainConfig ? (
<ButtonLeftContent>
<ChainIcon chainId={chainConfig.id} size={24} />
{isLargeScreen && chainConfig.name}
</ButtonLeftContent>
) : (
'Select Network'
)}
<BIcon icon="Chevron" color={vars('--color-neutral-foreground-3-rest')} />
<UnderLine />
</StyledButton>
</StyledSelectBox>
);
};
export default ChainSelector;
const ButtonLeftContent = styled.div`
display: flex;
align-items: center;
gap: ${vars('--spacing-s')};
`;
const StyledSelectBox = styled(SelectBox)`
width: ${CHAIN_SELECTOR_WIDTH}px;
`;
const StyledButton = styled(Button)`
display: flex;
position: relative;
align-items: center;
justify-content: space-between;
gap: ${vars('--spacing-s')};
padding-inline: ${vars('--spacing-s')};
width: ${CHAIN_SELECTOR_WIDTH}px;
border-radius: ${vars('--spacing-s')};
background: ${vars('--color-neutral-background-1-rest')};
border-color: ${vars('--color-neutral-stroke-2-rest')};
overflow: hidden;
${typography.body1};
@media (width <= ${BOTTOM_MENU_BREAKPOINT}) { /* stylelint-disable-line media-query-no-invalid */
width: fit-content;
}
`;
const Option = styled.div`
display: flex;
align-items: center;
gap: ${vars('--spacing-s')};
width: 100%;
${typography.body1Strong};
& > ${BIcon} {
margin-left: auto;
}
`;
const UnderLine = styled.div`
position: absolute;
left: 0;
bottom: 0;
height: 1px;
width: 100%;
background: ${vars('--color-neutral-stroke-2-rest')};
`;