Skip to content

Commit

Permalink
Update logic of delegation card, fix ui issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrotkk committed Nov 13, 2024
1 parent ddfa32b commit a53b441
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 32 deletions.
15 changes: 8 additions & 7 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ body {
width: 100%;
}

.fullH {
height: 100%;
}

.mp__btnConnect {
position: relative;

Expand Down Expand Up @@ -1149,7 +1153,6 @@ input[type=number] {
}
}


.trustedBadge {
color: #0095f6;
}
Expand All @@ -1158,12 +1161,6 @@ input[type=number] {
color: #ffb817;
}

.validatorCard {
height: 100% !important;
cursor: pointer;
}


.pOneLine {
overflow: hidden;
white-space: nowrap;
Expand Down Expand Up @@ -1426,6 +1423,10 @@ input[type=number] {
display: none;
}

.opacity0 {
opacity: 0;
}

.MuiTooltip-tooltip {
font-size: 0.8rem !important;
padding: 8px 12px !important;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default function Tile(props: {
cmn.flex,
cmn.flexcv,
cmn.mbott5,
['pSec', !props.color],
['pSec', !props.color && !props.textColor],
['blackP', props.color]
)}
>
Expand Down
72 changes: 50 additions & 22 deletions src/components/delegation/Delegation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { Collapse, Grid, Tooltip } from '@mui/material'
import ArrowForwardIosRoundedIcon from '@mui/icons-material/ArrowForwardIosRounded'
import AccountBalanceRoundedIcon from '@mui/icons-material/AccountBalanceRounded'
import ApartmentRoundedIcon from '@mui/icons-material/ApartmentRounded'
import AccountCircleRoundedIcon from '@mui/icons-material/AccountCircleRounded'
import HistoryRoundedIcon from '@mui/icons-material/HistoryRounded'

import SkBtn from '../SkBtn'
import ValidatorLogo from './ValidatorLogo'
Expand All @@ -42,16 +44,19 @@ import {
import { formatBigIntTimestampSeconds } from '../../core/timeHelper'

import { convertMonthIndexToText, formatBalance } from '../../core/helper'
import Tile from '../Tile'

export default function Delegation(props: {
delegation: types.staking.IDelegation
validator: types.staking.IValidator
delegationType: types.staking.DelegationType
accept?: (delegationInfo: types.staking.IDelegationInfo) => Promise<void>
unstake?: (delegationInfo: types.staking.IDelegationInfo) => Promise<void>
cancelRequest?: (delegationInfo: types.staking.IDelegationInfo) => Promise<void>
loading: types.staking.IRewardInfo | types.staking.IDelegationInfo | false
isXs: boolean
customAddress: types.AddressType | undefined
isValidatorPage?: boolean
}) {
const source = getDelegationSource(props.delegation)
const delegationAmount = formatBalance(props.delegation.amount, 'SKL')
Expand Down Expand Up @@ -91,26 +96,35 @@ export default function Delegation(props: {
}
}

const noActions =
Number(props.delegation.stateId) !== DelegationState.PROPOSED &&
Number(props.delegation.stateId) !== DelegationState.DELEGATED &&
!isCompleted &&
!props.isValidatorPage

if (!props.validator) return
return (
<div className={cls(cmn.mbott10, 'titleSection')}>
<Grid
container
spacing={0}
alignItems="center"
className="validatorCard"
className={cls('fullH', ['pointer', !noActions])}
onClick={() => {
if (noActions) return
setOpen(!open)
}}
>
<Grid item md={3} xs={12}>
<div className={cls(cmn.flex, cmn.flexcv)}>
<ValidatorLogo validatorId={Number(props.delegation.id + 500n)} size="md" />
<ValidatorLogo
validatorId={props.validator.id}
size="sm"
className="validatorIconDelegation"
/>
{!props.isValidatorPage && (
<ValidatorLogo
validatorId={props.validator.id}
size="sm"
className="validatorIconDelegation"
/>
)}
<div className={cls(cmn.mleft10)}>
<p className={cls(cmn.p, cmn.p2, cmn.p700)}>ID: {Number(props.delegation.id)}</p>
<p className={cls(cmn.p, cmn.p4, cmn.pSec)}>
Expand Down Expand Up @@ -162,22 +176,43 @@ export default function Delegation(props: {
<h4 className={cls(cmn.p, cmn.p700, [cmn.pSec, !isActive])}>{delegationAmount}</h4>
<p className={cls(cmn.p, cmn.p4, cmn.pSec)}>{getStakingText()}</p>
</div>

<ArrowForwardIosRoundedIcon
className={cls(cmn.pSec, styles.chainIconxs, 'rotate-90', ['active', open])}
className={cls(
cmn.pSec,
styles.chainIconxs,
'rotate-90',
['active', open],
['opacity0', noActions]
)}
/>
</div>
</Grid>
</Grid>
<Collapse in={open}>
<div className={cls(cmn.mtop20)}>
{isCompleted ? (
<div className={cls(cmn.mbfott20)}>
<p className={cls(cmn.p, cmn.p3)}>Delegation completed</p>
<p className={cls(cmn.p, cmn.p2, cmn.p700)}>
{convertMonthIndexToText(Number(props.delegation.finished))}
</p>
</div>
) : null}
{props.isValidatorPage && (
<Tile
className={cls(cmn.nop, cmn.mtop20)}
transparent
value={props.delegation.address}
text="Token Holder Address"
grow
size="md"
icon={<AccountCircleRoundedIcon className={cls(styles.chainIconxs)} />}
/>
)}
{isCompleted && (
<Tile
className={cls(cmn.nop, cmn.mtop20)}
transparent
value={convertMonthIndexToText(Number(props.delegation.finished))}
text="Delegation completed"
grow
size="md"
icon={<HistoryRoundedIcon className={cls(styles.chainIconxs)} />}
/>
)}
{Number(props.delegation.stateId) === DelegationState.DELEGATED && props.unstake ? (
<SkBtn
loading={loading}
Expand All @@ -202,13 +237,6 @@ export default function Delegation(props: {
disabled={props.loading !== false || props.customAddress !== undefined}
/>
) : null}
{Number(props.delegation.stateId) !== DelegationState.PROPOSED &&
Number(props.delegation.stateId) !== DelegationState.DELEGATED &&
!isCompleted ? (
<p className={cls(cmn.p, cmn.p3, cmn.pSec, cmn.pCent, cmn.mtop20)}>
No actions available
</p>
) : null}
</div>
</Collapse>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/components/delegation/DelegationTotals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import { useMemo } from 'react'
import { cls, styles } from '@skalenetwork/metaport'
import { cls, styles, useUIStore } from '@skalenetwork/metaport'
import { type types } from '@/core'

import InboxRoundedIcon from '@mui/icons-material/InboxRounded'
Expand All @@ -46,7 +46,7 @@ const DelegationTotals: React.FC<DelegationTotalsProps> = ({ delegations, classN
() => (delegations ? calculateDelegationTotals(delegations) : null),
[delegations]
)

const theme = useUIStore((state) => state.theme)
const getTileText = (status: string, count?: number) => `${status}${count ? ` (${count})` : ''}`

return (
Expand All @@ -56,6 +56,7 @@ const DelegationTotals: React.FC<DelegationTotalsProps> = ({ delegations, classN
text={getTileText('Proposed', totals?.proposed.count)}
grow
size="md"
textColor={totals?.proposed.count ? theme.primary : undefined}
icon={<InboxRoundedIcon className={cls(styles.chainIconxs)} />}
/>
<Tile
Expand Down
1 change: 1 addition & 0 deletions src/pages/Validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default function Validator(props: {
loading={false}
isXs={props.isXs}
customAddress={props.customAddress}
isValidatorPage
/>
))}
{remainingItems > 0 && (
Expand Down

0 comments on commit a53b441

Please sign in to comment.