Skip to content

Commit

Permalink
fix: wrong stake statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom committed Sep 25, 2024
1 parent 6c954a3 commit 107931b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { StakingTxDepositInfo } from '@safe-global/safe-gateway-typescript-
import {
ConfirmationViewTypes,
type NativeStakingDepositConfirmationView,
NativeStakingStatus,
} from '@safe-global/safe-gateway-typescript-sdk'
import ConfirmationOrderHeader from '@/components/tx/ConfirmationOrder/ConfirmationOrderHeader'
import { formatDurationFromSeconds, formatVisualAmount } from '@/utils/formatters'
Expand Down Expand Up @@ -79,9 +78,7 @@ const StakingConfirmationTxDeposit = ({ order }: StakingOrderConfirmationViewPro
<FieldsGrid title="Validators">{order.numValidators}</FieldsGrid>
)}

{!isOrder && order.status === NativeStakingStatus.VALIDATION_STARTED ? null : (
<FieldsGrid title="Active in">{formatDurationFromSeconds(order.estimatedEntryTime)}</FieldsGrid>
)}
<FieldsGrid title="Activation time">{formatDurationFromSeconds(order.estimatedEntryTime)}</FieldsGrid>

<FieldsGrid title="Rewards">Approx. every 5 days after activation</FieldsGrid>

Expand Down
56 changes: 28 additions & 28 deletions src/features/stake/components/StakingStatus/index.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import { NativeStakingExitStatus, NativeStakingStatus } from '@safe-global/safe-gateway-typescript-sdk'
import { NativeStakingStatus } from '@safe-global/safe-gateway-typescript-sdk'
import { SvgIcon } from '@mui/material'
import CheckIcon from '@/public/images/common/circle-check.svg'
import ClockIcon from '@/public/images/common/clock.svg'
import SlashShield from '@/public/images/common/shield-off.svg'
import SignatureIcon from '@/public/images/common/document_signature.svg'
import TxStatusChip, { type TxStatusChipProps } from '@/components/transactions/TxStatusChip'

const ColorIcons: Record<
NativeStakingStatus | NativeStakingExitStatus,
NativeStakingStatus,
| {
color: TxStatusChipProps['color']
icon?: React.ComponentType
text: string
}
| undefined
> = {
[NativeStakingStatus.AWAITING_ENTRY]: {
[NativeStakingStatus.NOT_STAKED]: {
color: 'warning',
icon: SignatureIcon,
text: 'Signature needed',
},
[NativeStakingStatus.ACTIVATING]: {
color: 'info',
icon: ClockIcon,
text: 'Activating',
},
[NativeStakingStatus.REQUESTED_EXIT]: {
[NativeStakingStatus.DEPOSIT_IN_PROGRESS]: {
color: 'info',
icon: ClockIcon,
text: 'Requested exit',
},
[NativeStakingStatus.SIGNATURE_NEEDED]: {
color: 'warning',
icon: SignatureIcon,
text: 'Signature needed',
},
[NativeStakingStatus.AWAITING_EXECUTION]: {
color: 'warning',
icon: ClockIcon,
text: 'Awaiting execution',
text: 'Awaiting entry',
},
[NativeStakingStatus.VALIDATION_STARTED]: {
[NativeStakingStatus.ACTIVE]: {
color: 'success',
icon: CheckIcon,
text: 'Validation started',
},
[NativeStakingStatus.WITHDRAWN]: {
color: 'success',
icon: CheckIcon,
text: 'Withdrawn',
},
[NativeStakingExitStatus.READY_TO_WITHDRAW]: {
color: 'success',
icon: CheckIcon,
text: 'Ready to withdraw',
[NativeStakingStatus.EXIT_REQUESTED]: {
color: 'info',
icon: ClockIcon,
text: 'Requested exit',
},
[NativeStakingExitStatus.REQUEST_PENDING]: {
[NativeStakingStatus.EXITING]: {
color: 'info',
icon: ClockIcon,
text: 'Request pending',
},
[NativeStakingStatus.UNKNOWN]: undefined,
[NativeStakingStatus.EXITED]: {
color: 'success',
icon: CheckIcon,
text: 'Withdrawn',
},
[NativeStakingStatus.SLASHED]: {
color: 'warning',
icon: SlashShield,
text: 'Slashed',
},
}

const capitalizedStatus = (status: string) =>
Expand All @@ -63,7 +63,7 @@ const capitalizedStatus = (status: string) =>
.replace(/_/g, ' ')
.replace(/^\w/g, (l) => l.toUpperCase())

const StakingStatus = ({ status }: { status: NativeStakingStatus | NativeStakingExitStatus }) => {
const StakingStatus = ({ status }: { status: NativeStakingStatus }) => {
const config = ColorIcons[status]

return (
Expand Down
10 changes: 5 additions & 5 deletions src/features/stake/components/StakingTxExitDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Box } from '@mui/material'
import type { StakingTxExitInfo, TransactionData } from '@safe-global/safe-gateway-typescript-sdk'
import { NativeStakingExitStatus } from '@safe-global/safe-gateway-typescript-sdk'
import { NativeStakingStatus } from '@safe-global/safe-gateway-typescript-sdk'
import FieldsGrid from '@/components/tx/FieldsGrid'
import TokenAmount from '@/components/common/TokenAmount'
import StakingStatus from '@/features/stake/components/StakingStatus'
import { formatDurationFromSeconds } from '@/utils/formatters'

const StakingTxExitDetails = ({ info }: { info: StakingTxExitInfo; txData?: TransactionData }) => {
const withdrawIn = formatDurationFromSeconds(info.estimatedExitTime + info.estimatedWithdrawalTime, ['days', 'hours'])

console.log('staking tx exit details', info.status, NativeStakingStatus.EXITED)
return (
<Box pl={1} pr={5} display="flex" flexDirection="column" gap={1}>
<FieldsGrid title="Receive">
Expand All @@ -23,11 +25,9 @@ const StakingTxExitDetails = ({ info }: { info: StakingTxExitInfo; txData?: Tran
{info.numValidators} Validator{info.numValidators > 1 ? 's' : ''}
</FieldsGrid>

{info.status !== NativeStakingExitStatus.READY_TO_WITHDRAW && (
<FieldsGrid title="Est. exit time">Up to {withdrawIn}</FieldsGrid>
)}
{info.status !== NativeStakingStatus.EXITED && <FieldsGrid title="Est. exit time">Up to {withdrawIn}</FieldsGrid>}

<FieldsGrid title="Exit">
<FieldsGrid title="Validator status">
<StakingStatus status={info.status} />
</FieldsGrid>
</Box>
Expand Down

0 comments on commit 107931b

Please sign in to comment.