From f62f4012cff586a792ff21913714d5eb758612dc Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 19 Dec 2024 17:08:08 +0100 Subject: [PATCH 1/9] fix(wallet-dashboard): other assets --- .../app/(protected)/assets/page.tsx | 19 ++++++++------- .../components/tiles/AssetTileLink.tsx | 2 +- .../components/tiles/NonVisualAssetTile.tsx | 24 +++++++++++-------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/assets/page.tsx b/apps/wallet-dashboard/app/(protected)/assets/page.tsx index 7007cc86c5c..87c9df64d1a 100644 --- a/apps/wallet-dashboard/app/(protected)/assets/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/assets/page.tsx @@ -31,21 +31,22 @@ export default function AssetsDashboardPage(): React.JSX.Element { const account = useCurrentAccount(); const { data, isFetching, fetchNextPage, hasNextPage, refetch } = useGetOwnedObjects( account?.address, - undefined, + { + MatchNone: [{ StructType: '0x2::coin::Coin' }], + }, OBJECTS_PER_REQ, ); - const assets: IotaObjectData[] = []; + const visualAssets: IotaObjectData[] = []; + const otherAssets: 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); + if (hasDisplayData(asset)) { + visualAssets.push(asset.data); + } else { + otherAssets.push(asset.data); } } } @@ -71,7 +72,7 @@ export default function AssetsDashboardPage(): React.JSX.Element { } 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 ( - - - } /> - + + + + } /> + + ); } From 9b816ecfe877b9cc2df6e032581aec2b9ca7d474 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Fri, 20 Dec 2024 08:39:37 +0100 Subject: [PATCH 2/9] fix(dashboard): simplified code --- apps/wallet-dashboard/app/(protected)/assets/page.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/assets/page.tsx b/apps/wallet-dashboard/app/(protected)/assets/page.tsx index 87c9df64d1a..0786fbc509d 100644 --- a/apps/wallet-dashboard/app/(protected)/assets/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/assets/page.tsx @@ -37,16 +37,17 @@ export default function AssetsDashboardPage(): React.JSX.Element { OBJECTS_PER_REQ, ); - const visualAssets: IotaObjectData[] = []; - const otherAssets: IotaObjectData[] = []; + const assets = new Map( + ASSET_CATEGORIES.map((tab) => [tab.value, []]), + ); for (const page of data?.pages || []) { for (const asset of page.data) { if (asset.data && asset.data.objectId) { if (hasDisplayData(asset)) { - visualAssets.push(asset.data); + assets.get(AssetCategory.Visual)?.push(asset.data); } else { - otherAssets.push(asset.data); + assets.get(AssetCategory.Other)?.push(asset.data); } } } @@ -72,7 +73,7 @@ export default function AssetsDashboardPage(): React.JSX.Element { Date: Fri, 20 Dec 2024 09:54:47 +0100 Subject: [PATCH 3/9] feat(core): add a new COIN_TYPE constant --- apps/core/src/constants/coins.constants.ts | 1 + apps/core/src/constants/timelock.constants.ts | 4 +++- apps/explorer/tests/utils/localnet.ts | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/core/src/constants/coins.constants.ts b/apps/core/src/constants/coins.constants.ts index 11fba0c12a0..d9004d71a0f 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'; \ No newline at end of file diff --git a/apps/core/src/constants/timelock.constants.ts b/apps/core/src/constants/timelock.constants.ts index 6b9ab9c2627..d91b44d93f0 100644 --- a/apps/core/src/constants/timelock.constants.ts +++ b/apps/core/src/constants/timelock.constants.ts @@ -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'; diff --git a/apps/explorer/tests/utils/localnet.ts b/apps/explorer/tests/utils/localnet.ts index a03f865afa3..422965ba7e7 100644 --- a/apps/explorer/tests/utils/localnet.ts +++ b/apps/explorer/tests/utils/localnet.ts @@ -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(); @@ -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)], }); From 71d93ceb49674cfd55c710f3bdf3f04510785209 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Fri, 20 Dec 2024 09:55:12 +0100 Subject: [PATCH 4/9] fix(dashboard): revert changes of assets array and use new COIN_TYPE constant --- .../app/(protected)/assets/page.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/assets/page.tsx b/apps/wallet-dashboard/app/(protected)/assets/page.tsx index 0786fbc509d..c75401c9d74 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'; @@ -32,22 +32,24 @@ export default function AssetsDashboardPage(): React.JSX.Element { const { data, isFetching, fetchNextPage, hasNextPage, refetch } = useGetOwnedObjects( account?.address, { - MatchNone: [{ StructType: '0x2::coin::Coin' }], + MatchNone: [{ StructType: COIN_TYPE }], }, OBJECTS_PER_REQ, ); - const assets = new Map( - ASSET_CATEGORIES.map((tab) => [tab.value, []]), - ); + const assets: IotaObjectData[] = []; for (const page of data?.pages || []) { for (const asset of page.data) { if (asset.data && asset.data.objectId) { - if (hasDisplayData(asset)) { - assets.get(AssetCategory.Visual)?.push(asset.data); - } else { - assets.get(AssetCategory.Other)?.push(asset.data); + if (selectedCategory == AssetCategory.Visual) { + if (hasDisplayData(asset)) { + assets.push(asset.data); + } + } else if (selectedCategory == AssetCategory.Other) { + if (!hasDisplayData(asset)) { + assets.push(asset.data); + } } } } @@ -73,7 +75,7 @@ export default function AssetsDashboardPage(): React.JSX.Element { Date: Fri, 20 Dec 2024 10:10:19 +0100 Subject: [PATCH 5/9] fix(dashboard): improve the assets filter --- .../app/(protected)/assets/page.tsx | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/assets/page.tsx b/apps/wallet-dashboard/app/(protected)/assets/page.tsx index c75401c9d74..9af8669a717 100644 --- a/apps/wallet-dashboard/app/(protected)/assets/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/assets/page.tsx @@ -37,23 +37,22 @@ export default function AssetsDashboardPage(): React.JSX.Element { 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) { - if (!hasDisplayData(asset)) { - 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); From 3dfce3318a8ef705d6d54270ce5a753a553a3d85 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Fri, 20 Dec 2024 10:17:51 +0100 Subject: [PATCH 6/9] fix(core): linter --- apps/core/src/constants/coins.constants.ts | 2 +- apps/core/src/constants/timelock.constants.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/core/src/constants/coins.constants.ts b/apps/core/src/constants/coins.constants.ts index d9004d71a0f..b0e38e586cd 100644 --- a/apps/core/src/constants/coins.constants.ts +++ b/apps/core/src/constants/coins.constants.ts @@ -3,4 +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'; \ No newline at end of file +export const COIN_TYPE = '0x2::coin::Coin'; diff --git a/apps/core/src/constants/timelock.constants.ts b/apps/core/src/constants/timelock.constants.ts index d91b44d93f0..7d3803f14f5 100644 --- a/apps/core/src/constants/timelock.constants.ts +++ b/apps/core/src/constants/timelock.constants.ts @@ -1,7 +1,7 @@ // Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { COIN_TYPE } from "./coins.constants"; +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'; From dfba076136dca02f025528ae1e7f732892618931 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 20 Dec 2024 16:12:56 +0100 Subject: [PATCH 7/9] fix(explorer): Revert localnet.ts --- apps/explorer/tests/utils/localnet.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/explorer/tests/utils/localnet.ts b/apps/explorer/tests/utils/localnet.ts index 422965ba7e7..a03f865afa3 100644 --- a/apps/explorer/tests/utils/localnet.ts +++ b/apps/explorer/tests/utils/localnet.ts @@ -8,7 +8,6 @@ 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(); @@ -25,7 +24,7 @@ export async function split_coin(address: string) { const tx = new Transaction(); tx.moveCall({ target: '0x2::pay::split', - typeArguments: [COIN_TYPE], + typeArguments: ['0x2::iota::IOTA'], arguments: [tx.object(coin_id), tx.pure.u64(10)], }); From dc3ea7f5e9c18096db3a7aabb3cc9dbc603e3e22 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 20 Dec 2024 16:25:57 +0100 Subject: [PATCH 8/9] fix(core): Revert timelock.constants.ts --- apps/core/src/constants/timelock.constants.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/core/src/constants/timelock.constants.ts b/apps/core/src/constants/timelock.constants.ts index 7d3803f14f5..ee2d9b6e48b 100644 --- a/apps/core/src/constants/timelock.constants.ts +++ b/apps/core/src/constants/timelock.constants.ts @@ -1,7 +1,5 @@ // Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { COIN_TYPE } from './coins.constants'; - -export const TIMELOCK_IOTA_TYPE = `0x2::timelock::TimeLock<0x2::balance::Balance<${COIN_TYPE}>>`; +export const TIMELOCK_IOTA_TYPE = `0x2::timelock::TimeLock<0x2::balance::Balance<0x2::iota::IOTA>>`; export const TIMELOCK_STAKED_TYPE = '0x3::timelocked_staking::TimelockedStakedIota'; From 060870ca5b3a11561349b6f8613bef773a9089f7 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 20 Dec 2024 16:34:23 +0100 Subject: [PATCH 9/9] ' --- apps/core/src/constants/timelock.constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/core/src/constants/timelock.constants.ts b/apps/core/src/constants/timelock.constants.ts index ee2d9b6e48b..6b9ab9c2627 100644 --- a/apps/core/src/constants/timelock.constants.ts +++ b/apps/core/src/constants/timelock.constants.ts @@ -1,5 +1,5 @@ // 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>>`; +export const TIMELOCK_IOTA_TYPE = '0x2::timelock::TimeLock<0x2::balance::Balance<0x2::iota::IOTA>>'; export const TIMELOCK_STAKED_TYPE = '0x3::timelocked_staking::TimelockedStakedIota';