From 903d6518e35e68e3ce8141f08a1e6504d8e94a68 Mon Sep 17 00:00:00 2001 From: evavirseda Date: Tue, 24 Dec 2024 17:20:40 +0100 Subject: [PATCH 1/7] 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/7] 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/7] 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/7] 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 +} From 11b1d4262eb2fde05e9cdce2acbef090bdc4032d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bego=C3=B1a=20Alvarez?= Date: Wed, 8 Jan 2025 16:13:18 +0100 Subject: [PATCH 5/7] refactor: timelocked portfolio totals --- .../app/(protected)/migrations/page.tsx | 62 +++++++++++++------ .../migration/views/ConfirmMigrationView.tsx | 11 ++-- .../migration/MigrationObjectsPanel.tsx | 4 +- apps/wallet-dashboard/hooks/index.ts | 2 +- ...onDate.ts => useGroupedStardustObjects.ts} | 8 +-- .../utils/migration/groupMigrationObjects.ts | 12 ++-- .../groupStardustObjectsByMigrationStatus.ts | 43 +++---------- 7 files changed, 68 insertions(+), 74 deletions(-) rename apps/wallet-dashboard/hooks/{useGroupedMigrationObjectsByExpirationDate.ts => useGroupedStardustObjects.ts} (91%) diff --git a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx index 6f1edf4ea04..d80f9d96fd4 100644 --- a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx @@ -6,11 +6,8 @@ import { useState, useMemo, useCallback } from 'react'; import { useQueryClient } from '@tanstack/react-query'; import clsx from 'clsx'; -import { - useGetStardustMigratableObjects, - useGroupedMigrationObjectsByExpirationDate, -} from '@/hooks'; -import { summarizeMigratableObjectValues, summarizeTimelockedObjectValues } from '@/lib/utils'; +import { useGetStardustMigratableObjects, useGroupedStardustObjects } from '@/hooks'; +import { getStardustObjectsTotals } from '@/lib/utils'; import { Button, ButtonSize, @@ -22,7 +19,7 @@ import { Panel, Title, } from '@iota/apps-ui-kit'; -import { Assets, Clock, IotaLogoMark, Tokens } from '@iota/ui-icons'; +import { Assets, 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'; @@ -50,30 +47,49 @@ function MigrationDashboardPage(): JSX.Element { timelockedNftOutputs, } = stardustMigrationObjects || {}; - const { data: resolvedObjects = [] } = useGroupedMigrationObjectsByExpirationDate( + const { data: resolvedMigrationObjects = [] } = useGroupedStardustObjects( [...(migratableBasicOutputs || []), ...(migratableNftOutputs || [])], - selectedStardustObjectsCategory === StardustOutputMigrationStatus.Migratable, + false, + ); + const { data: resolvedTimelockedObjects = [] } = useGroupedStardustObjects( + [...(timelockedBasicOutputs || []), ...(timelockedNftOutputs || [])], + true, ); const { - totalIotaAmount, + totalIotaAmount: migratableIotaAmount, totalNativeTokens: migratableNativeTokens, totalVisualAssets: migratableVisualAssets, - } = summarizeMigratableObjectValues({ + } = getStardustObjectsTotals({ basicOutputs: migratableBasicOutputs, nftOutputs: migratableNftOutputs, address, - resolvedObjects, + resolvedObjects: resolvedMigrationObjects, }); - const { totalTimelockedObjects } = summarizeTimelockedObjectValues({ + const { + totalIotaAmount: timelockedIotaAmount, + totalNativeTokens: timelockedNativeTokens, + totalVisualAssets: timelockedVisualAssets, + } = getStardustObjectsTotals({ basicOutputs: timelockedBasicOutputs, nftOutputs: timelockedNftOutputs, + address, + resolvedObjects: resolvedTimelockedObjects, }); const hasMigratableObjects = (migratableBasicOutputs?.length || 0) > 0 && (migratableNftOutputs?.length || 0) > 0; + const hasTimelockedObjects = + (timelockedBasicOutputs?.length || 0) > 0 && (timelockedNftOutputs?.length || 0) > 0; - const [timelockedIotaTokens, symbol] = useFormatCoin(totalIotaAmount, IOTA_TYPE_ARG); + const [migratableIotaAmountFormatted, migratableIotaAmountSymbol] = useFormatCoin( + migratableIotaAmount, + IOTA_TYPE_ARG, + ); + const [timelockedIotaAmountFormatted, timelockedIotaAmountSymbol] = useFormatCoin( + timelockedIotaAmount, + IOTA_TYPE_ARG, + ); const handleOnSuccess = useCallback( (digest: string) => { @@ -99,7 +115,7 @@ function MigrationDashboardPage(): JSX.Element { const MIGRATION_CARDS: MigrationDisplayCardProps[] = [ { - title: `${timelockedIotaTokens} ${symbol}`, + title: `${migratableIotaAmountFormatted} ${migratableIotaAmountSymbol}`, subtitle: 'IOTA Tokens', icon: IotaLogoMark, }, @@ -117,9 +133,19 @@ function MigrationDashboardPage(): JSX.Element { const TIMELOCKED_ASSETS_CARDS: MigrationDisplayCardProps[] = [ { - title: `${totalTimelockedObjects}`, - subtitle: 'Time-locked', - icon: Clock, + title: `${timelockedIotaAmountFormatted} ${timelockedIotaAmountSymbol}`, + subtitle: 'IOTA Tokens', + icon: IotaLogoMark, + }, + { + title: `${timelockedNativeTokens}`, + subtitle: 'Native Tokens', + icon: Tokens, + }, + { + title: `${timelockedVisualAssets}`, + subtitle: 'Visual Assets', + icon: Assets, }, ]; @@ -233,7 +259,7 @@ function MigrationDashboardPage(): JSX.Element { disabled={ selectedStardustObjectsCategory === StardustOutputMigrationStatus.TimeLocked || - !totalTimelockedObjects + !hasTimelockedObjects } onClick={() => setSelectedStardustObjectsCategory( diff --git a/apps/wallet-dashboard/components/Dialogs/migration/views/ConfirmMigrationView.tsx b/apps/wallet-dashboard/components/Dialogs/migration/views/ConfirmMigrationView.tsx index 7066a922187..465069879dd 100644 --- a/apps/wallet-dashboard/components/Dialogs/migration/views/ConfirmMigrationView.tsx +++ b/apps/wallet-dashboard/components/Dialogs/migration/views/ConfirmMigrationView.tsx @@ -17,11 +17,11 @@ import { Title, TitleSize, } from '@iota/apps-ui-kit'; -import { useGroupedMigrationObjectsByExpirationDate } from '@/hooks'; +import { useGroupedStardustObjects } from '@/hooks'; import { Loader, Warning } from '@iota/ui-icons'; import { Collapsible, useFormatCoin } from '@iota/core'; import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; -import { summarizeMigratableObjectValues } from '@/lib/utils'; +import { getStardustObjectsTotals } from '@/lib/utils'; import { MigrationObjectDetailsCard } from '@/components/migration/migration-object-details-card'; import { DialogLayout, DialogLayoutBody, DialogLayoutFooter } from '../../layout'; import { Transaction } from '@iota/iota-sdk/transactions'; @@ -60,12 +60,9 @@ export function ConfirmMigrationView({ data: resolvedObjects = [], isLoading, error: isGroupedMigrationError, - } = useGroupedMigrationObjectsByExpirationDate( - [...basicOutputObjects, ...nftOutputObjects], - isTimelocked, - ); + } = useGroupedStardustObjects([...basicOutputObjects, ...nftOutputObjects], isTimelocked); - const { totalNotOwnedStorageDepositReturnAmount } = summarizeMigratableObjectValues({ + const { totalNotOwnedStorageDepositReturnAmount } = getStardustObjectsTotals({ basicOutputs: basicOutputObjects, nftOutputs: nftOutputObjects, address: account?.address || '', diff --git a/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx b/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx index 348ccd6b02b..567335ddb0b 100644 --- a/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx +++ b/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx @@ -3,7 +3,7 @@ 'use client'; -import { useGroupedMigrationObjectsByExpirationDate } from '@/hooks'; +import { useGroupedStardustObjects } from '@/hooks'; import { STARDUST_MIGRATABLE_OBJECTS_FILTER_LIST, STARDUST_TIMELOCKED_OBJECTS_FILTER_LIST, @@ -51,7 +51,7 @@ export function MigrationObjectsPanel({ data: resolvedObjects = [], isLoading, error: isErrored, - } = useGroupedMigrationObjectsByExpirationDate(selectedObjects, isTimelocked); + } = useGroupedStardustObjects(selectedObjects, isTimelocked); const filteredObjects = filterMigrationObjects(resolvedObjects, stardustOutputDetailsFilter); diff --git a/apps/wallet-dashboard/hooks/index.ts b/apps/wallet-dashboard/hooks/index.ts index e5ebbf33490..c54d887f0f2 100644 --- a/apps/wallet-dashboard/hooks/index.ts +++ b/apps/wallet-dashboard/hooks/index.ts @@ -10,6 +10,6 @@ export * from './useTimelockedUnstakeTransaction'; export * from './useExplorerLinkGetter'; export * from './useGetStardustMigratableObjects'; export * from './useGetSupplyIncreaseVestingObjects'; -export * from './useGroupedMigrationObjectsByExpirationDate'; +export * from './useGroupedStardustObjects'; export * from './useTransferTransaction'; export * from './usePersistedNetwork'; diff --git a/apps/wallet-dashboard/hooks/useGroupedMigrationObjectsByExpirationDate.ts b/apps/wallet-dashboard/hooks/useGroupedStardustObjects.ts similarity index 91% rename from apps/wallet-dashboard/hooks/useGroupedMigrationObjectsByExpirationDate.ts rename to apps/wallet-dashboard/hooks/useGroupedStardustObjects.ts index d9d96816fd2..6c54e672ba0 100644 --- a/apps/wallet-dashboard/hooks/useGroupedMigrationObjectsByExpirationDate.ts +++ b/apps/wallet-dashboard/hooks/useGroupedStardustObjects.ts @@ -13,9 +13,9 @@ import { useQuery } from '@tanstack/react-query'; import { useGetCurrentEpochStartTimestamp } from './useGetCurrentEpochStartTimestamp'; import { useGetCurrentEpochEndTimestamp } from './useGetCurrentEpochEndTimestamp'; -export function useGroupedMigrationObjectsByExpirationDate( +export function useGroupedStardustObjects( objects: IotaObjectData[], - isTimelockUnlockCondition: boolean = false, + groupByTimelockUC: boolean = false, ) { const client = useIotaClient(); const address = useCurrentAccount()?.address; @@ -32,7 +32,7 @@ export function useGroupedMigrationObjectsByExpirationDate( 'grouped-migration-objects', objects, address, - isTimelockUnlockCondition, + groupByTimelockUC, epochStartMs, epochEndMs, ], @@ -44,7 +44,7 @@ export function useGroupedMigrationObjectsByExpirationDate( objects, client, address, - isTimelockUnlockCondition, + groupByTimelockUC, ); return sortStardustResolvedObjectsByExpiration( diff --git a/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts b/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts index 73991f4ac09..3c50fb509cc 100644 --- a/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts +++ b/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts @@ -16,7 +16,7 @@ import { STARDUST_BASIC_OUTPUT_TYPE, STARDUST_NFT_OUTPUT_TYPE, } from '@iota/core'; -import { extractMigrationOutputFields, extractOwnedStorageDepositReturnAmount } from '.'; +import { extractOutputFields, extractOwnedStorageDepositReturnAmount } from '.'; import { IotaClient, IotaObjectData } from '@iota/iota-sdk/client'; import { MIGRATION_OBJECT_WITHOUT_UC_KEY } from '@/lib/constants'; @@ -24,7 +24,7 @@ export async function groupMigrationObjectsByUnlockCondition( objectsData: IotaObjectData[], client: IotaClient, currentAddress: string = '', - isTimelockUnlockCondition: boolean = false, + groupByTimelockUC: boolean = false, // If true, group by timelock unlock condition, else group by expiration unlock condition ): Promise { const flatObjects: ResolvedObjectTypes[] = []; const basicObjectMap: Map = new Map(); @@ -37,10 +37,10 @@ export async function groupMigrationObjectsByUnlockCondition( const chunk = objectsData.slice(i, i + PROMISE_CHUNK_SIZE); const promises = chunk.map(async (object) => { - const objectFields = extractMigrationOutputFields(object); + const objectFields = extractOutputFields(object); let groupKey: string | undefined; - if (isTimelockUnlockCondition) { + if (groupByTimelockUC) { const timestamp = objectFields.timelock_uc?.fields.unix_time.toString(); groupKey = timestamp; } else { @@ -160,7 +160,7 @@ async function getNftDetails( expirationKey: UnlockConditionTimestamp, client: IotaClient, ): Promise { - const objectFields = extractMigrationOutputFields(object); + const objectFields = extractOutputFields(object); const nftOutputDynamicFields = await client.getDynamicFields({ parentId: objectFields.id.id, }); @@ -195,7 +195,7 @@ async function extractNativeTokensFromObject( client: IotaClient, expirationKey: UnlockConditionTimestamp, ): Promise { - const fields = extractMigrationOutputFields(object); + const fields = extractOutputFields(object); const bagId = fields.native_tokens.fields.id.id; const bagSize = Number(fields.native_tokens.fields.size); diff --git a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts index 169409b7c31..5c0a20a824c 100644 --- a/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts +++ b/apps/wallet-dashboard/lib/utils/migration/groupStardustObjectsByMigrationStatus.ts @@ -23,7 +23,7 @@ export function groupStardustObjectsByMigrationStatus( const epochUnix = epochTimestampMs / MILLISECONDS_PER_SECOND; for (const outputObject of stardustOutputObjects) { - const outputObjectFields = extractMigrationOutputFields(outputObject); + const outputObjectFields = extractOutputFields(outputObject); if ( outputObjectFields.timelock_uc && @@ -50,26 +50,26 @@ export function groupStardustObjectsByMigrationStatus( return { migratable, timelocked }; } -interface MigratableObjectsData { +interface StardustObjectsTotals { totalNativeTokens: number; totalVisualAssets: number; totalIotaAmount: bigint; totalNotOwnedStorageDepositReturnAmount: bigint; } -interface SummarizeMigrationObjectParams { +interface StardustObjectsTotalsParams { basicOutputs: IotaObjectData[] | undefined; nftOutputs: IotaObjectData[] | undefined; address: string; resolvedObjects?: ResolvedObjectTypes[]; } -export function summarizeMigratableObjectValues({ +export function getStardustObjectsTotals({ basicOutputs = [], nftOutputs = [], address, resolvedObjects, -}: SummarizeMigrationObjectParams): MigratableObjectsData { +}: StardustObjectsTotalsParams): StardustObjectsTotals { let totalNativeTokens = 0; let totalIotaAmount: bigint = 0n; let totalNotOwnedStorageDepositReturnAmount: bigint = 0n; @@ -87,7 +87,7 @@ export function summarizeMigratableObjectValues({ totalNativeTokens = getUniqueNativeTokensByCoinType(filteredObjects); for (const output of outputObjects) { - const outputObjectFields = extractMigrationOutputFields(output); + const outputObjectFields = extractOutputFields(output); totalIotaAmount += BigInt(outputObjectFields.balance); totalIotaAmount += @@ -104,33 +104,6 @@ export function summarizeMigratableObjectValues({ }; } -interface UnmmigratableObjectsData { - totalTimelockedObjects: number; -} - -export function summarizeTimelockedObjectValues({ - basicOutputs = [], - nftOutputs = [], - resolvedObjects, -}: Omit): UnmmigratableObjectsData { - const basicObjects = basicOutputs.length; - const nftObjects = nftOutputs.length; - let nativeTokens = 0; - let filteredObjects: ResolvedObjectTypes[] = []; - - if (resolvedObjects) { - filteredObjects = filterMigrationObjects( - resolvedObjects, - StardustOutputDetailsFilter.NativeTokens, - ); - } - nativeTokens = getUniqueNativeTokensByCoinType(filteredObjects); - - const totalTimelockedObjects = basicObjects + nativeTokens + nftObjects; - - return { totalTimelockedObjects }; -} - export function extractOwnedStorageDepositReturnAmount( { storage_deposit_return_uc }: CommonOutputObjectWithUc, address: string, @@ -144,9 +117,7 @@ export function extractOwnedStorageDepositReturnAmount( return null; } -export function extractMigrationOutputFields( - outputObject: IotaObjectData, -): CommonOutputObjectWithUc { +export function extractOutputFields(outputObject: IotaObjectData): CommonOutputObjectWithUc { return ( outputObject.content as unknown as { fields: CommonOutputObjectWithUc; From 0cfdf623579772c83198a68dc027646183331b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bego=C3=B1a=20Alvarez?= Date: Thu, 9 Jan 2025 10:27:29 +0100 Subject: [PATCH 6/7] refactor: rename isTimelocked by groupByTimelockUC --- .../app/(protected)/migrations/page.tsx | 2 +- .../components/dialogs/migration/MigrationDialog.tsx | 2 +- .../dialogs/migration/views/ConfirmMigrationView.tsx | 8 ++++---- .../components/migration/MigrationObjectsPanel.tsx | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx index d80f9d96fd4..ffb642ea3f2 100644 --- a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx @@ -274,7 +274,7 @@ function MigrationDashboardPage(): JSX.Element { diff --git a/apps/wallet-dashboard/components/dialogs/migration/MigrationDialog.tsx b/apps/wallet-dashboard/components/dialogs/migration/MigrationDialog.tsx index 5e21d9896dd..e3e9cd19541 100644 --- a/apps/wallet-dashboard/components/dialogs/migration/MigrationDialog.tsx +++ b/apps/wallet-dashboard/components/dialogs/migration/MigrationDialog.tsx @@ -73,7 +73,7 @@ export function MigrationDialog({ nftOutputObjects={nftOutputObjects} onSuccess={handleMigrate} setOpen={setOpen} - isTimelocked={isTimelocked} + groupByTimelockUC={isTimelocked} migrateData={migrateData} isMigrationPending={isMigrationPending} isMigrationError={isMigrationError} diff --git a/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx b/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx index 6b8ee5d1d50..806f9d3a0b4 100644 --- a/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx +++ b/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx @@ -31,7 +31,7 @@ interface ConfirmMigrationViewProps { nftOutputObjects: IotaObjectData[] | undefined; onSuccess: () => void; setOpen: (bool: boolean) => void; - isTimelocked: boolean; + groupByTimelockUC: boolean; migrateData: | { transaction: Transaction; @@ -48,7 +48,7 @@ export function ConfirmMigrationView({ nftOutputObjects = [], onSuccess, setOpen, - isTimelocked, + groupByTimelockUC, migrateData, isMigrationPending, isMigrationError, @@ -60,7 +60,7 @@ export function ConfirmMigrationView({ data: resolvedObjects = [], isLoading, error: isGroupedMigrationError, - } = useGroupedStardustObjects([...basicOutputObjects, ...nftOutputObjects], isTimelocked); + } = useGroupedStardustObjects([...basicOutputObjects, ...nftOutputObjects], groupByTimelockUC); const { totalIotaAmount, @@ -164,7 +164,7 @@ export function ConfirmMigrationView({ render={(migrationObject) => ( )} /> diff --git a/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx b/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx index 567335ddb0b..4e6df6ad374 100644 --- a/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx +++ b/apps/wallet-dashboard/components/migration/MigrationObjectsPanel.tsx @@ -36,13 +36,13 @@ const FILTERS = { interface MigrationObjectsPanelProps { selectedObjects: IotaObjectData[]; onClose: () => void; - isTimelocked: boolean; + groupByTimelockUC: boolean; } export function MigrationObjectsPanel({ selectedObjects, onClose, - isTimelocked, + groupByTimelockUC, }: MigrationObjectsPanelProps): React.JSX.Element { const [stardustOutputDetailsFilter, setStardustOutputDetailsFilter] = useState(StardustOutputDetailsFilter.All); @@ -51,11 +51,11 @@ export function MigrationObjectsPanel({ data: resolvedObjects = [], isLoading, error: isErrored, - } = useGroupedStardustObjects(selectedObjects, isTimelocked); + } = useGroupedStardustObjects(selectedObjects, groupByTimelockUC); const filteredObjects = filterMigrationObjects(resolvedObjects, stardustOutputDetailsFilter); - const filters = isTimelocked ? FILTERS.timelocked : FILTERS.migratable; + const filters = groupByTimelockUC ? FILTERS.timelocked : FILTERS.migratable; const isHidden = selectedObjects.length === 0; return ( @@ -101,7 +101,7 @@ export function MigrationObjectsPanel({ render={(migrationObject) => ( )} /> From 1f39da9f791d25ed87916140c7078efb582d900d Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 9 Jan 2025 10:47:10 +0100 Subject: [PATCH 7/7] fix: clean import --- .../dialogs/migration/views/ConfirmMigrationView.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx b/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx index 806f9d3a0b4..bd9071e3a6c 100644 --- a/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx +++ b/apps/wallet-dashboard/components/dialogs/migration/views/ConfirmMigrationView.tsx @@ -20,8 +20,7 @@ import { useGroupedStardustObjects } from '@/hooks'; import { Loader, Warning } from '@iota/ui-icons'; import { Collapsible, useFormatCoin } from '@iota/core'; import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; -import { getStardustObjectsTotals } from '@/lib/utils'; -import { filterMigrationObjects } from '@/lib/utils'; +import { getStardustObjectsTotals, filterMigrationObjects } from '@/lib/utils'; import { DialogLayout, DialogLayoutBody, DialogLayoutFooter } from '../../layout'; import { Transaction } from '@iota/iota-sdk/transactions'; import { StardustOutputDetailsFilter } from '@/lib/enums';