Skip to content

Commit

Permalink
Merge pull request #1472 from oasisprotocol/mz/newtxList
Browse files Browse the repository at this point in the history
Add details column to Consensus transactions list
  • Loading branch information
buberdds authored Jul 25, 2024
2 parents a01b899 + 3aaf156 commit 1651e1a
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 76 deletions.
1 change: 1 addition & 0 deletions .changelog/1472.trivial.md
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 src/app/components/Transactions/ConsensusTransactionDetails.tsx
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 }}
/>
)
}
}
93 changes: 23 additions & 70 deletions src/app/components/Transactions/ConsensusTransactions.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import Box from '@mui/material/Box'
import { Transaction } from '../../../oasis-nexus/api'
import { Table, TableCellAlign, TableColProps } from '../../components/Table'
import { RoundedBalance } from '../../components/RoundedBalance'
import { TablePaginationProps } from '../Table/TablePagination'
import { BlockLink } from '../Blocks/BlockLink'
import { AccountLink } from '../Account/AccountLink'
import { StatusIcon } from '../StatusIcon'
import { Age } from '../Age'
import { TransactionLink } from './TransactionLink'
import { ConsensusTransactionMethod } from '../ConsensusTransactionMethod'
import { ConsensusTransactionDetails } from './ConsensusTransactionDetails'

type TableConsensusTransaction = Transaction & {
markAsNew?: boolean
Expand All @@ -28,7 +26,6 @@ type ConsensusTransactionsProps = {
isLoading: boolean
limit: number
pagination: false | TablePaginationProps
verbose?: boolean
}

export const ConsensusTransactions: FC<ConsensusTransactionsProps> = ({
Expand All @@ -37,28 +34,19 @@ export const ConsensusTransactions: FC<ConsensusTransactionsProps> = ({
pagination,
transactions,
ownAddress,
verbose = true,
}) => {
const { t } = useTranslation()

const tableColumns: TableColProps[] = [
{ key: 'status', content: t('common.status') },
{ key: 'hash', content: t('common.hash') },
{ key: 'block', content: t('common.block') },
{ key: 'age', content: t('common.age') },
...(verbose
? [
{ key: 'method', content: t('common.method') },
{ key: 'from', content: t('common.from'), width: '150px' },
{ key: 'to', content: t('common.to'), width: '150px' },
{ key: 'txnFee', content: t('common.transactionFee'), align: TableCellAlign.Right, width: '250px' },
{ key: 'value', align: TableCellAlign.Right, content: t('common.value'), width: '250px' },
]
: []),
{ key: 'type', content: t('common.type') },
{ key: 'details', content: t('common.details') },
{ align: TableCellAlign.Right, key: 'value', content: t('common.amount') },
]

const tableRows = transactions?.map(transaction => {
const targetAddress = transaction.body.to || transaction.body.account
return {
key: `${transaction.hash}${transaction.index}`,
data: [
Expand All @@ -70,64 +58,29 @@ export const ConsensusTransactions: FC<ConsensusTransactionsProps> = ({
content: <TransactionLink scope={transaction} alwaysTrim hash={transaction.hash} />,
key: 'hash',
},
{
content: <BlockLink scope={transaction} height={transaction.block} />,
key: 'round',
},
{
content: <Age sinceTimestamp={transaction.timestamp} />,
key: 'timestamp',
},
...(verbose
? [
{
content: <ConsensusTransactionMethod method={transaction.method} truncate />,
key: 'method',
},
{
align: TableCellAlign.Right,
content: (
<Box
sx={{
display: 'flex',
alignItems: 'center',
position: 'relative',
pr: 3,
}}
>
<AccountLink
labelOnly={transaction.sender === ownAddress}
scope={transaction}
address={transaction.sender}
alwaysTrim
/>
</Box>
),
key: 'from',
},
{
content: targetAddress ? (
<AccountLink
labelOnly={targetAddress === ownAddress}
scope={transaction}
address={targetAddress}
alwaysTrim
/>
) : null,
key: 'to',
},
{
align: TableCellAlign.Right,
content: <RoundedBalance value={transaction.fee} ticker={transaction.ticker} />,
key: 'fee_amount',
},
{
align: TableCellAlign.Right,
content: <RoundedBalance value={transaction.body.amount} ticker={transaction.ticker} />,
key: 'value',
},
]
: []),
{
content: <ConsensusTransactionMethod method={transaction.method} truncate />,
key: 'method',
},

{
content: <ConsensusTransactionDetails ownAddress={ownAddress} transaction={transaction} />,
key: 'details',
},
{
align: TableCellAlign.Right,
content: (
<RoundedBalance
value={transaction.body?.amount || transaction.body?.amount_change}
ticker={transaction.ticker}
/>
),
key: 'amount',
},
],
highlight: transaction.markAsNew,
}
Expand Down
114 changes: 114 additions & 0 deletions src/app/components/Transactions/TransactionDetailsElements.tsx
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>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import { SearchScope } from '../../../types/searchScope'
import { ConsensusTransactions } from '../../components/Transactions'
import { NUMBER_OF_ITEMS_ON_DASHBOARD as limit } from '../../config'
import { RouteUtils } from '../../utils/route-utils'
import { useScreenSize } from '../../hooks/useScreensize'

export const LatestConsensusTransactions: FC<{ scope: SearchScope }> = ({ scope }) => {
const { isTablet } = useScreenSize()
const { t } = useTranslation()
const { network } = scope

Expand Down Expand Up @@ -45,7 +43,6 @@ export const LatestConsensusTransactions: FC<{ scope: SearchScope }> = ({ scope
isLoading={transactionsQuery.isLoading}
limit={limit}
pagination={false}
verbose={!isTablet}
/>
</CardContent>
</Card>
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConsensusTxMethod, Transaction } from '../../oasis-nexus/api'
export const getConsensusTransactionToAddress = (transaction: Transaction) => {
switch (transaction.method) {
case ConsensusTxMethod.stakingAddEscrow:
return transaction.body?.address
return transaction.body?.account
case ConsensusTxMethod.stakingAllow:
return transaction.body?.beneficiary
case ConsensusTxMethod.stakingReclaimEscrow:
Expand Down
Loading

0 comments on commit 1651e1a

Please sign in to comment.