@@ -3,6 +3,7 @@ import { GatsbyImage, IGatsbyImageData } from "gatsby-plugin-image"
3
3
import React , { useState } from "react"
4
4
import styled from "@emotion/styled"
5
5
import { useIntl } from "react-intl"
6
+ import { Stack , Text } from "@chakra-ui/react"
6
7
7
8
// Components
8
9
import ButtonLink from "../ButtonLink"
@@ -11,6 +12,10 @@ import Translation from "../Translation"
11
12
import { StyledSelect as Select } from "../SharedStyledComponents"
12
13
13
14
// Data
15
+ import {
16
+ cexOnboardData ,
17
+ CexOnboard ,
18
+ } from "../../data/layer-2/cex-layer-2-onboard"
14
19
import cexSupport from "../../data/layer-2/cex-layer-2-support.json"
15
20
16
21
//Utils
@@ -190,6 +195,10 @@ interface ExchangeOption extends Option {
190
195
cex : Exchange
191
196
}
192
197
198
+ interface CexOnboardOption extends Option {
199
+ cexOnboard : CexOnboard
200
+ }
201
+
193
202
export interface IProps {
194
203
layer2DataCombined : Array < Layer2 >
195
204
ethIcon : IGatsbyImageData
@@ -203,8 +212,13 @@ const Layer2Onboard: React.FC<IProps> = ({
203
212
} ) => {
204
213
const intl = useIntl ( )
205
214
206
- const [ selectedExchange , setSelectedExchange ] = useState < Exchange > ( )
207
- const [ selectedL2 , setSelectedL2 ] = useState < Layer2 > ( )
215
+ const [ selectedCexOnboard , setSelectedCexOnboard ] = useState <
216
+ CexOnboard | undefined
217
+ > ( undefined )
218
+ const [ selectedExchange , setSelectedExchange ] = useState <
219
+ Exchange | undefined
220
+ > ( undefined )
221
+ const [ selectedL2 , setSelectedL2 ] = useState < Layer2 | undefined > ( undefined )
208
222
209
223
const layer2Options : Array < Layer2Option > = layer2DataCombined . map ( ( l2 ) => {
210
224
return {
@@ -224,6 +238,50 @@ const Layer2Onboard: React.FC<IProps> = ({
224
238
}
225
239
)
226
240
241
+ const cexOnboardOptions : Array < CexOnboardOption > = cexOnboardData . map (
242
+ ( cexOnboard : CexOnboard ) => {
243
+ return {
244
+ label : cexOnboard . name ,
245
+ value : cexOnboard . name ,
246
+ cexOnboard : cexOnboard ,
247
+ }
248
+ }
249
+ )
250
+
251
+ const formatGroupLabel = ( data ) => {
252
+ return data . label ? (
253
+ < Stack borderTop = "2px solid" m = { 0 } >
254
+ < Text mb = { 0 } mt = { 2 } textTransform = "none" color = "theme.colors.text" >
255
+ { data . label }
256
+ </ Text >
257
+ </ Stack >
258
+ ) : (
259
+ < > </ >
260
+ )
261
+ }
262
+
263
+ const selectExchangeOnboard = ( option : ExchangeOption | CexOnboardOption ) => {
264
+ if ( Object . hasOwn ( option , "cex" ) ) {
265
+ trackCustomEvent ( {
266
+ eventCategory : `Selected cex to onboard` ,
267
+ eventAction : `Clicked` ,
268
+ eventName : `${ option . cex . name } selected` ,
269
+ eventValue : `${ option . cex . name } ` ,
270
+ } )
271
+ setSelectedExchange ( option . cex )
272
+ setSelectedCexOnboard ( undefined )
273
+ } else {
274
+ trackCustomEvent ( {
275
+ eventCategory : `Selected cexOnboard to onboard` ,
276
+ eventAction : `Clicked` ,
277
+ eventName : `${ option . cexOnboard . name } selected` ,
278
+ eventValue : `${ option . cexOnboard . name } ` ,
279
+ } )
280
+ setSelectedCexOnboard ( option . cexOnboard )
281
+ setSelectedExchange ( undefined )
282
+ }
283
+ }
284
+
227
285
return (
228
286
< Content >
229
287
< Description >
@@ -308,20 +366,24 @@ const Layer2Onboard: React.FC<IProps> = ({
308
366
< StyledSelect
309
367
className = "react-select-container"
310
368
classNamePrefix = "react-select"
311
- options = { cexSupportOptions }
312
- onChange = { ( selectedOption : ExchangeOption ) => {
313
- trackCustomEvent ( {
314
- eventCategory : `Selected cex to onboard` ,
315
- eventAction : `Clicked` ,
316
- eventName : `${ selectedOption . cex . name } selected` ,
317
- eventValue : `${ selectedOption . cex . name } ` ,
318
- } )
319
- setSelectedExchange ( selectedOption . cex )
369
+ options = { [
370
+ {
371
+ options : [ ...cexSupportOptions ] ,
372
+ } ,
373
+ {
374
+ label :
375
+ "Don't see you exchange? Use dapps to bridge directly from exchanges to layer 2." ,
376
+ options : [ ...cexOnboardOptions ] ,
377
+ } ,
378
+ ] }
379
+ onChange = { ( selectedOption : ExchangeOption | CexOnboardOption ) => {
380
+ selectExchangeOnboard ( selectedOption )
320
381
} }
321
382
placeholder = { translateMessageId (
322
383
"layer-2-onboard-exchange-input-placeholder" ,
323
384
intl
324
385
) }
386
+ formatGroupLabel = { formatGroupLabel }
325
387
/>
326
388
</ RightSelect >
327
389
< EthLogo >
@@ -360,6 +422,21 @@ const Layer2Onboard: React.FC<IProps> = ({
360
422
</ SelectedContainer >
361
423
</ RightSelected >
362
424
) }
425
+ { selectedCexOnboard && (
426
+ < RightSelected >
427
+ < SelectedContainer >
428
+ < H3 > Supported exchanges</ H3 >
429
+ < p > { selectedCexOnboard . cex_support . join ( ", " ) } </ p >
430
+ < H3 > Supported layer 2s</ H3 >
431
+ < p > { selectedCexOnboard . network_support . join ( ", " ) } </ p >
432
+ < ButtonLink to = { selectedCexOnboard . url } >
433
+ { `${ translateMessageId ( "layer-2-go-to" , intl ) } ${
434
+ selectedCexOnboard . name
435
+ } `}
436
+ </ ButtonLink >
437
+ </ SelectedContainer >
438
+ </ RightSelected >
439
+ ) }
363
440
</ Grid >
364
441
</ Content >
365
442
)
0 commit comments