Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Display live cells of a specific address #1597

Merged
merged 16 commits into from
Jun 7, 2024
Merged
23 changes: 19 additions & 4 deletions src/pages/Address/Cells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
let assetName = null
let attribute = null
let detailInfo = null
let assetTypeText = assetType
switch (assetType) {
case 'ckb': {
assetTypeText = 'CKB'
if (cell.typeHash) {
icon = <TypeHashIcon />
assetName = 'UNKNOWN ASSET'
Expand Down Expand Up @@ -98,6 +100,7 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
case 'udt': {
icon = SUDTTokenIcon
assetName = cell.extraInfo.symbol || 'UDT'
assetTypeText = 'UDT'
attribute = cell.extraInfo.decimal
? parseUDTAmount(cell.extraInfo.amount, cell.extraInfo.decimal)
: 'Unknown UDT amount'
Expand All @@ -107,6 +110,7 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
case 'xudt': {
icon = SUDTTokenIcon
assetName = cell.extraInfo?.symbol || 'xUDT'
assetTypeText = 'xUDT'
attribute =
cell.extraInfo?.decimal && cell.extraInfo?.amount
? parseUDTAmount(cell.extraInfo.amount, cell.extraInfo.decimal)
Expand All @@ -117,6 +121,7 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
case 'omiga_inscription': {
icon = SUDTTokenIcon
assetName = cell.extraInfo.symbol || t('udt.inscription')
assetTypeText = 'xUDT'
attribute = cell.extraInfo.decimal
? parseUDTAmount(cell.extraInfo.amount, cell.extraInfo.decimal)
: 'Unknown amount'
Expand All @@ -126,6 +131,7 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
case 'spore_cell': {
icon = <SporeCellIcon />
assetName = 'DOB'
assetTypeText = 'NFT'
if (cell.data.length > ATTRIBUTE_LENGTH) {
attribute = `${cell.data.slice(0, ATTRIBUTE_LENGTH)}...`
} else {
Expand All @@ -137,6 +143,7 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
case 'spore_cluster': {
icon = <SporeCluterIcon />
assetName = 'Spore Cluster'
assetTypeText = 'NFT'
if (cell.data.length > ATTRIBUTE_LENGTH) {
attribute = `${cell.data.slice(0, ATTRIBUTE_LENGTH)}...`
} else {
Expand All @@ -147,20 +154,27 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
}
case 'nrc_721': {
icon = SUDTTokenIcon
assetTypeText = 'NFT'
assetName = !cell.extraInfo.symbol
? '?'
: sliceNftName(`${cell.extraInfo.symbol} #${cell.extraInfo.typeHash.slice(0, 3)}`)
attribute = cell.extraInfo.amount
if (cell.extraInfo.amount.length > ATTRIBUTE_LENGTH) {
attribute = `${cell.extraInfo.amount.slice(0, ATTRIBUTE_LENGTH)}...`
} else {
attribute = cell.extraInfo.amount
}
break
}
case 'm_nft': {
icon = SUDTTokenIcon
assetTypeText = 'NFT'
assetName = cell.extraInfo.className
attribute = `#${parseInt(cell.extraInfo.tokenId, 16)}`
attribute = cell.extraInfo.tokenId ? `#${parseInt(cell.extraInfo.tokenId, 16)}` : '/'
break
}
default: {
icon = SUDTTokenIcon
assetTypeText = 'Unknown Cell'
assetName = 'UNKNOWN'
attribute = '-'
}
Expand All @@ -185,6 +199,7 @@ const getCellDetails = (cell: LiveCell, t: TFunction) => {
title,
parsedBlockCreateAt,
cellInfo,
assetTypeText,
}
}

Expand Down Expand Up @@ -234,15 +249,15 @@ const CellTable: FC<{ cells: LiveCell[] }> = ({ cells }) => {
</thead>
<tbody>
{cells.map((cell, index) => {
const { ckb, outPointStr, assetName, attribute, cellInfo } = getCellDetails(cell, t)
const { ckb, outPointStr, assetName, attribute, cellInfo, assetTypeText } = getCellDetails(cell, t)

return (
<tr key={cell.txHash + cell.cellIndex}>
<td>{index + 1}</td>
<td>{cell.blockNumber}</td>
<td>{outPointStr}</td>
<td>{ckb}</td>
<td>{cell.extraInfo?.type}</td>
<td>{assetTypeText}</td>
<td>
{attribute} {attribute === 'Unknown amount' ? '' : assetName}
</td>
Expand Down