Skip to content

Commit cc16781

Browse files
refactor(StakingProductsCardGrid): update code to match prod
1 parent 2a5dbe8 commit cc16781

File tree

4 files changed

+96
-102
lines changed

4 files changed

+96
-102
lines changed

src/components/Staking/StakingProductsCardGrid/StakingProductCard.tsx

Lines changed: 79 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as React from "react"
1+
import { useTranslation } from "next-i18next"
2+
import type { ComponentType, ReactNode, SVGProps } from "react"
23
import {
34
Badge,
45
Box,
@@ -7,52 +8,55 @@ import {
78
Flex,
89
Heading,
910
HStack,
10-
Icon as ChakraIcon,
11+
Icon,
1112
List,
1213
ListIcon,
1314
ListItem,
1415
} from "@chakra-ui/react"
1516

16-
import { ButtonLink } from "../../Buttons"
17+
import { ButtonLink } from "@/components/Buttons"
1718
import {
1819
CautionProductGlyphIcon,
1920
GreenCheckProductGlyphIcon,
2021
UnknownProductGlyphIcon,
2122
WarningProductGlyphIcon,
22-
} from "../../icons/staking"
23-
import Translation from "../../Translation"
23+
} from "@/components/icons/staking"
2424

2525
import { FlagType, Product } from "./types"
2626

