Skip to content

Commit

Permalink
feat: add to unmigratable objects and fix funciton
Browse files Browse the repository at this point in the history
  • Loading branch information
evavirseda committed Dec 27, 2024
1 parent 60843a7 commit 6fa4f4b
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function summarizeMigratableObjectValues({
StardustOutputDetailsFilter.NativeTokens,
);
}
totalNativeTokens = calculateTotalNativeTokensByName(filteredObjects);
totalNativeTokens = getUniqueNativeTokensByCoinType(filteredObjects);

for (const output of outputObjects) {
const outputObjectFields = extractMigrationOutputFields(output);
Expand All @@ -111,16 +111,20 @@ interface UnmmigratableObjectsData {
export function summarizeTimelockedObjectValues({
basicOutputs = [],
nftOutputs = [],
resolvedObjects,
}: Omit<SummarizeMigrationObjectParams, 'address'>): 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;

Expand Down Expand Up @@ -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;
}

0 comments on commit 6fa4f4b

Please sign in to comment.