Skip to content

Commit

Permalink
refactor: validator exit
Browse files Browse the repository at this point in the history
Instead of displaying the value for exiting a validator, we now display
the validator amount that we are exiting.
  • Loading branch information
compojoom committed Sep 27, 2024
1 parent cea76a7 commit b55d1ad
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/components/transactions/TxDetails/TxData/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const TxData = ({
}

if (isStakingTxExitInfo(txDetails.txInfo)) {
return <StakingTxExitDetails txData={txDetails.txData} info={txDetails.txInfo} />
return <StakingTxExitDetails info={txDetails.txInfo} />
}

if (isStakingTxWithdrawInfo(txDetails.txInfo)) {
Expand Down
3 changes: 1 addition & 2 deletions src/features/stake/components/StakingConfirmationTx/Exit.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Alert, Stack, Typography } from '@mui/material'
import FieldsGrid from '@/components/tx/FieldsGrid'
import type { StakingTxExitInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { formatDurationFromMilliseconds } from '@/utils/formatters'
import { type NativeStakingValidatorsExitConfirmationView } from '@safe-global/safe-gateway-typescript-sdk/dist/types/decoded-data'
import ConfirmationOrderHeader from '@/components/tx/ConfirmationOrder/ConfirmationOrderHeader'
import { InfoTooltip } from '@/features/stake/components/InfoTooltip'

type StakingOrderConfirmationViewProps = {
order: NativeStakingValidatorsExitConfirmationView | StakingTxExitInfo
order: NativeStakingValidatorsExitConfirmationView
}

const StakingConfirmationTxExit = ({ order }: StakingOrderConfirmationViewProps) => {
Expand Down
4 changes: 2 additions & 2 deletions src/features/stake/components/StakingTxDepositInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StakingTxInfo } from '@safe-global/safe-gateway-typescript-sdk'
import type { StakingTxDepositInfo as StakingTxDepositInfoType } from '@safe-global/safe-gateway-typescript-sdk'
import TokenAmount from '@/components/common/TokenAmount'

export const StakingTxDepositInfo = ({ info }: { info: StakingTxInfo }) => {
export const StakingTxDepositInfo = ({ info }: { info: StakingTxDepositInfoType }) => {
return (
<>
<TokenAmount
Expand Down
45 changes: 28 additions & 17 deletions src/features/stake/components/StakingTxExitDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import { Box } from '@mui/material'
import type { StakingTxExitInfo, TransactionData } from '@safe-global/safe-gateway-typescript-sdk'
import { Box, Link } from '@mui/material'
import type { StakingTxExitInfo } 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 { formatDurationFromMilliseconds } from '@/utils/formatters'
import { BEACON_CHAIN_EXPLORERS } from '@/features/stake/constants'
import useChainId from '@/hooks/useChainId'

const StakingTxExitDetails = ({ info, txData }: { info: StakingTxExitInfo; txData?: TransactionData }) => {
const StakingTxExitDetails = ({ info }: { info: StakingTxExitInfo }) => {
const withdrawIn = formatDurationFromMilliseconds(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">
<TokenAmount
value={info.value}
tokenSymbol={info.tokenInfo.symbol}
decimals={info.tokenInfo.decimals}
logoUri={info.tokenInfo.logoUri}
/>
</FieldsGrid>

<Box pr={5} display="flex" flexDirection="column" gap={1}>
<FieldsGrid title="Exit">
{info.numValidators} Validator{info.numValidators > 1 ? 's' : ''}
{info.validators.map((validator: string, index: number) => {
return (
<>
<BeaconChainLink name={`Validator ${index + 1}`} validator={validator} key={index} />
{index < info.validators.length - 1 && ' | '}
</>
)
})}
</FieldsGrid>

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

<FieldsGrid title="Validator status">
Expand All @@ -37,4 +34,18 @@ const StakingTxExitDetails = ({ info, txData }: { info: StakingTxExitInfo; txDat
)
}

export const BeaconChainLink = ({ validator, name }: { validator: string; name: string }) => {
const chainId = useChainId()
return (
<Link
variant="body1"
target="_blank"
href={`${
BEACON_CHAIN_EXPLORERS[chainId as keyof typeof BEACON_CHAIN_EXPLORERS] ?? 'https://beaconcha.in'
}/validator/${validator}`}
>
{name}
</Link>
)
}
export default StakingTxExitDetails
12 changes: 3 additions & 9 deletions src/features/stake/components/StakingTxExitInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import type { StakingTxInfo } from '@safe-global/safe-gateway-typescript-sdk'
import TokenAmount from '@/components/common/TokenAmount'
import type { StakingTxExitInfo } from '@safe-global/safe-gateway-typescript-sdk'

const StakingTxExitInfo = ({ info }: { info: StakingTxInfo }) => {
const StakingTxExitInfo = ({ info }: { info: StakingTxExitInfo }) => {
return (
<>
<TokenAmount
value={info.value}
tokenSymbol={info.tokenInfo.symbol}
decimals={info.tokenInfo.decimals}
logoUri={info.tokenInfo.logoUri}
/>
{info.numValidators} Validator{info.numValidators > 1 ? 's' : ''}
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const StakingTxWithdrawInfo = ({ info }: { info: StakingTxWithdrawInfo }) => {
return (
<>
<TokenAmount
value={info.rewards}
value={info.value}
tokenSymbol={info.tokenInfo.symbol}
decimals={info.tokenInfo.decimals}
logoUri={info.tokenInfo.logoUri}
Expand Down
6 changes: 6 additions & 0 deletions src/features/stake/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export const widgetAppData = {
iconUrl: '/images/common/stake.svg',
chainIds: ['17000', '11155111', '1', '42161', '137', '56', '8453', '10'],
}

// TODO: move this to the config service
export const BEACON_CHAIN_EXPLORERS = {
'1': 'https://beaconcha.in',
'17000': 'https://holesky.beaconcha.in',
}

0 comments on commit b55d1ad

Please sign in to comment.