Skip to content

Commit

Permalink
fix(wallet-dashboard): other assets (#4574)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: marc2332 <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 1661d22 commit 92ddb6b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions apps/core/src/constants/coins.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
35 changes: 19 additions & 16 deletions apps/wallet-dashboard/app/(protected)/assets/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-dashboard/components/tiles/AssetTileLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function AssetTileLink({ asset, type, onClick }: AssetTileLinkProps): Rea
{type === AssetCategory.Visual ? (
<VisualAssetTile asset={asset} icon={<VisibilityOff />} onClick={handleClick} />
) : (
<NonVisualAssetCard asset={asset} onClick={handleClick} />
<NonVisualAssetCard asset={asset} />
)}
</>
);
Expand Down
24 changes: 14 additions & 10 deletions apps/wallet-dashboard/components/tiles/NonVisualAssetTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.ComponentProps<typeof Card>, 'onClick'>;
} & React.ComponentProps<typeof Card>;

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 (
<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>
<ExplorerLink objectID={asset.objectId} type={ExplorerLinkType.Object}>
<Card type={CardType.Default} isHoverable>
<CardBody
title={formatAddress(asset.objectId!)}
subtitle={`${formatAddress(address)}::${module}::${name}`}
isTextTruncated
/>
<CardAction type={CardActionType.Link} icon={<ArrowTopRight />} />
</Card>
</ExplorerLink>
);
}

0 comments on commit 92ddb6b

Please sign in to comment.