11import { Box , Divider } from "@mui/material" ;
2-
32import { Button , Typography } from "@atoms" ;
43import { primaryBlue } from "@consts" ;
54import { useAppContext , useModal } from "@context" ;
@@ -31,15 +30,87 @@ export const AutomatedVotingCard = ({
3130 const onClickShowTransaction = ( ) =>
3231 openInNewTab ( `${ cExplorerBaseUrl } /tx/${ transactionId } ` ) ;
3332
33+ const renderTransactionButton = ( ) =>
34+ transactionId && (
35+ < Button
36+ onClick = { onClickShowTransaction }
37+ sx = { { width : "fit-content" , p : 0 } }
38+ variant = "text"
39+ >
40+ { t ( "seeTransaction" ) }
41+ </ Button >
42+ ) ;
43+
44+ const renderVotingPower = ( ) => (
45+ < Box
46+ sx = { {
47+ alignContent : "flex-start" ,
48+ display : "flex" ,
49+ flexDirection : "column" ,
50+ px : screenWidth < 1024 ? 0 : 4.25 ,
51+ py : screenWidth < 1024 ? 1 : 0 ,
52+ width : screenWidth < 1024 ? "100%" : "auto" ,
53+ } }
54+ >
55+ < Typography color = "neutralGray" fontWeight = { 500 } variant = "caption" >
56+ { t ( "dRepDirectory.votingPower" ) }
57+ </ Typography >
58+ < Typography sx = { { display : "flex" , flexDirection : "row" , mt : 0.5 } } >
59+ { "₳ " }
60+ { votingPower }
61+ </ Typography >
62+ </ Box >
63+ ) ;
64+
65+ const renderActionButtons = ( ) => (
66+ < Box
67+ sx = { {
68+ display : "flex" ,
69+ flexDirection : "row" ,
70+ gap : 2.5 ,
71+ mt : screenWidth < 1024 ? 3 : 0 ,
72+ width : screenWidth < 1024 ? "100%" : "auto" ,
73+ } }
74+ >
75+ < Button
76+ data-testid = { `${ testIdLabel } -info-button` }
77+ onClick = { onClickInfo }
78+ size = { isMobile ? "medium" : "large" }
79+ sx = { { flex : screenWidth < 768 ? 1 : undefined } }
80+ variant = "outlined"
81+ >
82+ { t ( "info" ) }
83+ </ Button >
84+ { isConnected ? (
85+ ! isSelected && (
86+ < Button
87+ data-testid = { `${ testIdLabel } -delegate-button` }
88+ isLoading = { isDelegateLoading }
89+ onClick = { onClickDelegate }
90+ size = { isMobile ? "medium" : "large" }
91+ sx = { { flex : screenWidth < 768 ? 1 : undefined } }
92+ variant = "contained"
93+ >
94+ { t ( "delegate" ) }
95+ </ Button >
96+ )
97+ ) : (
98+ < Button
99+ data-testid = { `${ testIdLabel } -connect-to-delegate-button` }
100+ onClick = { ( ) => openModal ( { type : "chooseWallet" } ) }
101+ size = { isMobile ? "medium" : "large" }
102+ sx = { { flex : screenWidth < 768 ? 1 : undefined } }
103+ >
104+ { t ( "connectToDelegate" ) }
105+ </ Button >
106+ ) }
107+ </ Box >
108+ ) ;
109+
34110 return (
35111 < Card
36- { ...( inProgress && {
37- variant : "warning" ,
38- label : t ( "inProgress" ) ,
39- } ) }
40- { ...( isSelected && {
41- variant : "primary" ,
42- } ) }
112+ { ...( inProgress && { variant : "warning" , label : t ( "inProgress" ) } ) }
113+ { ...( isSelected && { variant : "primary" } ) }
43114 sx = { {
44115 alignItems : "center" ,
45116 bgcolor : ( theme ) => `${ theme . palette . neutralWhite } 40` ,
@@ -72,15 +143,7 @@ export const AutomatedVotingCard = ({
72143 >
73144 { description }
74145 </ Typography >
75- { transactionId && (
76- < Button
77- onClick = { onClickShowTransaction }
78- sx = { { width : "fit-content" , p : 0 } }
79- variant = "text"
80- >
81- { t ( "seeTransaction" ) }
82- </ Button >
83- ) }
146+ { renderTransactionButton ( ) }
84147 </ Box >
85148 { ! inProgress && ! isSelected && (
86149 < >
@@ -90,72 +153,14 @@ export const AutomatedVotingCard = ({
90153 sx = { { ml : screenWidth < 1024 ? 0 : 1 } }
91154 variant = { screenWidth < 1024 ? "fullWidth" : "middle" }
92155 />
93- < Box
94- sx = { {
95- alignContent : "flex-start" ,
96- display : "flex" ,
97- flexDirection : "column" ,
98- px : screenWidth < 1024 ? 0 : 4.25 ,
99- py : screenWidth < 1024 ? 1 : 0 ,
100- width : screenWidth < 1024 ? "100%" : "auto" ,
101- } }
102- >
103- < Typography color = "neutralGray" fontWeight = { 500 } variant = "caption" >
104- { t ( "dRepDirectory.votingPower" ) }
105- </ Typography >
106- < Typography sx = { { display : "flex" , flexDirection : "row" , mt : 0.5 } } >
107- { "₳ " }
108- { votingPower }
109- </ Typography >
110- </ Box >
156+ { renderVotingPower ( ) }
111157 < Divider
112158 flexItem
113159 orientation = { screenWidth < 1024 ? "horizontal" : "vertical" }
114160 sx = { { mr : screenWidth < 1024 ? 0 : 1 } }
115161 variant = { screenWidth < 1024 ? "fullWidth" : "middle" }
116162 />
117- < Box
118- sx = { {
119- display : "flex" ,
120- flexDirection : "row" ,
121- gap : 2.5 ,
122- mt : screenWidth < 1024 ? 3 : 0 ,
123- width : screenWidth < 1024 ? "100%" : "auto" ,
124- } }
125- >
126- < Button
127- data-testid = { `${ testIdLabel } -info-button` }
128- onClick = { onClickInfo }
129- size = { isMobile ? "medium" : "large" }
130- sx = { { flex : screenWidth < 768 ? 1 : undefined } }
131- variant = "outlined"
132- >
133- { t ( "info" ) }
134- </ Button >
135- { ! isConnected ? (
136- < Button
137- data-testid = { `${ testIdLabel } -connect-to-delegate-button` }
138- onClick = { ( ) => openModal ( { type : "chooseWallet" } ) }
139- size = { isMobile ? "medium" : "large" }
140- sx = { { flex : screenWidth < 768 ? 1 : undefined } }
141- >
142- { t ( "connectToDelegate" ) }
143- </ Button >
144- ) : (
145- ! isSelected && (
146- < Button
147- data-testid = { `${ testIdLabel } -delegate-button` }
148- isLoading = { isDelegateLoading }
149- onClick = { onClickDelegate }
150- size = { isMobile ? "medium" : "large" }
151- sx = { { flex : screenWidth < 768 ? 1 : undefined } }
152- variant = "contained"
153- >
154- { t ( "delegate" ) }
155- </ Button >
156- )
157- ) }
158- </ Box >
163+ { renderActionButtons ( ) }
159164 </ >
160165 ) }
161166 </ Card >
0 commit comments