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

feat(wallet-dashboard): display migration summary in migration confirmation view #4640

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import React from 'react';
import { MigrationObjectLoading, VirtualList } from '@/components';
import { useCurrentAccount } from '@iota/dapp-kit';
import { IotaObjectData } from '@iota/iota-sdk/client';
Expand All @@ -21,10 +20,11 @@ import { useGroupedMigrationObjectsByExpirationDate } 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 { MigrationObjectDetailsCard } from '@/components/migration/migration-object-details-card';
import { filterMigrationObjects, summarizeMigratableObjectValues } from '@/lib/utils';
import { DialogLayout, DialogLayoutBody, DialogLayoutFooter } from '../../layout';
import { Transaction } from '@iota/iota-sdk/transactions';
import { StardustOutputDetailsFilter } from '@/lib/enums';
import { MigrationObjectDetailsCard } from '@/components/migration/migration-object-details-card';

interface ConfirmMigrationViewProps {
basicOutputObjects: IotaObjectData[] | undefined;
Expand Down Expand Up @@ -65,21 +65,69 @@ export function ConfirmMigrationView({
isTimelocked,
);

const { totalNotOwnedStorageDepositReturnAmount } = summarizeMigratableObjectValues({
const {
totalIotaAmount,
totalNativeTokens: migratableNativeTokens,
totalVisualAssets: migratableVisualAssets,
totalNotOwnedStorageDepositReturnAmount,
} = summarizeMigratableObjectValues({
basicOutputs: basicOutputObjects,
nftOutputs: nftOutputObjects,
address: account?.address || '',
});

const [timelockedIotaTokens, symbol] = useFormatCoin(totalIotaAmount, IOTA_TYPE_ARG);
const [gasFee, gasFeeSymbol] = useFormatCoin(migrateData?.gasBudget, IOTA_TYPE_ARG);
const [totalStorageDepositReturnAmountFormatted, totalStorageDepositReturnAmountSymbol] =
useFormatCoin(totalNotOwnedStorageDepositReturnAmount.toString(), IOTA_TYPE_ARG);

const filteredIotaObjects = filterMigrationObjects(
resolvedObjects,
StardustOutputDetailsFilter.IOTA,
);
const filteredNativeTokens = filterMigrationObjects(
resolvedObjects,
StardustOutputDetailsFilter.NativeTokens,
);
const filteredVisualAssets = filterMigrationObjects(
resolvedObjects,
StardustOutputDetailsFilter.VisualAssets,
);
const filteredWithExpiration = filterMigrationObjects(
resolvedObjects,
StardustOutputDetailsFilter.WithExpiration,
);

const assetsToMigrateCategories = [
{
title: 'IOTA Tokens',
subtitle: `${timelockedIotaTokens} ${symbol}`,
filteredObjects: filteredIotaObjects,
},
{
title: 'Native Tokens',
subtitle: `${migratableNativeTokens} Types`,
filteredObjects: filteredNativeTokens,
},
{
title: 'Visual Assets',
subtitle: `${migratableVisualAssets} Assets`,
filteredObjects: filteredVisualAssets,
},
{
title: 'With Expiration',
subtitle: `${filteredWithExpiration.length} Objects`,
filteredObjects: filteredWithExpiration,
},
];
const filteredAssetsToMigrateCategories = assetsToMigrateCategories.filter(
({ filteredObjects }) => filteredObjects.length > 0,
);
return (
<DialogLayout>
<Header title="Confirmation" onClose={() => setOpen(false)} titleCentered />
<Header title="Migrate Your Assets" onClose={() => setOpen(false)} titleCentered />
<DialogLayoutBody>
<div className="flex h-full flex-col gap-y-md overflow-y-auto">
<div className="flex h-full flex-col gap-y-md">
{isGroupedMigrationError && !isLoading && (
<InfoBox
title="Error"
Expand All @@ -106,27 +154,37 @@ export function ConfirmMigrationView({
</>
) : (
<>
<Collapsible
defaultOpen
render={() => (
<Title size={TitleSize.Small} title="Assets to Migrate" />
<div className="flex flex-col gap-y-sm">
{filteredAssetsToMigrateCategories.map(
({ title, subtitle, filteredObjects }) => (
<Collapsible
key={title}
render={() => (
<Title
size={TitleSize.Small}
title={title}
subtitle={subtitle}
/>
)}
>
<div className="flex h-full max-h-[300px] flex-col gap-y-sm pb-sm">
<VirtualList
heightClassName="h-full"
overflowClassName="overflow-y-auto"
items={filteredObjects}
estimateSize={() => 58}
render={(migrationObject) => (
<MigrationObjectDetailsCard
migrationObject={migrationObject}
isTimelocked={isTimelocked}
/>
)}
/>
</div>
</Collapsible>
),
)}
>
<div className="h-[500px] pb-md--rs xl:h-[600px]">
<VirtualList
heightClassName="h-full"
overflowClassName="overflow-y-auto"
items={resolvedObjects}
estimateSize={() => 58}
render={(migrationObject) => (
<MigrationObjectDetailsCard
migrationObject={migrationObject}
isTimelocked={isTimelocked}
/>
)}
/>
</div>
</Collapsible>
</div>
<Panel hasBorder>
<div className="flex flex-col gap-y-sm p-md">
<KeyValueInfo
Expand Down
Loading