-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1472 from oasisprotocol/mz/newtxList
Add details column to Consensus transactions list
- Loading branch information
Showing
9 changed files
with
402 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Sync Consensus transactions list with updated designs |
84 changes: 84 additions & 0 deletions
84
src/app/components/Transactions/ConsensusTransactionDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { FC } from 'react' | ||
import { TFunction } from 'i18next' | ||
import Box from '@mui/material/Box' | ||
import { ConsensusTxMethod, Transaction } from '../../../oasis-nexus/api' | ||
import { From, LabelValue, Shares, To } from './TransactionDetailsElements' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
type ConsensusTransactionDetailsProps = { | ||
ownAddress?: string | ||
transaction: Transaction | ||
} | ||
|
||
export const ConsensusTransactionDetails: FC<ConsensusTransactionDetailsProps> = ({ | ||
ownAddress, | ||
transaction, | ||
}) => { | ||
const { t } = useTranslation() | ||
const details = getConsensusTransactionDetails(t, transaction, ownAddress) | ||
|
||
return <Box sx={{ display: 'flex', flexWrap: 'no-wrap', gap: '20px' }}>{details}</Box> | ||
} | ||
|
||
const getConsensusTransactionDetails = (t: TFunction, transaction: Transaction, ownAddress?: string) => { | ||
const scope = { layer: transaction.layer, network: transaction.network } | ||
|
||
switch (transaction.method) { | ||
case ConsensusTxMethod.roothashExecutorCommit: | ||
return ( | ||
<> | ||
<From address={transaction.sender} ownAddress={ownAddress} scope={scope} /> | ||
<LabelValue label={t('common.id')} value={transaction.body?.id} trimMobile /> | ||
</> | ||
) | ||
case ConsensusTxMethod.stakingAddEscrow: | ||
return ( | ||
<> | ||
<From address={transaction.sender} ownAddress={ownAddress} scope={scope} /> | ||
<To | ||
address={transaction.to} | ||
label={t('validator.title')} | ||
ownAddress={ownAddress} | ||
scope={scope} | ||
type="validator" | ||
/> | ||
</> | ||
) | ||
case ConsensusTxMethod.stakingAllow: | ||
return ( | ||
<> | ||
<From address={transaction.sender} ownAddress={ownAddress} scope={scope} /> | ||
<To address={transaction.to} label={t('common.recipient')} ownAddress={ownAddress} scope={scope} /> | ||
</> | ||
) | ||
case ConsensusTxMethod.stakingReclaimEscrow: | ||
return ( | ||
<> | ||
<From address={transaction.sender} ownAddress={ownAddress} scope={scope} /> | ||
<To | ||
address={transaction.to} | ||
label={t('validator.title')} | ||
scope={scope} | ||
ownAddress={ownAddress} | ||
type="validator" | ||
/> | ||
<Shares value={transaction.body.shares} /> | ||
</> | ||
) | ||
case ConsensusTxMethod.stakingTransfer: | ||
return ( | ||
<> | ||
<From address={transaction.sender} ownAddress={ownAddress} scope={scope} /> | ||
<To address={transaction.to} ownAddress={ownAddress} scope={scope} /> | ||
</> | ||
) | ||
default: | ||
return ( | ||
<From | ||
address={transaction.sender} | ||
ownAddress={ownAddress} | ||
scope={{ layer: transaction.layer, network: transaction.network }} | ||
/> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/app/components/Transactions/TransactionDetailsElements.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { FC, PropsWithChildren } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import Box from '@mui/material/Box' | ||
import Tooltip from '@mui/material/Tooltip' | ||
import Typography from '@mui/material/Typography' | ||
import { SearchScope } from '../../../types/searchScope' | ||
import { COLORS } from '../../../styles/theme/colors' | ||
import { tooltipDelay } from '../../../styles/theme' | ||
import { RoundedBalance } from '../../components/RoundedBalance' | ||
import { trimLongString } from '../../utils/trimLongString' | ||
import { useScreenSize } from '../../hooks/useScreensize' | ||
import { AccountLink } from '../Account/AccountLink' | ||
import { ValidatorLink } from '../Validators/ValidatorLink' | ||
|
||
const Label: FC<PropsWithChildren> = ({ children }) => { | ||
return ( | ||
<Typography color={COLORS.grayDark} sx={{ paddingRight: 4 }}> | ||
{children} | ||
</Typography> | ||
) | ||
} | ||
|
||
type FromProps = { | ||
address: string | ||
ownAddress?: string | ||
scope: SearchScope | ||
} | ||
|
||
export const From: FC<FromProps> = ({ address, ownAddress, scope }) => { | ||
const { t } = useTranslation() | ||
|
||
if (!address) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Box sx={{ display: 'inline-flex' }}> | ||
<Label>{t('common.from')}</Label> | ||
<AccountLink labelOnly={address === ownAddress} scope={scope} address={address} alwaysTrim /> | ||
</Box> | ||
) | ||
} | ||
|
||
type ToProps = { | ||
address: string | undefined | ||
label?: string | ||
ownAddress?: string | ||
scope: SearchScope | ||
type?: 'account' | 'validator' | ||
} | ||
|
||
export const To: FC<ToProps> = ({ address, label, ownAddress, scope, type = 'account' }) => { | ||
const { t } = useTranslation() | ||
|
||
if (!address) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Box sx={{ display: 'inline-flex' }}> | ||
<Label>{label || t('common.to')}</Label> | ||
{type === 'account' && ( | ||
<AccountLink labelOnly={address === ownAddress} scope={scope} address={address} alwaysTrim /> | ||
)} | ||
{type === 'validator' && <ValidatorLink network={scope.network} address={address} alwaysTrim />} | ||
</Box> | ||
) | ||
} | ||
|
||
type SharesProps = { | ||
value: string | ||
} | ||
|
||
export const Shares: FC<SharesProps> = ({ value }) => { | ||
const { t } = useTranslation() | ||
|
||
if (!value) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Box sx={{ display: 'inline-flex' }}> | ||
<Label>{t('common.shares')}</Label> | ||
<Typography fontWeight={700}> | ||
<RoundedBalance compactLargeNumbers value={value} /> | ||
</Typography> | ||
</Box> | ||
) | ||
} | ||
|
||
type LabelValueProps = { | ||
label?: string | ||
trimMobile?: boolean | ||
value: string | ||
} | ||
|
||
export const LabelValue: FC<LabelValueProps> = ({ label, trimMobile, value }) => { | ||
const { t } = useTranslation() | ||
const { isTablet } = useScreenSize() | ||
const trimEnabled = trimMobile && isTablet | ||
|
||
return ( | ||
<Box sx={{ display: 'inline-flex' }}> | ||
<Label>{label || t('common.value')}</Label> | ||
{trimEnabled ? ( | ||
<Tooltip arrow placement="top" title={value} enterDelay={tooltipDelay} enterNextDelay={tooltipDelay}> | ||
<Typography variant="mono">{trimLongString(value, 2, 18)}</Typography> | ||
</Tooltip> | ||
) : ( | ||
<Typography variant="mono">{value}</Typography> | ||
)} | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.