From 92ddb6b466ba036f58963d268d5ce4f68071977f Mon Sep 17 00:00:00 2001 From: cpl121 <100352899+cpl121@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:47:32 +0100 Subject: [PATCH] fix(wallet-dashboard): other assets (#4574) * fix(wallet-dashboard): other assets * fix(dashboard): simplified code * feat(core): add a new COIN_TYPE constant * fix(dashboard): revert changes of assets array and use new COIN_TYPE constant * fix(dashboard): improve the assets filter * fix(core): linter * fix(explorer): Revert localnet.ts * fix(core): Revert timelock.constants.ts * ' --------- Co-authored-by: Bran <52735957+brancoder@users.noreply.github.com> Co-authored-by: marc2332 --- apps/core/src/constants/coins.constants.ts | 1 + .../app/(protected)/assets/page.tsx | 35 ++++++++++--------- .../components/tiles/AssetTileLink.tsx | 2 +- .../components/tiles/NonVisualAssetTile.tsx | 24 +++++++------ 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/apps/core/src/constants/coins.constants.ts b/apps/core/src/constants/coins.constants.ts index 11fba0c12a0..b0e38e586cd 100644 --- a/apps/core/src/constants/coins.constants.ts +++ b/apps/core/src/constants/coins.constants.ts @@ -3,3 +3,4 @@ export const COINS_QUERY_REFETCH_INTERVAL = 20_000; export const COINS_QUERY_STALE_TIME = 20_000; +export const COIN_TYPE = '0x2::coin::Coin'; diff --git a/apps/wallet-dashboard/app/(protected)/assets/page.tsx b/apps/wallet-dashboard/app/(protected)/assets/page.tsx index 7007cc86c5c..9af8669a717 100644 --- a/apps/wallet-dashboard/app/(protected)/assets/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/assets/page.tsx @@ -4,7 +4,7 @@ 'use client'; import { Panel, Title, Chip, TitleSize } from '@iota/apps-ui-kit'; -import { hasDisplayData, useGetOwnedObjects } from '@iota/core'; +import { COIN_TYPE, hasDisplayData, useGetOwnedObjects } from '@iota/core'; import { useCurrentAccount } from '@iota/dapp-kit'; import { IotaObjectData } from '@iota/iota-sdk/client'; import { useState } from 'react'; @@ -31,25 +31,28 @@ export default function AssetsDashboardPage(): React.JSX.Element { const account = useCurrentAccount(); const { data, isFetching, fetchNextPage, hasNextPage, refetch } = useGetOwnedObjects( account?.address, - undefined, + { + MatchNone: [{ StructType: COIN_TYPE }], + }, OBJECTS_PER_REQ, ); - const assets: IotaObjectData[] = []; - - for (const page of data?.pages || []) { - for (const asset of page.data) { - if (asset.data && asset.data.objectId) { - if (selectedCategory == AssetCategory.Visual) { - if (hasDisplayData(asset)) { - assets.push(asset.data); - } - } else if (selectedCategory == AssetCategory.Other) { - assets.push(asset.data); - } + const assets = (data?.pages || []) + .flatMap((page) => page.data) + .filter((asset) => { + if (!asset.data || !asset.data.objectId) { + return false; } - } - } + if (selectedCategory === AssetCategory.Visual) { + return hasDisplayData(asset); + } + if (selectedCategory === AssetCategory.Other) { + return !hasDisplayData(asset); + } + return false; + }) + .map((asset) => asset.data) + .filter((data): data is IotaObjectData => data !== null && data !== undefined); function onAssetClick(asset: IotaObjectData) { setSelectedAsset(asset); diff --git a/apps/wallet-dashboard/components/tiles/AssetTileLink.tsx b/apps/wallet-dashboard/components/tiles/AssetTileLink.tsx index 64c4d805513..6d5d25d23b7 100644 --- a/apps/wallet-dashboard/components/tiles/AssetTileLink.tsx +++ b/apps/wallet-dashboard/components/tiles/AssetTileLink.tsx @@ -25,7 +25,7 @@ export function AssetTileLink({ asset, type, onClick }: AssetTileLinkProps): Rea {type === AssetCategory.Visual ? ( } onClick={handleClick} /> ) : ( - + )} ); diff --git a/apps/wallet-dashboard/components/tiles/NonVisualAssetTile.tsx b/apps/wallet-dashboard/components/tiles/NonVisualAssetTile.tsx index 0758714510e..c73c519bcd9 100644 --- a/apps/wallet-dashboard/components/tiles/NonVisualAssetTile.tsx +++ b/apps/wallet-dashboard/components/tiles/NonVisualAssetTile.tsx @@ -5,21 +5,25 @@ import { Card, CardAction, CardActionType, CardBody, CardType } from '@iota/apps import { IotaObjectData } from '@iota/iota-sdk/client'; import { formatAddress, parseStructTag } from '@iota/iota-sdk/utils'; import { ArrowTopRight } from '@iota/ui-icons'; +import { ExplorerLink } from '../ExplorerLink'; +import { ExplorerLinkType } from '@iota/core'; type NonVisualAssetCardProps = { asset: IotaObjectData; -} & Pick, 'onClick'>; +} & React.ComponentProps; -export function NonVisualAssetCard({ asset, onClick }: NonVisualAssetCardProps): React.JSX.Element { +export function NonVisualAssetCard({ asset }: NonVisualAssetCardProps): React.JSX.Element { const { address, module, name } = parseStructTag(asset.type!); return ( - - - } /> - + + + + } /> + + ); }