1
1
import { ChangeEvent , FC , useMemo , useState } from "react"
2
2
import { useTranslation } from "next-i18next"
3
- import { Button , Flex , Text } from "@chakra-ui/react"
4
3
5
4
import CopyToClipboard from "@/components/CopyToClipboard"
6
5
import Emoji from "@/components/Emoji"
7
- import Input from "@/components/Input"
8
6
import Translation from "@/components/Translation"
9
7
10
8
import { trackCustomEvent } from "@/lib/utils/matomo"
11
9
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
+
12
16
interface Validator {
13
17
validatorIndex : number
14
18
withdrawalCredentials : string
@@ -35,10 +39,9 @@ const WithdrawalCredentials: FC = () => {
35
39
eventName : `click` ,
36
40
} )
37
41
setHasError ( false )
38
- setIsLoading ( ( prev ) => ( {
39
- ...prev ,
40
- [ networkLowercase ] : true ,
41
- } ) )
42
+ setIsLoading ( ( prev ) =>
43
+ isTestnet ? { ...prev , testnet : true } : { ...prev , mainnet : true }
44
+ )
42
45
const endpoint = `https://${ networkLowercase } .beaconcha.in/api/v1/validator/${ inputValue } `
43
46
try {
44
47
const response = await fetch ( endpoint )
@@ -56,10 +59,9 @@ const WithdrawalCredentials: FC = () => {
56
59
console . error ( error )
57
60
setHasError ( true )
58
61
} finally {
59
- setIsLoading ( ( prev ) => ( {
60
- ...prev ,
61
- [ networkLowercase ] : false ,
62
- } ) )
62
+ setIsLoading ( ( prev ) =>
63
+ isTestnet ? { ...prev , testnet : false } : { ...prev , mainnet : false }
64
+ )
63
65
}
64
66
}
65
67
@@ -78,89 +80,81 @@ const WithdrawalCredentials: FC = () => {
78
80
const resultText = useMemo < string | JSX . Element > ( ( ) => {
79
81
if ( hasError )
80
82
return (
81
- < Flex bg = "error.neutral" p = { 4 } >
82
- < Text m = { 0 } color = "error.base ">
83
+ < Alert variant = "error" >
84
+ < AlertContent className = "inline ">
83
85
{ t ( "comp-withdrawal-credentials-error" ) }
84
- </ Text >
85
- </ Flex >
86
+ </ AlertContent >
87
+ </ Alert >
86
88
)
87
89
if ( ! validator ) return " "
88
90
if ( validator . isUpgraded )
89
91
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 >
93
95
< Translation
94
96
id = "page-staking:comp-withdrawal-credentials-upgraded-1"
95
97
options = { { validatorIndex : validator . validatorIndex } }
96
98
/> { " " }
97
- </ Text >
99
+ </ strong >
98
100
{ t ( "comp-withdrawal-credentials-upgraded-2" ) } { " " }
99
101
< CopyToClipboard text = { longAddress } inline >
100
102
{ ( isCopied ) => (
101
103
< >
102
- < Text as = "span" title = { longAddress } fontWeight = "bold" >
103
- { shortAddress }
104
- </ Text >
104
+ < strong title = { longAddress } > { shortAddress } </ strong >
105
105
{ isCopied ? (
106
106
< >
107
107
< 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 >
111
109
</ >
112
110
) : (
113
111
< Emoji text = "📋" className = "mx-2 text-lg" />
114
112
) }
115
113
</ >
116
114
) }
117
115
</ CopyToClipboard >
118
- </ Text >
119
- </ Flex >
116
+ </ AlertContent >
117
+ </ Alert >
120
118
)
121
119
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 >
125
123
{ validator . isTestnet
126
124
? t ( "comp-withdrawal-credentials-not-upgraded-1-testnet" )
127
125
: t ( "comp-withdrawal-credentials-not-upgraded-1" ) }
128
- </ Text > { " " }
126
+ </ strong > { " " }
129
127
< Translation id = "page-staking:comp-withdrawal-credentials-not-upgraded-2" />
130
- </ Text >
131
- </ Flex >
128
+ </ AlertContent >
129
+ </ Alert >
132
130
)
133
131
} , [ hasError , validator , longAddress , shortAddress , t ] )
134
132
135
133
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 ">
138
136
< Input
139
137
id = "validatorIndex"
140
138
value = { inputValue }
141
139
onChange = { handleChange }
142
- w = { { base : " full" , sm : " 18ch" } }
140
+ className = "w- full sm:w-[ 18ch]"
143
141
placeholder = { t ( "comp-withdrawal-credentials-placeholder" ) }
144
142
/>
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" >
150
144
< Button
151
145
onClick = { ( ) => checkWithdrawalCredentials ( ) }
152
- isDisabled = { ! inputValue . length }
153
- isLoading = { isLoading . mainnet }
146
+ disabled = { ! inputValue . length }
154
147
>
155
148
{ t ( "comp-withdrawal-credentials-verify-mainnet" ) }
149
+ { isLoading . mainnet && < Spinner /> }
156
150
</ Button >
157
151
< Button
158
152
onClick = { ( ) => checkWithdrawalCredentials ( true ) }
159
- isDisabled = { ! inputValue . length }
153
+ disabled = { ! inputValue . length }
160
154
variant = "outline"
161
- isLoading = { isLoading . testnet }
162
155
>
163
156
{ t ( "comp-withdrawal-credentials-verify-holesky" ) }
157
+ { isLoading . testnet && < Spinner /> }
164
158
</ Button >
165
159
</ Flex >
166
160
</ Flex >
0 commit comments