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

fix(wallet-dashboard): other assets #4574

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
4 changes: 3 additions & 1 deletion apps/core/src/constants/timelock.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export const TIMELOCK_IOTA_TYPE = '0x2::timelock::TimeLock<0x2::balance::Balance<0x2::iota::IOTA>>';
import { COIN_TYPE } from './coins.constants';

export const TIMELOCK_IOTA_TYPE = `0x2::timelock::TimeLock<0x2::balance::Balance<${COIN_TYPE}>>`;
export const TIMELOCK_STAKED_TYPE = '0x3::timelocked_staking::TimelockedStakedIota';
3 changes: 2 additions & 1 deletion apps/explorer/tests/utils/localnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IotaClient, getFullnodeUrl } from '@iota/iota-sdk/client';
import { type Keypair } from '@iota/iota-sdk/cryptography';
import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519';
import { Transaction } from '@iota/iota-sdk/transactions';
import { COIN_TYPE } from '@iota/core';

const addressToKeypair = new Map<string, Keypair>();

Expand All @@ -24,7 +25,7 @@ export async function split_coin(address: string) {
const tx = new Transaction();
tx.moveCall({
target: '0x2::pay::split',
typeArguments: ['0x2::iota::IOTA'],
typeArguments: [COIN_TYPE],
arguments: [tx.object(coin_id), tx.pure.u64(10)],
});

Expand Down
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>
);
}
Loading