-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Wallet-dashboard): add styles for non visual assets
- Loading branch information
Showing
3 changed files
with
117 additions
and
18 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
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,74 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AssetCategory } from '@/lib/enums'; | ||
import { ArrowTopRight, VisibilityOff } from '@iota/ui-icons'; | ||
import { | ||
Card, | ||
CardAction, | ||
CardActionType, | ||
CardBody, | ||
CardType, | ||
VisualAssetCard, | ||
VisualAssetType, | ||
} from '@iota/apps-ui-kit'; | ||
import { useGetNFTMeta } from '@iota/core'; | ||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { formatAddress, parseStructTag } from '@iota/iota-sdk/utils'; | ||
|
||
interface AssetCardProps { | ||
asset: IotaObjectData; | ||
type: AssetCategory; | ||
onClick?: () => void; | ||
} | ||
|
||
export function AssetCard({ asset, type, onClick }: AssetCardProps): React.JSX.Element { | ||
return type === AssetCategory.Visual ? ( | ||
<VisualAsset asset={asset} icon={<VisibilityOff />} onClick={onClick} /> | ||
) : ( | ||
<NonVisualAssetCard key={asset.digest} asset={asset} onClick={onClick} /> | ||
); | ||
} | ||
|
||
type NonVisualAssetCardProps = { | ||
asset: IotaObjectData; | ||
} & Pick<React.ComponentProps<typeof Card>, 'onClick'>; | ||
|
||
export function NonVisualAssetCard({ asset, onClick }: NonVisualAssetCardProps): React.JSX.Element { | ||
const { address, module, name } = parseStructTag(asset.type!); | ||
return ( | ||
<Card type={CardType.Default} isHoverable onClick={onClick}> | ||
<CardBody | ||
title={formatAddress(asset.objectId!)} | ||
subtitle={`${formatAddress(address)}::${module}::${name}`} | ||
isTextTruncated | ||
/> | ||
<CardAction type={CardActionType.Link} icon={<ArrowTopRight />} /> | ||
</Card> | ||
); | ||
} | ||
|
||
type VisualAssetProps = { | ||
asset: IotaObjectData; | ||
} & Pick<React.ComponentProps<typeof VisualAssetCard>, 'onClick' | 'onIconClick' | 'icon'>; | ||
|
||
export function VisualAsset({ | ||
asset, | ||
icon, | ||
onClick, | ||
onIconClick, | ||
}: VisualAssetProps): React.JSX.Element | null { | ||
const { data: nftMeta } = useGetNFTMeta(asset.objectId); | ||
return asset.display && nftMeta && nftMeta.imageUrl ? ( | ||
<VisualAssetCard | ||
assetSrc={nftMeta?.imageUrl ?? asset?.display?.data?.imageUrl ?? ''} | ||
assetTitle={nftMeta?.name ?? asset?.display?.data?.name} | ||
assetType={VisualAssetType.Image} | ||
altText={nftMeta?.name ?? (asset?.display?.data?.name || 'NFT')} | ||
isHoverable | ||
icon={icon} | ||
onClick={onClick} | ||
onIconClick={onIconClick} | ||
/> | ||
) : null; | ||
} |
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,40 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { ASSETS_ROUTE } from '@/lib/constants/routes.constants'; | ||
import { AssetCategory } from '@/lib/enums'; | ||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { useRouter } from 'next/navigation'; | ||
import { AssetCard } from './AssetCard'; | ||
|
||
interface AssetListProps { | ||
assets: IotaObjectData[]; | ||
selectedCategory: AssetCategory; | ||
} | ||
|
||
const ASSET_LAYOUT: Record<AssetCategory, string> = { | ||
[AssetCategory.Visual]: | ||
'grid-template-visual-assets grid max-h-[600px] gap-md overflow-auto py-sm', | ||
[AssetCategory.Other]: 'flex flex-col overflow-auto py-sm', | ||
}; | ||
|
||
export function AssetList({ assets, selectedCategory }: AssetListProps): React.JSX.Element { | ||
const router = useRouter(); | ||
|
||
function handleAssetClick(asset: IotaObjectData) { | ||
router.push(ASSETS_ROUTE.path + `/${asset.objectId}`); | ||
} | ||
|
||
return ( | ||
<div className={ASSET_LAYOUT[selectedCategory]}> | ||
{assets.map((asset) => ( | ||
<AssetCard | ||
key={asset.digest} | ||
asset={asset} | ||
type={selectedCategory} | ||
onClick={() => handleAssetClick(asset)} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} |