-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.tsx
More file actions
190 lines (181 loc) · 5.11 KB
/
Copy pathindex.tsx
File metadata and controls
190 lines (181 loc) · 5.11 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { Box, Flex, Skeleton } from '@chakra-ui/react'
import {
NetworkArbitrumOne,
NetworkEthereum,
NetworkOptimism,
NetworkPolygon,
NetworkSepolia,
} from '@web3icons/react'
import { useState } from 'react'
import { arbitrum, mainnet, optimism, polygon, sepolia } from 'viem/chains'
import OptionsDropdown from '@/src/components/pageComponents/home/Examples/demos/OptionsDropdown'
import Icon from '@/src/components/pageComponents/home/Examples/demos/TokenInput/Icon'
import BaseTokenInput from '@/src/components/sharedComponents/TokenInput'
import { useTokenInput } from '@/src/components/sharedComponents/TokenInput/useTokenInput'
import type { Networks } from '@/src/components/sharedComponents/TokenSelect/types'
import { includeTestnets } from '@/src/constants/common'
import { useTokenLists } from '@/src/hooks/useTokenLists'
import { useTokenSearch } from '@/src/hooks/useTokenSearch'
import { useWeb3Status } from '@/src/hooks/useWeb3Status'
import { withSuspenseAndRetry } from '@/src/utils/suspenseWrapper'
type Options = 'single' | 'multi'
const SkeletonLoadingTokenInput = () => (
<Flex
flexDirection="column"
height="144px"
padding={4}
rowGap={2}
width="100%"
>
<Skeleton
height="17px"
minHeight="0"
width="80px"
/>
<Skeleton
borderRadius="8px"
minHeight="58px"
width="100%"
/>
<Skeleton
borderRadius="8px"
minHeight="18px"
width="100%"
/>
</Flex>
)
/**
* Select multi-token or single-token mode
*/
const TokenInputMode = withSuspenseAndRetry(
({ currentTokenInput }: { currentTokenInput: Options }) => {
const { isWalletConnected } = useWeb3Status()
const [currentNetworkId, setCurrentNetworkId] = useState<number>()
const { tokensByChainId } = useTokenLists()
const { searchResult } = useTokenSearch({
tokens: tokensByChainId[1],
defaultSearchTerm: 'WETH',
})
const tokenInputMulti = useTokenInput()
const tokenInputSingle = useTokenInput(searchResult[0])
const networks: Networks = [
{
icon: (
<NetworkEthereum
size={24}
variant="background"
/>
),
id: mainnet.id,
label: mainnet.name,
onClick: () => setCurrentNetworkId(mainnet.id),
},
{
icon: (
<NetworkOptimism
size={24}
variant="background"
/>
),
id: optimism.id,
label: optimism.name,
onClick: () => setCurrentNetworkId(optimism.id),
},
{
icon: (
<NetworkArbitrumOne
size={24}
variant="background"
/>
),
id: arbitrum.id,
label: arbitrum.name,
onClick: () => setCurrentNetworkId(arbitrum.id),
},
{
icon: (
<NetworkPolygon
size={24}
variant="background"
/>
),
id: polygon.id,
label: polygon.name,
onClick: () => setCurrentNetworkId(polygon.id),
},
...(includeTestnets
? [
{
icon: (
<NetworkSepolia
size={24}
variant="background"
/>
),
id: sepolia.id,
label: sepolia.name,
onClick: () => setCurrentNetworkId(sepolia.id),
},
]
: []),
]
return (
<BaseTokenInput
currentNetworkId={currentNetworkId}
networks={networks}
showAddTokenButton
showBalance={isWalletConnected}
showTopTokens
singleToken={currentTokenInput === 'single'}
title="You pay"
tokenInput={currentTokenInput === 'multi' ? tokenInputMulti : tokenInputSingle}
/>
)
},
)
/**
* This demo uses the TokenInput component to show how to use it in a single
* token or multi token mode.
*/
const TokenInput = () => {
const [currentTokenInput, setCurrentTokenInput] = useState<Options>('multi')
const dropdownItems = [
{ label: 'Multi token', onClick: () => setCurrentTokenInput('multi') },
{ label: 'Single token', onClick: () => setCurrentTokenInput('single') },
]
return (
<Box
paddingTop={{ base: 2, lg: 6 }}
width="100%"
>
<OptionsDropdown
items={dropdownItems}
currentItem={dropdownItems[0].label}
/>
<TokenInputMode
currentTokenInput={currentTokenInput}
suspenseFallback={<SkeletonLoadingTokenInput />}
/>
</Box>
)
}
const tokenInput = {
demo: <TokenInput />,
href: 'https://bootnodedev.github.io/dAppBooster/variables/components_sharedComponents_TokenInput.TokenInput.html',
icon: <Icon />,
text: (
<>
<a
href="https://bootnodedev.github.io/dAppBooster/variables/components_sharedComponents_TokenSelect.TokenSelect.html"
rel="noreferrer"
target="_blank"
>
Select a token
</a>{' '}
or specify one beforehand, enter a token amount, auto detect token decimals, user balance, min
and max boundaries, format numbers, max button.
</>
),
title: 'Token input',
}
export default tokenInput