|
| 1 | +import React from "react" |
| 2 | +import { Box, Center, chakra, Flex, Heading, Text } from "@chakra-ui/react" |
| 3 | + |
| 4 | +import CardList from "../CardList" |
| 5 | +import Link from "../Link" |
| 6 | +import Emoji from "../Emoji" |
| 7 | +import Translation from "../Translation" |
| 8 | +import { StyledSelect as Select } from "../SharedStyledComponents" |
| 9 | + |
| 10 | +import { ChildOnlyProp } from "../../types" |
| 11 | +import { useEthExchanges } from "./use-eth-exchanges" |
| 12 | + |
| 13 | +const ListContainer = (props: ChildOnlyProp) => ( |
| 14 | + <Box mt={16} flex={{ base: "1 1 100%", md: "1 1 50%" }} {...props} /> |
| 15 | +) |
| 16 | + |
| 17 | +const ResultsContainer = (props: ChildOnlyProp) => ( |
| 18 | + <Flex |
| 19 | + justify="center" |
| 20 | + w="full" |
| 21 | + maxWidth="876px" |
| 22 | + flexWrap={{ base: "wrap", md: "initial" }} |
| 23 | + sx={{ |
| 24 | + "& > *": { |
| 25 | + _first: { |
| 26 | + mr: { base: 0, md: 6 }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + }} |
| 30 | + {...props} |
| 31 | + /> |
| 32 | +) |
| 33 | + |
| 34 | +const EmptyStateContainer = (props: ChildOnlyProp) => ( |
| 35 | + <Center flexDir="column" mt={16} {...props} /> |
| 36 | +) |
| 37 | + |
| 38 | +const SuccessContainer = (props: ChildOnlyProp) => ( |
| 39 | + <Flex flexDir="column" mt={4} {...props} /> |
| 40 | +) |
| 41 | + |
| 42 | +const EmptyStateText = (props: ChildOnlyProp) => ( |
| 43 | + <Text m={8} fontSize="xl" maxW="450px" textAlign="center" {...props} /> |
| 44 | +) |
| 45 | + |
| 46 | +const StyledSelect = chakra(Select, { |
| 47 | + baseStyle: { |
| 48 | + maxW: "container.sm", |
| 49 | + }, |
| 50 | +}) |
| 51 | + |
| 52 | +const NoResults = ({ children }) => ( |
| 53 | + <EmptyStateContainer> |
| 54 | + <Emoji text=":crying_face:" fontSize="80px" /> |
| 55 | + <EmptyStateText> |
| 56 | + {children}{" "} |
| 57 | + <Link to="mailto:website@ethereum.org">website@ethereum.org</Link>. |
| 58 | + </EmptyStateText> |
| 59 | + </EmptyStateContainer> |
| 60 | +) |
| 61 | + |
| 62 | +const NoResultsSingle = ({ children }) => ( |
| 63 | + <Center flexDir="column" mt={6}> |
| 64 | + <Text maxW="450px" mb={16}> |
| 65 | + {children}{" "} |
| 66 | + <Link to="mailto:website@ethereum.org">website@ethereum.org</Link>. |
| 67 | + </Text> |
| 68 | + <Emoji text=":crying_face:" fontSize="80px" /> |
| 69 | + </Center> |
| 70 | +) |
| 71 | + |
| 72 | +// TODO move component into get-eth.js page? |
| 73 | +const EthExchanges = () => { |
| 74 | + const { |
| 75 | + exchangesByCountry, |
| 76 | + handleSelectChange, |
| 77 | + hasSelectedCountry, |
| 78 | + placeholderString, |
| 79 | + t, |
| 80 | + hasExchangeResults, |
| 81 | + hasWalletResults, |
| 82 | + filteredExchanges, |
| 83 | + filteredWallets, |
| 84 | + lastUpdated, |
| 85 | + } = useEthExchanges() |
| 86 | + |
| 87 | + return ( |
| 88 | + <Flex flexDir="column" align="center" w="full"> |
| 89 | + <Heading fontSize={{ base: "2xl", md: "2rem" }} fontWeight={600} lineHeight={1.4}> |
| 90 | + <Translation id="page-get-eth-exchanges-header" /> |
| 91 | + </Heading> |
| 92 | + <Text maxW="container.sm" mb={8} lineHeight={1.4} textAlign="center"> |
| 93 | + <Translation id="page-get-eth-exchanges-intro" /> |
| 94 | + </Text> |
| 95 | + <StyledSelect |
| 96 | + aria-label={t("page-get-eth-exchanges-header")} |
| 97 | + className="react-select-container" |
| 98 | + classNamePrefix="react-select" |
| 99 | + options={exchangesByCountry} |
| 100 | + onChange={handleSelectChange} |
| 101 | + placeholder={placeholderString} |
| 102 | + /> |
| 103 | + {!hasSelectedCountry && ( |
| 104 | + <EmptyStateContainer> |
| 105 | + <Emoji text=":world_map:" fontSize="80px" /> |
| 106 | + <EmptyStateText> |
| 107 | + <Translation id="page-get-eth-exchanges-empty-state-text" /> |
| 108 | + </EmptyStateText> |
| 109 | + </EmptyStateContainer> |
| 110 | + )} |
| 111 | + {/* No results */} |
| 112 | + {hasSelectedCountry && !hasExchangeResults && !hasWalletResults && ( |
| 113 | + <ResultsContainer> |
| 114 | + <NoResults> |
| 115 | + <Translation id="page-get-eth-exchanges-no-exchanges-or-wallets" /> |
| 116 | + </NoResults> |
| 117 | + </ResultsContainer> |
| 118 | + )} |
| 119 | + {/* Has results */} |
| 120 | + {(hasExchangeResults || hasWalletResults) && ( |
| 121 | + <> |
| 122 | + <ResultsContainer> |
| 123 | + <ListContainer> |
| 124 | + <Heading |
| 125 | + as="h3" |
| 126 | + fontSize={{ base: "xl", md: "2xl" }} |
| 127 | + fontWeight={600} |
| 128 | + lineHeight={1.4} |
| 129 | + > |
| 130 | + <Translation id="page-get-eth-exchanges-header-exchanges" /> |
| 131 | + </Heading> |
| 132 | + {hasExchangeResults && ( |
| 133 | + <SuccessContainer> |
| 134 | + <Text> |
| 135 | + <Translation id="page-get-eth-exchanges-success-exchange" /> |
| 136 | + </Text> |
| 137 | + <CardList content={filteredExchanges} /> |
| 138 | + </SuccessContainer> |
| 139 | + )} |
| 140 | + {!hasExchangeResults && ( |
| 141 | + <NoResultsSingle> |
| 142 | + <Translation id="page-get-eth-exchanges-no-exchanges" /> |
| 143 | + </NoResultsSingle> |
| 144 | + )} |
| 145 | + </ListContainer> |
| 146 | + <ListContainer> |
| 147 | + <Heading |
| 148 | + as="h3" |
| 149 | + fontSize={{ base: "xl", md: "2xl" }} |
| 150 | + fontWeight={600} |
| 151 | + lineHeight={1.4} |
| 152 | + > |
| 153 | + <Translation id="page-get-eth-exchanges-header-wallets" /> |
| 154 | + </Heading> |
| 155 | + |
| 156 | + {hasWalletResults && ( |
| 157 | + <SuccessContainer> |
| 158 | + <Text> |
| 159 | + <Translation id="page-get-eth-exchanges-success-wallet-paragraph" />{" "} |
| 160 | + <Link to="/wallets/"> |
| 161 | + <Translation id="page-get-eth-exchanges-success-wallet-link" /> |
| 162 | + </Link> |
| 163 | + . |
| 164 | + </Text> |
| 165 | + <CardList content={filteredWallets} /> |
| 166 | + </SuccessContainer> |
| 167 | + )} |
| 168 | + {!hasWalletResults && ( |
| 169 | + <NoResultsSingle> |
| 170 | + <Translation id="page-get-eth-exchanges-no-wallets" /> |
| 171 | + </NoResultsSingle> |
| 172 | + )} |
| 173 | + </ListContainer> |
| 174 | + </ResultsContainer> |
| 175 | + <Text w="full" maxW="876px" mt={16} mb={0}> |
| 176 | + <Translation id="page-get-eth-exchanges-disclaimer" />{" "} |
| 177 | + <Link to="mailto:website@ethereum.org">website@ethereum.org</Link>.{" "} |
| 178 | + <Translation id="page-find-wallet-last-updated" />{" "} |
| 179 | + <strong>{lastUpdated}</strong> |
| 180 | + </Text> |
| 181 | + </> |
| 182 | + )} |
| 183 | + </Flex> |
| 184 | + ) |
| 185 | +} |
| 186 | + |
| 187 | +export default EthExchanges |
0 commit comments