11import { FC , ReactNode } from 'react'
22import { useTranslation } from 'react-i18next'
3- import CheckCircleIcon from '@mui/icons-material/CheckCircle'
4- import CancelIcon from '@mui/icons-material/Cancel'
53import { COLORS } from '../../../styles/theme/colors'
6- import HelpIcon from '@mui/icons-material/Help'
7- import LockIcon from '@mui/icons-material/Lock'
84import { TxError } from '../../../oasis-nexus/api'
95import { Tooltip } from '@oasisprotocol/ui-library/src/components/tooltip'
106import { useTxErrorMessage } from '../../hooks/useTxErrorMessage'
117import { TFunction } from 'i18next'
128import { cn } from '@oasisprotocol/ui-library/src/lib/utils'
9+ import { CircleCheck , CircleX , CircleHelp , Clock } from 'lucide-react'
1310
14- type TxStatus = 'unknown' | 'success' | 'partialsuccess' | ' failure' | 'pending'
11+ type TxStatus = 'unknown' | 'success' | 'failure' | 'pending'
1512
1613const statusBgColor : Record < TxStatus , string > = {
17- unknown : COLORS . grayMediumLight ,
18- success : COLORS . eucalyptus ,
19- partialsuccess : COLORS . honeydew ,
20- failure : COLORS . linen ,
21- pending : COLORS . warningLight ,
14+ unknown : 'bg-zinc-500' ,
15+ success : 'bg-success' ,
16+ failure : 'bg-destructive' ,
17+ pending : 'bg-zinc-500' ,
2218}
2319
24- const statusFgColor : Record < TxStatus , string > = {
25- unknown : COLORS . grayMedium ,
26- success : COLORS . honeydew ,
27- partialsuccess : COLORS . eucalyptus ,
28- failure : COLORS . errorIndicatorBackground ,
29- pending : COLORS . warningColor ,
30- }
20+ const statusIcon = ( status : TxStatus , size : number , withText ?: boolean ) : ReactNode => {
21+ // [&_circle]:stroke-transparent fixes background animation on new transactions
22+ const strokeClass = withText ? 'stroke-background' : '[&_circle]:stroke-transparent'
3123
32- const statusIcon : Record < TxStatus , ReactNode > = {
33- unknown : < LockIcon color = "inherit" fontSize = "inherit" /> ,
34- success : < CheckCircleIcon color = "inherit" fontSize = "inherit" /> ,
35- partialsuccess : < CheckCircleIcon color = "success" fontSize = "inherit" /> ,
36- failure : < CancelIcon color = "error" fontSize = "inherit" /> ,
37- pending : < HelpIcon color = "inherit" fontSize = "inherit" /> ,
24+ switch ( status ) {
25+ case 'unknown' :
26+ return < CircleHelp size = { size } className = { cn ( 'fill-zinc-500' , strokeClass ) } />
27+ case 'success' :
28+ return < CircleCheck size = { size } className = { cn ( 'fill-success' , strokeClass ) } />
29+ case 'failure' :
30+ return < CircleX size = { size } className = { cn ( 'fill-destructive' , strokeClass ) } />
31+ case 'pending' :
32+ return < Clock size = { size } className = { cn ( 'fill-zinc-500' , strokeClass ) } />
33+ }
3834}
3935
4036interface StatusBadgeProps {
@@ -46,13 +42,10 @@ interface StatusBadgeProps {
4642export const StatusBadge : FC < StatusBadgeProps > = ( { status, children, withText } ) => (
4743 < div
4844 className = { cn (
49- 'flex justify-center items-center text-sm rounded-lg' ,
50- withText ? 'px-3 py-1' : 'w-7 min-h-7 p-1' ,
45+ 'flex justify-center items-center text-sm rounded-lg text-background' ,
46+ withText ? 'px-3 py-1' : 'p-0' ,
47+ withText && statusBgColor [ status ] ,
5148 ) }
52- style = { {
53- backgroundColor : statusBgColor [ status ] ,
54- color : statusFgColor [ status ] ,
55- } }
5649 >
5750 { children }
5851 </ div >
@@ -106,6 +99,13 @@ const getPendingLabel = (t: TFunction, method: string | undefined, withText?: bo
10699 return t ( 'transaction.startedDescription' , { method : translatedMethod } )
107100}
108101
102+ const getUnknownLabel = ( t : TFunction , withText ?: boolean ) => {
103+ if ( withText ) {
104+ return t ( 'common.unknown' )
105+ }
106+ return t ( 'transaction.tooltips.statusEncrypted' )
107+ }
108+
109109export const StatusIcon : FC < StatusIconProps > = ( { success, error, withText, method } ) => {
110110 const { t } = useTranslation ( )
111111 const status : TxStatus =
@@ -117,41 +117,40 @@ export const StatusIcon: FC<StatusIconProps> = ({ success, error, withText, meth
117117 ? 'success'
118118 : 'failure'
119119 const statusLabel : Record < TxStatus , string > = {
120- unknown : t ( 'common.unknown' ) ,
120+ unknown : getUnknownLabel ( t , withText ) ,
121121 success : t ( 'common.success' ) ,
122- partialsuccess : t ( 'common.partial_success' ) ,
123122 failure : t ( 'common.failed' ) ,
124123 pending : getPendingLabel ( t , method , withText ) ,
125124 }
126125 const errorMessage = useTxErrorMessage ( error )
126+ const iconSize = withText ? 16 : 20
127127
128128 if ( withText ) {
129129 return (
130130 < >
131131 < div
132132 className = { cn (
133- 'flex justify-center items-center text-sm rounded-lg' ,
134- withText ? 'px-3 py-1' : 'w-7 min-h-7 p-1' ,
133+ 'flex justify-center items-center text-sm rounded-full text-background gap-2' ,
134+ withText ? 'px-4 py-0.5' : 'w-7 min-h-7 p-1' ,
135+ withText && statusBgColor [ status ] ,
135136 ) }
136- style = { {
137- backgroundColor : statusBgColor [ status ] ,
138- color : statusFgColor [ status ] ,
139- } }
140137 >
141138 { statusLabel [ status ] }
142-
143- { statusIcon [ status ] }
139+ { statusIcon ( status , iconSize , withText ) }
144140 </ div >
145141 { errorMessage && < StatusDetails error > { errorMessage } </ StatusDetails > }
146142 { ! errorMessage && status === 'pending' && < StatusDetails > { getPendingLabel ( t , method ) } </ StatusDetails > }
143+ { status === 'unknown' && < StatusDetails > { getUnknownLabel ( t ) } </ StatusDetails > }
147144 </ >
148145 )
149146 } else {
150147 return (
151148 < Tooltip title = { errorMessage ? `${ statusLabel [ status ] } : ${ errorMessage } ` : statusLabel [ status ] } >
152- < StatusBadge status = { status } withText = { withText } >
153- { statusIcon [ status ] }
154- </ StatusBadge >
149+ < div >
150+ < StatusBadge status = { status } withText = { withText } >
151+ { statusIcon ( status , iconSize , withText ) }
152+ </ StatusBadge >
153+ </ div >
155154 </ Tooltip >
156155 )
157156 }
0 commit comments