Skip to content

Commit

Permalink
feat(address): nrc 721 (#298)
Browse files Browse the repository at this point in the history
* feat(address): nrc 721

* feat(nrc721): add the prefix word `id:` for token id

---------

Signed-off-by: Chen Yu <[email protected]>
Co-authored-by: Chen Yu <[email protected]>
  • Loading branch information
Daryl-L and Keith-CY authored May 11, 2024
1 parent bcda583 commit 019d43e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
25 changes: 5 additions & 20 deletions src/pages/Address/AddressAssetComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { formatNftDisplayId, handleNftImgError, hexToBase64, patchMibaoImg } fro
import { getDobs } from '../../services/DobsService'
import { sliceNftName } from '../../utils/string'
import styles from './addressAssetComp.module.scss'
import EllipsisMiddle from '../../components/EllipsisMiddle'

export const AddressAssetComp = ({
href,
Expand Down Expand Up @@ -51,9 +52,7 @@ export const AddressAssetComp = ({
)}
<div className={styles.fields}>
<div className={styles.assetName}>{name}</div>
<div className={styles.attribute} title={property}>
{property}
</div>
<EllipsisMiddle className={styles.attribute} text={property} />
</div>
</div>
</a>
Expand Down Expand Up @@ -177,16 +176,7 @@ export const AddressMNFTComp = ({ account, isRGBPP }: { account: MNFT; isRGBPP?:
)
}

export const AddressNRC721Comp = ({
account,
isRGBPP,
isMerged = false,
}: {
account: NRC721
isRGBPP?: boolean
isMerged?: boolean
}) => {
const { t } = useTranslation()
export const AddressNRC721Comp = ({ account, isRGBPP }: { account: NRC721; isRGBPP?: boolean }) => {
const { symbol, amount, udtIconFile, collection } = account
const [icon, setIcon] = useState(udtIconFile)

Expand All @@ -205,17 +195,12 @@ export const AddressNRC721Comp = ({
})
}, [udtIconFile])

let name = !symbol ? '?' : sliceNftName(symbol)
if (isMerged) {
name = `${t('rgbpp.amount')}: ${(+amount).toLocaleString('en')}`
}

return (
<AddressAssetComp
isRGBPP={isRGBPP ?? false}
href={`/nft-collections/${collection?.typeHash}`}
property={!symbol ? '?' : `#${amount}`}
name={name}
property={`id: ${amount}`}
name={!symbol ? '?' : sliceNftName(`${symbol} #${collection.typeHash.slice(2, 5)}`)}
isUnverified={!symbol}
udtLabel="NRC 721"
icon={{
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Address/AddressComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ export const AddressOverviewCard: FC<{ address: Address }> = ({ address }) => {

case 'm_nft_token':
return <AddressMNFTComp account={udt} key={udt.symbol + udt.udtType + udt.amount} />

case 'nrc_721_token':
return <AddressNRC721Comp account={udt} key={udt.symbol + udt.udtType + udt.amount} />

default:
return null
}
Expand Down
9 changes: 6 additions & 3 deletions src/pages/Address/Cells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useSetToast } from '../../components/Toast'
import { PAGE_SIZE } from '../../constants/common'
import styles from './cells.module.scss'
import SmallLoading from '../../components/Loading/SmallLoading'
import { sliceNftName } from '../../utils/string'

enum Sort {
TimeAsc = 'block_timestamp.asc',
Expand Down Expand Up @@ -164,8 +165,10 @@ const Cell: FC<{ cell: LiveCell }> = ({ cell }) => {
}
case 'nrc_721': {
icon = SUDTTokenIcon
assetName = 'NRC 721'
attribute = '-'
assetName = !cell.extraInfo.symbol
? '?'
: sliceNftName(`${cell.extraInfo.symbol} #${cell.extraInfo.typeHash.slice(0, 3)}`)
attribute = cell.extraInfo.amount
break
}
case 'm_nft': {
Expand Down Expand Up @@ -201,7 +204,7 @@ const Cell: FC<{ cell: LiveCell }> = ({ cell }) => {
<div className={styles.fields}>
<div className={styles.assetName}>{assetName}</div>
<div className={styles.attribute} title={detailInfo ?? attribute}>
{attribute}
<div className={styles.attributeContent}>{attribute}</div>
{detailInfo ? (
<button type="button" className={styles.copy} data-detail={detailInfo} onClick={handleCopy}>
<CopyIcon />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Address/MergedAssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const MergedAssetList: FC<{
case 'spore_cell':
return <AddressSporeComp isRGBPP isMerged account={nft} key={nft.symbol + nft.udtType + nft.amount} />
case 'nrc_721_token':
return <AddressNRC721Comp isRGBPP isMerged account={nft} key={nft.symbol + nft.udtType + nft.amount} />
return <AddressNRC721Comp isRGBPP account={nft} key={nft.symbol + nft.udtType + nft.amount} />
case 'm_nft_token':
return <AddressMNFTComp isRGBPP account={nft} key={nft.symbol + nft.udtType + nft.amount} />
default:
Expand Down
1 change: 1 addition & 0 deletions src/pages/Address/addressAssetComp.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
}

.fields {
width: 100%;
min-width: 0;
display: flex;
flex-direction: column;
Expand Down
6 changes: 6 additions & 0 deletions src/pages/Address/cells.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@

.attribute {
display: flex;

&Content {
text-overflow: ellipsis;
overflow: hidden;
}
}

.copy {
Expand All @@ -147,6 +152,7 @@
}

.fields {
min-width: 0;
display: flex;
flex-direction: column;
justify-content: space-around;
Expand Down

0 comments on commit 019d43e

Please sign in to comment.