From 903d6518e35e68e3ce8141f08a1e6504d8e94a68 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Tue, 24 Dec 2024 17:20:40 +0100 Subject: [PATCH 1/4] feat: fix total native tokens count --- .../app/(protected)/migrations/page.tsx | 24 +++++++++++++-- .../groupStardustObjectsByMigrationStatus.ts | 30 ++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx index e2cd767e663..ab3bf9a68b1 100644 --- a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx @@ -6,8 +6,15 @@ import { useState, useMemo, useCallback } from 'react'; import { useQueryClient } from '@tanstack/react-query'; import clsx from 'clsx'; -import { useGetStardustMigratableObjects } from '@/hooks'; -import { summarizeMigratableObjectValues, summarizeTimelockedObjectValues } from '@/lib/utils'; +import { + useGetStardustMigratableObjects, + useGroupedMigrationObjectsByExpirationDate, +} from '@/hooks'; +import { + filterMigrationObjects, + summarizeMigratableObjectValues, + summarizeTimelockedObjectValues, +} from '@/lib/utils'; import { Button, ButtonSize, @@ -23,7 +30,7 @@ import { Assets, Clock, IotaLogoMark, Tokens } from '@iota/ui-icons'; import { useCurrentAccount, useIotaClient } from '@iota/dapp-kit'; import { STARDUST_BASIC_OUTPUT_TYPE, STARDUST_NFT_OUTPUT_TYPE, useFormatCoin } from '@iota/core'; import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; -import { StardustOutputMigrationStatus } from '@/lib/enums'; +import { StardustOutputDetailsFilter, StardustOutputMigrationStatus } from '@/lib/enums'; import { MigrationObjectsPanel, MigrationDialog } from '@/components'; import { useRouter } from 'next/navigation'; @@ -47,6 +54,16 @@ function MigrationDashboardPage(): JSX.Element { timelockedNftOutputs, } = stardustMigrationObjects || {}; + const { data: resolvedObjects = [] } = useGroupedMigrationObjectsByExpirationDate( + [...(migratableBasicOutputs || []), ...(migratableNftOutputs || [])], + selectedStardustObjectsCategory === StardustOutputMigrationStatus.Migratable, + ); + + const filteredObjectsByNativeTokenFilter = filterMigrationObjects( + resolvedObjects, + StardustOutputDetailsFilter.NativeTokens, + ); + const { totalIotaAmount, totalNativeTokens: migratableNativeTokens, @@ -55,6 +72,7 @@ function MigrationDashboardPage(): JSX.Element { basicOutputs: migratableBasicOutputs, nftOutputs: migratableNftOutputs, address, + resolvedObjects: filteredObjectsByNativeTokenFilter, }); const { totalTimelockedObjects } = summarizeTimelockedObjectValues({ basicOutputs: timelockedBasicOutputs, diff --git a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts index b10f1cf4218..7cac9da910c 100644 --- a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts +++ b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts @@ -3,6 +3,9 @@ import { CommonOutputObjectWithUc, MILLISECONDS_PER_SECOND } from '@iota/core'; import { IotaObjectData } from '@iota/iota-sdk/client'; +import { filterMigrationObjects } from './filterMigrationObjectDetails'; +import { CommonMigrationObjectType, StardustOutputDetailsFilter } from '@/lib/enums'; +import { ResolvedObjectTypes } from '@/lib/types'; export type StardustMigrationGroupedObjects = { migratable: IotaObjectData[]; @@ -58,25 +61,35 @@ interface SummarizeMigrationObjectParams { basicOutputs: IotaObjectData[] | undefined; nftOutputs: IotaObjectData[] | undefined; address: string; + resolvedObjects?: ResolvedObjectTypes[]; } export function summarizeMigratableObjectValues({ basicOutputs = [], nftOutputs = [], address, + resolvedObjects, }: SummarizeMigrationObjectParams): MigratableObjectsData { let totalNativeTokens = 0; let totalIotaAmount: bigint = 0n; let totalNotOwnedStorageDepositReturnAmount: bigint = 0n; + let filteredObjects: ResolvedObjectTypes[] = []; const totalVisualAssets = nftOutputs.length; const outputObjects = [...basicOutputs, ...nftOutputs]; + if (resolvedObjects) { + filteredObjects = filterMigrationObjects( + resolvedObjects, + StardustOutputDetailsFilter.NativeTokens, + ); + } + totalNativeTokens = calculateTotalNativeTokensByName(filteredObjects); + for (const output of outputObjects) { const outputObjectFields = extractMigrationOutputFields(output); totalIotaAmount += BigInt(outputObjectFields.balance); - totalNativeTokens += parseInt(outputObjectFields.native_tokens.fields.size); totalIotaAmount += extractOwnedStorageDepositReturnAmount(outputObjectFields, address) || 0n; totalNotOwnedStorageDepositReturnAmount += @@ -149,3 +162,18 @@ export function extractNotOwnedStorageDepositReturnAmount( } return null; } + +export function calculateTotalNativeTokensByName(objects: ResolvedObjectTypes[]): number { + const uniqueTokens: string[] = []; + + return objects.reduce((total, obj) => { + if ( + obj.commonObjectType === CommonMigrationObjectType.NativeToken && + !uniqueTokens.includes(obj.name) + ) { + uniqueTokens.push(obj.name); + return total + 1; + } + return total; + }, 0); +} From 60843a7408921304f011fa41c0fc6af97fc8c168 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Thu, 26 Dec 2024 09:24:33 +0100 Subject: [PATCH 2/4] fix: cleanup --- .../app/(protected)/migrations/page.tsx | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx index ab3bf9a68b1..6f1edf4ea04 100644 --- a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx @@ -10,11 +10,7 @@ import { useGetStardustMigratableObjects, useGroupedMigrationObjectsByExpirationDate, } from '@/hooks'; -import { - filterMigrationObjects, - summarizeMigratableObjectValues, - summarizeTimelockedObjectValues, -} from '@/lib/utils'; +import { summarizeMigratableObjectValues, summarizeTimelockedObjectValues } from '@/lib/utils'; import { Button, ButtonSize, @@ -30,7 +26,7 @@ import { Assets, Clock, IotaLogoMark, Tokens } from '@iota/ui-icons'; import { useCurrentAccount, useIotaClient } from '@iota/dapp-kit'; import { STARDUST_BASIC_OUTPUT_TYPE, STARDUST_NFT_OUTPUT_TYPE, useFormatCoin } from '@iota/core'; import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; -import { StardustOutputDetailsFilter, StardustOutputMigrationStatus } from '@/lib/enums'; +import { StardustOutputMigrationStatus } from '@/lib/enums'; import { MigrationObjectsPanel, MigrationDialog } from '@/components'; import { useRouter } from 'next/navigation'; @@ -59,11 +55,6 @@ function MigrationDashboardPage(): JSX.Element { selectedStardustObjectsCategory === StardustOutputMigrationStatus.Migratable, ); - const filteredObjectsByNativeTokenFilter = filterMigrationObjects( - resolvedObjects, - StardustOutputDetailsFilter.NativeTokens, - ); - const { totalIotaAmount, totalNativeTokens: migratableNativeTokens, @@ -72,7 +63,7 @@ function MigrationDashboardPage(): JSX.Element { basicOutputs: migratableBasicOutputs, nftOutputs: migratableNftOutputs, address, - resolvedObjects: filteredObjectsByNativeTokenFilter, + resolvedObjects, }); const { totalTimelockedObjects } = summarizeTimelockedObjectValues({ basicOutputs: timelockedBasicOutputs, From 6fa4f4bdd2e32db093e96025853bedc7bf80af83 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Fri, 27 Dec 2024 08:16:48 +0100 Subject: [PATCH 3/4] feat: add to unmigratable objects and fix funciton --- .../groupStardustObjectsByMigrationStatus.ts | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts index 7cac9da910c..215f50eab51 100644 --- a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts +++ b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts @@ -84,7 +84,7 @@ export function summarizeMigratableObjectValues({ StardustOutputDetailsFilter.NativeTokens, ); } - totalNativeTokens = calculateTotalNativeTokensByName(filteredObjects); + totalNativeTokens = getUniqueNativeTokensByCoinType(filteredObjects); for (const output of outputObjects) { const outputObjectFields = extractMigrationOutputFields(output); @@ -111,16 +111,20 @@ interface UnmmigratableObjectsData { export function summarizeTimelockedObjectValues({ basicOutputs = [], nftOutputs = [], + resolvedObjects, }: Omit): UnmmigratableObjectsData { const basicObjects = basicOutputs.length; const nftObjects = nftOutputs.length; let nativeTokens = 0; + let filteredObjects: ResolvedObjectTypes[] = []; - for (const output of [...basicOutputs, ...nftOutputs]) { - const outputObjectFields = extractMigrationOutputFields(output); - - nativeTokens += parseInt(outputObjectFields.native_tokens.fields.size); + if (resolvedObjects) { + filteredObjects = filterMigrationObjects( + resolvedObjects, + StardustOutputDetailsFilter.NativeTokens, + ); } + nativeTokens = getUniqueNativeTokensByCoinType(filteredObjects); const totalTimelockedObjects = basicObjects + nativeTokens + nftObjects; @@ -163,17 +167,10 @@ export function extractNotOwnedStorageDepositReturnAmount( return null; } -export function calculateTotalNativeTokensByName(objects: ResolvedObjectTypes[]): number { - const uniqueTokens: string[] = []; - - return objects.reduce((total, obj) => { - if ( - obj.commonObjectType === CommonMigrationObjectType.NativeToken && - !uniqueTokens.includes(obj.name) - ) { - uniqueTokens.push(obj.name); - return total + 1; - } - return total; - }, 0); -} +export function getUniqueNativeTokensByCoinType(objects: ResolvedObjectTypes[]): number { + return new Set( + objects + .filter((obj) => obj.commonObjectType === CommonMigrationObjectType.NativeToken) + .map((obj) => obj.coinType), + ).size; +} \ No newline at end of file From 7f7e1cc06065d8cb6a7357068d6a19ffe224c12f Mon Sep 17 00:00:00 2001 From: evavirseda Date: Fri, 27 Dec 2024 08:17:46 +0100 Subject: [PATCH 4/4] fix format --- .../utils/migration/groupStardustObjectsByMigrationStatus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts index 215f50eab51..169409b7c31 100644 --- a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts +++ b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts @@ -173,4 +173,4 @@ export function getUniqueNativeTokensByCoinType(objects: ResolvedObjectTypes[]): .filter((obj) => obj.commonObjectType === CommonMigrationObjectType.NativeToken) .map((obj) => obj.coinType), ).size; -} \ No newline at end of file +}