Skip to content

Commit

Permalink
feat(dashboard): extract basic objects from all outputs (#4730)
Browse files Browse the repository at this point in the history
  • Loading branch information
VmMad authored Jan 10, 2025
1 parent 41e82b4 commit e5625e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions apps/wallet-dashboard/app/(protected)/migrations/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 22 additions & 25 deletions apps/wallet-dashboard/lib/utils/migration/groupMigrationObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e5625e6

Please sign in to comment.