Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet-dashboard): stardust timelocked/unmigratabale item grouping #4527

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/wallet-dashboard/app/(protected)/migrations/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useState, useMemo, useCallback } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import clsx from 'clsx';
import { useGetStardustMigratableObjects } from '@/hooks';
import { summarizeMigratableObjectValues, summarizeUnmigratableObjectValues } from '@/lib/utils';
import { summarizeMigratableObjectValues, summarizeTimelockedObjectValues } from '@/lib/utils';
import {
Button,
ButtonSize,
Expand Down Expand Up @@ -41,8 +41,8 @@ function MigrationDashboardPage(): JSX.Element {
const {
migratableBasicOutputs,
migratableNftOutputs,
unmigratableBasicOutputs,
unmigratableNftOutputs,
timelockedBasicOutputs,
timelockedNftOutputs,
} = stardustMigrationObjects || {};

const {
Expand All @@ -54,9 +54,9 @@ function MigrationDashboardPage(): JSX.Element {
nftOutputs: migratableNftOutputs,
address,
});
const { totalUnmigratableObjects } = summarizeUnmigratableObjectValues({
basicOutputs: unmigratableBasicOutputs,
nftOutputs: unmigratableNftOutputs,
const { totalTimelockedObjects } = summarizeTimelockedObjectValues({
basicOutputs: timelockedBasicOutputs,
nftOutputs: timelockedNftOutputs,
});

const hasMigratableObjects =
Expand Down Expand Up @@ -106,7 +106,7 @@ function MigrationDashboardPage(): JSX.Element {

const TIMELOCKED_ASSETS_CARDS: MigrationDisplayCardProps[] = [
{
title: `${totalUnmigratableObjects}`,
title: `${totalTimelockedObjects}`,
subtitle: 'Time-locked',
icon: Clock,
},
Expand All @@ -123,8 +123,8 @@ function MigrationDashboardPage(): JSX.Element {
selectedStardustObjectsCategory === StardustOutputMigrationStatus.TimeLocked
) {
return [
...stardustMigrationObjects.unmigratableBasicOutputs,
...stardustMigrationObjects.unmigratableNftOutputs,
...stardustMigrationObjects.timelockedBasicOutputs,
...stardustMigrationObjects.timelockedNftOutputs,
];
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ function MigrationDashboardPage(): JSX.Element {
disabled={
selectedStardustObjectsCategory ===
StardustOutputMigrationStatus.TimeLocked ||
!totalUnmigratableObjects
!totalTimelockedObjects
}
onClick={() =>
setSelectedStardustObjectsCategory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { useGroupedMigrationObjectsByExpirationDate } from '@/hooks';
import {
STARDUST_MIGRATABLE_OBJECTS_FILTER_LIST,
STARDUST_UNMIGRATABLE_OBJECTS_FILTER_LIST,
STARDUST_TIMELOCKED_OBJECTS_FILTER_LIST,
} from '@/lib/constants';
import { StardustOutputDetailsFilter } from '@/lib/enums';
import {
Expand All @@ -33,7 +33,7 @@ import { filterMigrationObjects } from '@/lib/utils';

const FILTERS = {
migratable: STARDUST_MIGRATABLE_OBJECTS_FILTER_LIST,
unmigratable: STARDUST_UNMIGRATABLE_OBJECTS_FILTER_LIST,
timelocked: STARDUST_TIMELOCKED_OBJECTS_FILTER_LIST,
};

interface MigrationObjectsPanelProps {
Expand All @@ -58,7 +58,7 @@ export function MigrationObjectsPanel({

const filteredObjects = filterMigrationObjects(resolvedObjects, stardustOutputDetailsFilter);

const filters = isTimelocked ? FILTERS.unmigratable : FILTERS.migratable;
const filters = isTimelocked ? FILTERS.timelocked : FILTERS.migratable;
const isHidden = selectedObjects.length === 0;

return (
Expand Down
12 changes: 6 additions & 6 deletions apps/wallet-dashboard/hooks/useGetStardustMigratableObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ export function useGetStardustMigratableObjects(address: string) {
queryFn: () => {
const epochMs = Number(currentEpochMs) || 0;

const { migratable: migratableBasicOutputs, unmigratable: unmigratableBasicOutputs } =
const { migratable: migratableBasicOutputs, timelocked: timelockedBasicOutputs } =
groupStardustObjectsByMigrationStatus(basicOutputObjects ?? [], epochMs, address);

const { migratable: migratableNftOutputs, unmigratable: unmigratableNftOutputs } =
const { migratable: migratableNftOutputs, timelocked: timelockedNftOutputs } =
groupStardustObjectsByMigrationStatus(nftOutputObjects ?? [], epochMs, address);

return {
migratableBasicOutputs,
unmigratableBasicOutputs,
timelockedBasicOutputs,
migratableNftOutputs,
unmigratableNftOutputs,
timelockedNftOutputs,
};
},
enabled:
Expand All @@ -52,9 +52,9 @@ export function useGetStardustMigratableObjects(address: string) {
staleTime: TimeUnit.ONE_SECOND * TimeUnit.ONE_MINUTE * 5,
placeholderData: {
migratableBasicOutputs: [],
unmigratableBasicOutputs: [],
timelockedBasicOutputs: [],
migratableNftOutputs: [],
unmigratableNftOutputs: [],
timelockedNftOutputs: [],
},
});
}
7 changes: 3 additions & 4 deletions apps/wallet-dashboard/lib/constants/migration.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export const STARDUST_MIGRATABLE_OBJECTS_FILTER_LIST: StardustOutputDetailsFilte
StardustOutputDetailsFilter,
);

export const STARDUST_UNMIGRATABLE_OBJECTS_FILTER_LIST: StardustOutputDetailsFilter[] =
Object.values(StardustOutputDetailsFilter).filter(
(element) => element !== StardustOutputDetailsFilter.WithExpiration,
);
export const STARDUST_TIMELOCKED_OBJECTS_FILTER_LIST: StardustOutputDetailsFilter[] = Object.values(
StardustOutputDetailsFilter,
).filter((element) => element !== StardustOutputDetailsFilter.WithExpiration);

export const MIGRATION_OBJECT_WITHOUT_UC_KEY = 'no-unlock-condition-timestamp';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IotaObjectData } from '@iota/iota-sdk/client';

export type StardustMigrationGroupedObjects = {
migratable: IotaObjectData[];
unmigratable: IotaObjectData[];
timelocked: IotaObjectData[];
};

export function groupStardustObjectsByMigrationStatus(
Expand All @@ -15,37 +15,36 @@ export function groupStardustObjectsByMigrationStatus(
address: string,
): StardustMigrationGroupedObjects {
const migratable: IotaObjectData[] = [];
const unmigratable: IotaObjectData[] = [];
const timelocked: IotaObjectData[] = [];

const epochUnix = epochTimestampMs / MILLISECONDS_PER_SECOND;

for (const outputObject of stardustOutputObjects) {
const outputObjectFields = extractMigrationOutputFields(outputObject);

if (
outputObjectFields.timelock_uc &&
outputObjectFields.timelock_uc.fields.unix_time > epochUnix
) {
timelocked.push(outputObject);
continue;
}

if (outputObjectFields.expiration_uc) {
const unlockableAddress =
outputObjectFields.expiration_uc.fields.unix_time <= epochUnix
? outputObjectFields.expiration_uc.fields.return_address
: outputObjectFields.expiration_uc.fields.owner;

if (unlockableAddress !== address) {
unmigratable.push(outputObject);
continue;
}
}

if (
outputObjectFields.timelock_uc &&
outputObjectFields.timelock_uc.fields.unix_time > epochUnix
) {
unmigratable.push(outputObject);
continue;
}

migratable.push(outputObject);
}

return { migratable, unmigratable };
return { migratable, timelocked };
}

interface MigratableObjectsData {
Expand Down Expand Up @@ -93,10 +92,10 @@ export function summarizeMigratableObjectValues({
}

interface UnmmigratableObjectsData {
totalUnmigratableObjects: number;
totalTimelockedObjects: number;
}

export function summarizeUnmigratableObjectValues({
export function summarizeTimelockedObjectValues({
basicOutputs = [],
nftOutputs = [],
}: Omit<SummarizeMigrationObjectParams, 'address'>): UnmmigratableObjectsData {
Expand All @@ -110,9 +109,9 @@ export function summarizeUnmigratableObjectValues({
nativeTokens += parseInt(outputObjectFields.native_tokens.fields.size);
}

const totalUnmigratableObjects = basicObjects + nativeTokens + nftObjects;
const totalTimelockedObjects = basicObjects + nativeTokens + nftObjects;

return { totalUnmigratableObjects };
return { totalTimelockedObjects };
}

export function extractOwnedStorageDepositReturnAmount(
Expand Down
Loading