From e5625e660800d086b8e96ef591b6e4a9784f1ec0 Mon Sep 17 00:00:00 2001 From: JCNoguera <88061365+VmMad@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:08:59 +0100 Subject: [PATCH] feat(dashboard): extract basic objects from all outputs (#4730) --- .../app/(protected)/migrations/page.tsx | 4 +- .../utils/migration/groupMigrationObjects.ts | 47 +++++++++---------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx index ffb642ea3f2..868877f00a5 100644 --- a/apps/wallet-dashboard/app/(protected)/migrations/page.tsx +++ b/apps/wallet-dashboard/app/(protected)/migrations/page.tsx @@ -78,9 +78,9 @@ function MigrationDashboardPage(): JSX.Element { }); const hasMigratableObjects = - (migratableBasicOutputs?.length || 0) > 0 && (migratableNftOutputs?.length || 0) > 0; + (migratableBasicOutputs?.length || 0) > 0 || (migratableNftOutputs?.length || 0) > 0; const hasTimelockedObjects = - (timelockedBasicOutputs?.length || 0) > 0 && (timelockedNftOutputs?.length || 0) > 0; + (timelockedBasicOutputs?.length || 0) > 0 || (timelockedNftOutputs?.length || 0) > 0; const [migratableIotaAmountFormatted, migratableIotaAmountSymbol] = useFormatCoin( migratableIotaAmount, diff --git a/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts b/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts index 3c50fb509cc..bc7523039c6 100644 --- a/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts +++ b/apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts @@ -54,32 +54,29 @@ export async function groupMigrationObjectsByUnlockCondition( return; } - if (object.type === STARDUST_BASIC_OUTPUT_TYPE) { - const existing = basicObjectMap.get(groupKey); - const gasReturn = extractOwnedStorageDepositReturnAmount( - objectFields, - currentAddress, - ); - const newBalance = - (existing ? existing.balance : 0n) + - BigInt(objectFields.balance) + - (gasReturn ?? 0n); + const existingBasicObject = basicObjectMap.get(groupKey); + const gasReturn = extractOwnedStorageDepositReturnAmount(objectFields, currentAddress); + const newBalance = + (existingBasicObject ? existingBasicObject.balance : 0n) + + BigInt(objectFields.balance) + + (gasReturn ?? 0n); + + if (existingBasicObject) { + existingBasicObject.balance = newBalance; + } else { + const newBasicObject: ResolvedBasicObject = { + balance: newBalance, + unlockConditionTimestamp: groupKey, + type: STARDUST_BASIC_OUTPUT_TYPE, + commonObjectType: CommonMigrationObjectType.Basic, + output: object, + uniqueId: objectFields.id.id, + }; + basicObjectMap.set(groupKey, newBasicObject); + flatObjects.push(newBasicObject); + } - if (existing) { - existing.balance = newBalance; - } else { - const newBasicObject: ResolvedBasicObject = { - balance: newBalance, - unlockConditionTimestamp: groupKey, - type: object.type, - commonObjectType: CommonMigrationObjectType.Basic, - output: object, - uniqueId: objectFields.id.id, - }; - basicObjectMap.set(groupKey, newBasicObject); - flatObjects.push(newBasicObject); - } - } else if (object.type === STARDUST_NFT_OUTPUT_TYPE) { + if (object.type === STARDUST_NFT_OUTPUT_TYPE) { const nftDetails = await getNftDetails(object, groupKey, client); flatObjects.push(...nftDetails); }