27-
const getIconFromName = (imageName: string): typeof ChakraIcon | undefined => {
28-
const { [imageName + "GlyphIcon"]: Icon } = require("../icons/staking")
27+
const getIconFromName = (
28+
imageName: string
29+
): ComponentType<SVGProps<SVGElement>> => {
30+
const {
31+
[imageName + "GlyphIcon"]: Icon,
32+
} = require("@/components/icons/staking")
2933
return Icon
3034
}
3135

32-
export const Status = ({ status }: { status: FlagType }) => {
36+
const Status = ({ status }: { status: FlagType | undefined }) => {
3337
if (!status) return null
3438

35-
const getStatusIcon = () => {
36-
switch (status) {
37-
case "green-check":
38-
return GreenCheckProductGlyphIcon
39-
case "caution":
40-
return CautionProductGlyphIcon
41-
case "warning":
42-
case "false":
43-
return WarningProductGlyphIcon
44-
default:
45-
return UnknownProductGlyphIcon
46-
}
39+
const styles = { fontSize: "2xl", m: 0 }
40+
switch (status) {
41+
case "green-check":
42+
return <ListIcon as={GreenCheckProductGlyphIcon} {...styles} />
43+
case "caution":
44+
return <ListIcon as={CautionProductGlyphIcon} {...styles} />
45+
case "warning":
46+
case "false":
47+
return <ListIcon as={WarningProductGlyphIcon} {...styles} />
48+
default:
49+
return <ListIcon as={UnknownProductGlyphIcon} {...styles} />
4750
}
48-
49-
return <ListIcon as={getStatusIcon()} fontSize="2xl" m={0} />
5051
}
5152

52-
const StakingBadge: React.FC<{
53+
const StakingBadge = ({
54+
type,
55+
children,
56+
}: {
5357
type: "ui" | "platform"
54-
children: React.ReactNode
55-
}> = ({ type, children }) => {
58+
children: ReactNode
59+
}) => {
5660
const uiTypeColor = type === "ui" && "stakingPillUI"
5761
const platformTypeColor = type === "platform" && "stakingPillPlatform"
5862

@@ -67,11 +71,11 @@ const StakingBadge: React.FC<{
6771
)
6872
}
6973

70-
interface ICardProps {
74+
type StakingProductCardProps = {
7175
product: Product
7276
}
7377

74-
export const StakingProductCard: React.FC<ICardProps> = ({
78+
export const StakingProductCard = ({
7579
product: {
7680
name,
7781
imageName,
@@ -95,72 +99,69 @@ export const StakingProductCard: React.FC<ICardProps> = ({
9599
economical,
96100
matomo,
97101
},
98-
}) => {
102+
}: StakingProductCardProps) => {
99103
const PADDED_DIV_STYLE: BoxProps = {
100104
px: 8,
101105
py: 6,
102106
}
103107

108+
const { t } = useTranslation("page-staking")
104109
const Svg = getIconFromName(imageName)
105-
type DataType = { label: JSX.Element; status?: FlagType }
110+
type DataType = { label: string; status?: FlagType }
106111
const data: DataType[] = [
107112
{
108-
label: <Translation id="page-staking-considerations-solo-1-title" />,
113+
label: t("page-staking-considerations-solo-1-title"),
109114
status: openSource,
110115
},
111116
{
112-
label: <Translation id="page-staking-considerations-solo-2-title" />,
117+
label: t("page-staking-considerations-solo-2-title"),
113118
status: audited,
114119
},
115120
{
116-
label: <Translation id="page-staking-considerations-solo-3-title" />,
121+
label: t("page-staking-considerations-solo-3-title"),
117122
status: bugBounty,
118123
},
119124
{
120-
label: <Translation id="page-staking-considerations-solo-4-title" />,
125+
label: t("page-staking-considerations-solo-4-title"),
121126
status: battleTested,
122127
},
123128
{
124-
label: <Translation id="page-staking-considerations-solo-5-title" />,
129+
label: t("page-staking-considerations-solo-5-title"),
125130
status: trustless,
126131
},
127132
{
128-
label: <Translation id="page-staking-considerations-solo-6-title" />,
133+
label: t("page-staking-considerations-solo-6-title"),
129134
status: permissionless,
130135
},
131136
{
132-
label: <Translation id="page-staking-considerations-pools-6-title" />,
137+
label: t("page-staking-considerations-pools-6-title"),
133138
status: permissionlessNodes,
134139
},
135140
{
136-
label: <Translation id="page-staking-considerations-solo-7-title" />,
141+
label: t("page-staking-considerations-solo-7-title"),
137142
status: multiClient,
138143
},
139144
{
140-
label: <Translation id="page-staking-considerations-saas-7-title" />,
145+
label: t("page-staking-considerations-saas-7-title"),
141146
status: executionDiversity,
142147
},
143148
{
144-
label: <Translation id="page-staking-considerations-saas-8-title" />,
149+
label: t("page-staking-considerations-saas-8-title"),
145150
status: consensusDiversity,
146151
},
147152
{
148-
label: <Translation id="page-staking-considerations-solo-8-title" />,
153+
label: t("page-staking-considerations-solo-8-title"),
149154
status: selfCustody,
150155
},
151156
{
152-
label: <Translation id="page-staking-considerations-pools-8-title" />,
157+
label: t("page-staking-considerations-pools-8-title"),
153158
status: liquidityToken,
154159
},
155160
{
156-
label: <Translation id="page-staking-considerations-solo-9-title" />,
161+
label: t("page-staking-considerations-solo-9-title"),
157162
status: economical,
158163
},
159-
]
160-
161-
const filteredData = data.filter(
162-
(item): item is Required<DataType> => !!item.status
163-
)
164+
].filter(({ status }) => !!status)
164165

165166
return (
166167
<Flex
@@ -180,7 +181,7 @@ export const StakingProductCard: React.FC<ICardProps> = ({
180181
borderRadius="base"
181182
maxH={24}
182183
>
183-
{!!Svg && <Svg fontSize="2rem" color="white" />}
184+
{!!Svg && <Icon as={Svg} fontSize="2rem" color="white" />}
184185
<Heading as="h4" fontSize="2xl" color="white">
185186
{name}
186187
</Heading>
@@ -203,45 +204,42 @@ export const StakingProductCard: React.FC<ICardProps> = ({
203204
flex={1}
204205
alignItems="flex-start"
205206
>
206-
{platforms &&
207-
platforms.map((platform, idx) => (
208-
<StakingBadge type="platform" key={idx}>
209-
{platform}
210-
</StakingBadge>
211-
))}
212-
{ui &&
213-
ui.map((_ui, idx) => (
214-
<StakingBadge type="ui" key={idx}>
215-
{_ui}
216-
</StakingBadge>
217-
))}
207+
{platforms.map((platform, idx) => (
208+
<StakingBadge type="platform" key={idx}>
209+
{platform}
210+
</StakingBadge>
211+
))}
212+
{ui.map((_ui, idx) => (
213+
<StakingBadge type="ui" key={idx}>
214+
{_ui}
215+
</StakingBadge>
216+
))}
218217
</Flex>
219218
<Box {...PADDED_DIV_STYLE} py={0}>
220219
<List m={0} gap={3}>
221-
{filteredData &&
222-
filteredData.map(({ label, status }, idx) => (
223-
<ListItem
224-
as={Flex}
225-
key={idx}
226-
textTransform="uppercase"
227-
fontSize="xs"
228-
lineHeight="0.875rem"
229-
letterSpacing="wider"
230-
my={4}
231-
ms="auto"
232-
me={0}
233-
gap="1em"
234-
alignItems="center"
235-
>
236-
<Status status={status} />
237-
{label}
238-
</ListItem>
239-
))}
220+
{data.map(({ label, status }, idx) => (
221+
<ListItem
222+
as={Flex}
223+
key={idx}
224+
textTransform="uppercase"
225+
fontSize="xs"
226+
lineHeight="0.875rem"
227+
letterSpacing="wider"
228+
my="4"
229+
ms="auto"
230+
me={0}
231+
gap="1em"
232+
alignItems="center"
233+
>
234+
<Status status={status} />
235+
{label}
236+
</ListItem>
237+
))}
240238
</List>
241239
</Box>
242240
<Box {...PADDED_DIV_STYLE}>
243-
<ButtonLink to={url} customEventOptions={matomo} width="100%">
244-
<Translation id="page-staking-products-get-started" />
241+
<ButtonLink href={url} customEventOptions={matomo} width="100%">
242+
{t("page-staking-products-get-started")}
245243
</ButtonLink>
246244
</Box>
247245
</Flex>

src/components/Staking/StakingProductsCardGrid/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { StakingProductCard } from "./StakingProductCard"
55
import { StakingProductsCategoryKeys } from "./types"
66
import { useStakingProductsCardGrid } from "./useStakingProductsCardGrid"
77

8-
export interface IProps {
8+
export type StakingProductsCardGridProps = {
99
category: StakingProductsCategoryKeys
1010
}
1111

12-
const StakingProductCardGrid: React.FC<IProps> = ({ category }) => {
12+
const StakingProductsCardGrid = ({
13+
category,
14+
}: StakingProductsCardGridProps) => {
1315
const { rankedProducts } = useStakingProductsCardGrid({ category })
1416

15-
if (!rankedProducts) return null
16-
1717
return (
1818
<SimpleGrid
1919
templateColumns="repeat(auto-fill, minmax(min(100%, 280px), 1fr))"
@@ -28,4 +28,4 @@ const StakingProductCardGrid: React.FC<IProps> = ({ category }) => {
2828
)
2929
}
3030

31-
export default StakingProductCardGrid
31+
export default StakingProductsCardGrid

src/components/Staking/StakingProductsCardGrid/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type Product = {
3434
matomo: MatomoEventOptions
3535
}
3636

37-
type StakingProductsType = typeof stakingProducts
37+
export type StakingProductsType = typeof stakingProducts
3838

3939
export type NodeToolsType = StakingProductsType["nodeTools"]
4040
export type KeyGenType = StakingProductsType["keyGen"]

src/components/Staking/StakingProductsCardGrid/useStakingProductsCardGrid.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ export const useStakingProductsCardGrid = ({
3333
const categoryProducts = stakingProducts[category]
3434
const products: Array<Product> = []
3535

36-
function mapCatProducts<T extends unknown>(
37-
products: T[],
38-
cb: (listing: T) => Product
39-
) {
36+
function mapCatProducts<T>(products: T[], cb: (listing: T) => Product) {
4037
return products.map((item) => cb(item))
4138
}
4239

@@ -111,17 +108,16 @@ export const useStakingProductsCardGrid = ({
111108
)
112109
}
113110

114-
if (products) {
115-
updateRankedProducts(
116-
shuffle(products)
117-
.map((product) => ({
118-
...product,
119-
rankingScore: getRankingScore(product),
120-
}))
121-
.sort((a, b) => b.rankingScore - a.rankingScore)
122-
)
123-
}
124-
}, [LUM, SAT, category])
111+
updateRankedProducts(
112+
shuffle(products)
113+
.map((product) => ({
114+
...product,
115+
rankingScore: getRankingScore(product),
116+
}))
117+
.sort((a, b) => b.rankingScore - a.rankingScore)
118+
)
119+
// eslint-disable-next-line react-hooks/exhaustive-deps
120+
}, [])
125121

126122
return {
127123
rankedProducts,

0 commit comments

Comments
 (0)