Skip to content

Commit 484d52b

Browse files
committed
refactor: WithdrawalCredentials to tailwind
use ui/alert component over custom divs
1 parent b7b26e1 commit 484d52b

File tree

1 file changed

+38
-44
lines changed

1 file changed

+38
-44
lines changed

src/components/Staking/WithdrawalCredentials.tsx

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { ChangeEvent, FC, useMemo, useState } from "react"
22
import { useTranslation } from "next-i18next"
3-
import { Button, Flex, Text } from "@chakra-ui/react"
43

54
import CopyToClipboard from "@/components/CopyToClipboard"
65
import Emoji from "@/components/Emoji"
7-
import Input from "@/components/Input"
86
import Translation from "@/components/Translation"
97

108
import { trackCustomEvent } from "@/lib/utils/matomo"
119

10+
import Input from "../../../tailwind/ui/Input"
11+
import { Alert, AlertContent } from "../ui/alert"
12+
import { Button } from "../ui/buttons/Button"
13+
import { Flex } from "../ui/flex"
14+
import { Spinner } from "../ui/spinner"
15+
1216
interface Validator {
1317
validatorIndex: number
1418
withdrawalCredentials: string
@@ -35,10 +39,9 @@ const WithdrawalCredentials: FC = () => {
3539
eventName: `click`,
3640
})
3741
setHasError(false)
38-
setIsLoading((prev) => ({
39-
...prev,
40-
[networkLowercase]: true,
41-
}))
42+
setIsLoading((prev) =>
43+
isTestnet ? { ...prev, testnet: true } : { ...prev, mainnet: true }
44+
)
4245
const endpoint = `https://${networkLowercase}.beaconcha.in/api/v1/validator/${inputValue}`
4346
try {
4447
const response = await fetch(endpoint)
@@ -56,10 +59,9 @@ const WithdrawalCredentials: FC = () => {
5659
console.error(error)
5760
setHasError(true)
5861
} finally {
59-
setIsLoading((prev) => ({
60-
...prev,
61-
[networkLowercase]: false,
62-
}))
62+
setIsLoading((prev) =>
63+
isTestnet ? { ...prev, testnet: false } : { ...prev, mainnet: false }
64+
)
6365
}
6466
}
6567

@@ -78,89 +80,81 @@ const WithdrawalCredentials: FC = () => {
7880
const resultText = useMemo<string | JSX.Element>(() => {
7981
if (hasError)
8082
return (
81-
<Flex bg="error.neutral" p={4}>
82-
<Text m={0} color="error.base">
83+
<Alert variant="error">
84+
<AlertContent className="inline">
8385
{t("comp-withdrawal-credentials-error")}
84-
</Text>
85-
</Flex>
86+
</AlertContent>
87+
</Alert>
8688
)
8789
if (!validator) return " "
8890
if (validator.isUpgraded)
8991
return (
90-
<Flex bg="success.neutral" p={4}>
91-
<Text m={0} color="success.base">
92-
<Text as="span" fontWeight="bold">
92+
<Alert variant="success">
93+
<AlertContent className="inline">
94+
<strong>
9395
<Translation
9496
id="page-staking:comp-withdrawal-credentials-upgraded-1"
9597
options={{ validatorIndex: validator.validatorIndex }}
9698
/>{" "}
97-
</Text>
99+
</strong>
98100
{t("comp-withdrawal-credentials-upgraded-2")}{" "}
99101
<CopyToClipboard text={longAddress} inline>
100102
{(isCopied) => (
101103
<>
102-
<Text as="span" title={longAddress} fontWeight="bold">
103-
{shortAddress}
104-
</Text>
104+
<strong title={longAddress}>{shortAddress}</strong>
105105
{isCopied ? (
106106
<>
107107
<Emoji text="✅" className="mx-2 text-lg" />
108-
<Text as="span" title={longAddress}>
109-
{t("copied")}
110-
</Text>
108+
<span title={longAddress}>{t("copied")}</span>
111109
</>
112110
) : (
113111
<Emoji text="📋" className="mx-2 text-lg" />
114112
)}
115113
</>
116114
)}
117115
</CopyToClipboard>
118-
</Text>
119-
</Flex>
116+
</AlertContent>
117+
</Alert>
120118
)
121119
return (
122-
<Flex bg="error.neutral" p={4}>
123-
<Text m={0} color="error.base">
124-
<Text as="span" fontWeight="bold">
120+
<Alert variant="error">
121+
<AlertContent className="inline">
122+
<strong>
125123
{validator.isTestnet
126124
? t("comp-withdrawal-credentials-not-upgraded-1-testnet")
127125
: t("comp-withdrawal-credentials-not-upgraded-1")}
128-
</Text>{" "}
126+
</strong>{" "}
129127
<Translation id="page-staking:comp-withdrawal-credentials-not-upgraded-2" />
130-
</Text>
131-
</Flex>
128+
</AlertContent>
129+
</Alert>
132130
)
133131
}, [hasError, validator, longAddress, shortAddress, t])
134132

135133
return (
136-
<Flex direction="column" gap={4}>
137-
<Flex alignItems="center" gap={2} flexWrap="wrap">
134+
<Flex className="flex-col gap-4">
135+
<Flex className="flex-wrap items-center gap-2">
138136
<Input
139137
id="validatorIndex"
140138
value={inputValue}
141139
onChange={handleChange}
142-
w={{ base: "full", sm: "18ch" }}
140+
className="w-full sm:w-[18ch]"
143141
placeholder={t("comp-withdrawal-credentials-placeholder")}
144142
/>
145-
<Flex
146-
w={{ base: "full", sm: "fit-content" }}
147-
direction={{ base: "column", sm: "row" }}
148-
gap={2}
149-
>
143+
<Flex className="w-full flex-col gap-2 sm:w-fit sm:flex-row">
150144
<Button
151145
onClick={() => checkWithdrawalCredentials()}
152-
isDisabled={!inputValue.length}
153-
isLoading={isLoading.mainnet}
146+
disabled={!inputValue.length}
154147
>
155148
{t("comp-withdrawal-credentials-verify-mainnet")}
149+
{isLoading.mainnet && <Spinner />}
156150
</Button>
157151
<Button
158152
onClick={() => checkWithdrawalCredentials(true)}
159-
isDisabled={!inputValue.length}
153+
disabled={!inputValue.length}
160154
variant="outline"
161-
isLoading={isLoading.testnet}
162155
>
163156
{t("comp-withdrawal-credentials-verify-holesky")}
157+
{isLoading.testnet && <Spinner />}
164158
</Button>
165159
</Flex>
166160
</Flex>

0 commit comments

Comments
 (0)