Skip to content

Commit 59c41d7

Browse files
committed
setup layer2onboard component for cexonboard
1 parent 3389e6c commit 59c41d7

File tree

1 file changed

+63
-16
lines changed

1 file changed

+63
-16
lines changed

src/components/Layer2/Layer2Onboard.tsx

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GatsbyImage, IGatsbyImageData } from "gatsby-plugin-image"
33
import React, { useState } from "react"
44
import styled from "@emotion/styled"
55
import { useIntl } from "react-intl"
6+
import { Stack, Text } from "@chakra-ui/react"
67

78
// Components
89
import ButtonLink from "../ButtonLink"
@@ -211,9 +212,13 @@ const Layer2Onboard: React.FC<IProps> = ({
211212
}) => {
212213
const intl = useIntl()
213214

214-
const [selectedCexOnboard, setSelectedCexOnboard] = useState<CexOnboard>()
215-
const [selectedExchange, setSelectedExchange] = useState<Exchange>()
216-
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)
217222

218223
const layer2Options: Array<Layer2Option> = layer2DataCombined.map((l2) => {
219224
return {
@@ -243,6 +248,41 @@ const Layer2Onboard: React.FC<IProps> = ({
243248
}
244249
)
245250

251+
const formatGroupLabel = (data) => {
252+
console.log(data)
253+
return data.label ? (
254+
<Stack borderTop="2px solid" m={0}>
255+
<Text mb={0} mt={2} textTransform="none" color="body">
256+
{data.label}
257+
</Text>
258+
</Stack>
259+
) : (
260+
<></>
261+
)
262+
}
263+
264+
const selectExchangeOnboard = (option: ExchangeOption | CexOnboardOption) => {
265+
if (Object.hasOwn(option, "cex")) {
266+
trackCustomEvent({
267+
eventCategory: `Selected cex to onboard`,
268+
eventAction: `Clicked`,
269+
eventName: `${option.cex.name} selected`,
270+
eventValue: `${option.cex.name}`,
271+
})
272+
setSelectedExchange(option.cex)
273+
setSelectedCexOnboard(undefined)
274+
} else {
275+
trackCustomEvent({
276+
eventCategory: `Selected cexOnboard to onboard`,
277+
eventAction: `Clicked`,
278+
eventName: `${option.cexOnboard.name} selected`,
279+
eventValue: `${option.cexOnboard.name}`,
280+
})
281+
setSelectedCexOnboard(option.cexOnboard)
282+
setSelectedExchange(undefined)
283+
}
284+
}
285+
246286
return (
247287
<Content>
248288
<Description>
@@ -325,39 +365,31 @@ const Layer2Onboard: React.FC<IProps> = ({
325365
</RightDescription>
326366
<RightSelect>
327367
<StyledSelect
328-
// TODO: style this label
329368
className="react-select-container"
330369
classNamePrefix="react-select"
331370
options={[
332371
{
333372
options: [...cexSupportOptions],
334373
},
335374
{
336-
// TODO: Add cex onboard label here
337-
label: "Test",
375+
label:
376+
"Don't see you exchange? Use dapps to bridge directly from exchanges to layer 2.",
338377
options: [...cexOnboardOptions],
339378
},
340379
]}
341-
onChange={(selectedOption: ExchangeOption) => {
342-
trackCustomEvent({
343-
eventCategory: `Selected cex to onboard`,
344-
eventAction: `Clicked`,
345-
eventName: `${selectedOption.cex.name} selected`,
346-
eventValue: `${selectedOption.cex.name}`,
347-
})
348-
// TODO: refactor this to use both selected exchange and selected cex onboard
349-
setSelectedExchange(selectedOption.cex)
380+
onChange={(selectedOption: ExchangeOption | CexOnboardOption) => {
381+
selectExchangeOnboard(selectedOption)
350382
}}
351383
placeholder={translateMessageId(
352384
"layer-2-onboard-exchange-input-placeholder",
353385
intl
354386
)}
387+
formatGroupLabel={formatGroupLabel}
355388
/>
356389
</RightSelect>
357390
<EthLogo>
358391
<Image image={ethIcon} objectFit="contain" alt={ethIconAlt} />
359392
</EthLogo>
360-
{/* TODO: Add markdown for rendering cex onboard content */}
361393
{selectedExchange && (
362394
<RightSelected>
363395
<SelectedContainer>
@@ -391,6 +423,21 @@ const Layer2Onboard: React.FC<IProps> = ({
391423
</SelectedContainer>
392424
</RightSelected>
393425
)}
426+
{selectedCexOnboard && (
427+
<RightSelected>
428+
<SelectedContainer>
429+
<H3>Supported exchanges</H3>
430+
<p>{selectedCexOnboard.cex_support.join(", ")}</p>
431+
<H3>Supported layer 2s</H3>
432+
<p>{selectedCexOnboard.network_support.join(", ")}</p>
433+
<ButtonLink to={selectedCexOnboard.url}>
434+
{`${translateMessageId("layer-2-go-to", intl)} ${
435+
selectedCexOnboard.name
436+
}`}
437+
</ButtonLink>
438+
</SelectedContainer>
439+
</RightSelected>
440+
)}
394441
</Grid>
395442
</Content>
396443
)

0 commit comments

Comments
 (0)