Skip to content

Commit

Permalink
feat: display tx page cell status icon on node-connect mode (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
PainterPuppets authored Jul 17, 2024
1 parent c7848f8 commit 894b910
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
17 changes: 16 additions & 1 deletion src/pages/Transaction/TransactionCell/NodeTransactionCell.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState, ReactNode } from 'react'
import { Tooltip } from 'antd'
import type { Cell } from '@ckb-lumos/base'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import { Link } from '../../../components/Link'
import { IOType } from '../../../constants/common'
Expand All @@ -17,7 +18,7 @@ import {
TransactionCellInfoPanel,
TransactionCellMobileItem,
} from './styled'
import { LeftArrow } from '../../../components/Transaction/TransactionCellArrow'
import { LeftArrow, CellOutputIcon } from '../../../components/Transaction/TransactionCellArrow'
import { NodeCellCapacityAmount } from '../../../components/TransactionItem/TransactionItemCell/NodeCellCapacityAmount'
import NervosDAODepositIcon from '../../../assets/nervos_dao_cell.png'
import NervosDAOWithdrawingIcon from '../../../assets/nervos_dao_withdrawing.png'
Expand All @@ -35,6 +36,7 @@ import { useIsMobile } from '../../../hooks'
import { getCellType } from '../../../utils/cell'
import { encodeNewAddress, encodeDeprecatedAddress } from '../../../utils/address'
import { Addr } from './index'
import { useCKBNode } from '../../../hooks/useCKBNode'

const TransactionCellIndexAddress = ({
cell,
Expand All @@ -47,10 +49,22 @@ const TransactionCellIndexAddress = ({
index: number
isAddrNew: boolean
}) => {
const { nodeService, isActivated } = useCKBNode()
const deprecatedAddr = encodeDeprecatedAddress(cell.cellOutput.lock)
const newAddr = encodeNewAddress(cell.cellOutput.lock)
const address = isAddrNew ? newAddr : deprecatedAddr

const cellStatus = useQuery(
['cellStatus', cell.outPoint],
async () => {
if (!cell.outPoint) return 'dead'
const liveCell = await nodeService.rpc.getLiveCell(cell.outPoint, false)
if (liveCell.status === 'live') return 'live'
return 'dead'
},
{ enabled: isActivated && cell.outPoint && ioType && ioType === IOType.Output },
)

return (
<TransactionCellAddressPanel>
<div className="transactionCellIndex">
Expand All @@ -63,6 +77,7 @@ const TransactionCellIndexAddress = ({
</Link>
)}
<Addr address={address ?? ''} isCellBase={false} />
{ioType === IOType.Output && <CellOutputIcon cell={{ status: cellStatus.data ?? 'dead' }} />}
</TransactionCellHashPanel>
</TransactionCellAddressPanel>
)
Expand Down
16 changes: 8 additions & 8 deletions src/pages/Transaction/TransactionCell/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@
> span {
margin: 0 3px;
}
}

.transactionCellAddressLink {
max-width: 70%;
.transactionCellAddressLink {
max-width: 70%;

@media (max-width: $mobileBreakPoint) {
max-width: unset;
}
@media (max-width: $mobileBreakPoint) {
max-width: unset;
}
}

.transactionCellAddressNoLink {
color: #000;
}
.transactionCellAddressNoLink {
color: #000;
}

.transactionCellAddressPanel {
Expand Down

0 comments on commit 894b910

Please sign in to comment.