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): add tx details state to the end of migration flow #4547

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
5 changes: 5 additions & 0 deletions apps/wallet-dashboard/app/(protected)/migrations/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ function MigrationDashboardPage(): JSX.Element {
setSelectedStardustObjectsCategory(undefined);
}

function handleMigrationDialogClose() {
setIsMigrationDialogOpen(false);
}

return (
<div className="flex h-full w-full flex-wrap items-center justify-center space-y-4">
<div
Expand All @@ -159,6 +163,7 @@ function MigrationDashboardPage(): JSX.Element {
selectedStardustObjectsCategory ===
StardustOutputMigrationStatus.TimeLocked
}
handleClose={handleMigrationDialogClose}
/>
)}
<Panel>
Expand Down
176 changes: 0 additions & 176 deletions apps/wallet-dashboard/components/Dialogs/MigrationDialog.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/wallet-dashboard/components/Dialogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export * from './Staking';
export * from './unstake';
export * from './vesting';
export * from './settings';
export * from './MigrationDialog';
export * from './migration';
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import React, { useState } from 'react';
import { useCurrentAccount, useSignAndExecuteTransaction } from '@iota/dapp-kit';
import { IotaObjectData } from '@iota/iota-sdk/client';
import { useMigrationTransaction } from '@/hooks/useMigrationTransaction';
import { Dialog } from '@iota/apps-ui-kit';
import toast from 'react-hot-toast';
import { TransactionDialogView } from '../TransactionDialog';
import { MigrationDialogView } from './enums';
import { ConfirmMigrationView } from './views';

interface MigrationDialogProps {
handleClose: () => void;
basicOutputObjects: IotaObjectData[] | undefined;
nftOutputObjects: IotaObjectData[] | undefined;
onSuccess: (digest: string) => void;
setOpen: (bool: boolean) => void;
open: boolean;
isTimelocked: boolean;
}

export function MigrationDialog({
handleClose,
basicOutputObjects = [],
nftOutputObjects = [],
onSuccess,
open,
setOpen,
isTimelocked,
}: MigrationDialogProps): JSX.Element {
const account = useCurrentAccount();
const [txDigest, setTxDigest] = useState<string>('');
const [view, setView] = useState<MigrationDialogView>(MigrationDialogView.Confirmation);

const {
data: migrateData,
isPending: isMigrationPending,
isError: isMigrationError,
} = useMigrationTransaction(account?.address || '', basicOutputObjects, nftOutputObjects);

const { mutateAsync: signAndExecuteTransaction, isPending: isSendingTransaction } =
useSignAndExecuteTransaction();

async function handleMigrate(): Promise<void> {
if (!migrateData) return;
signAndExecuteTransaction(
{
transaction: migrateData.transaction,
},
{
onSuccess: (tx) => {
onSuccess(tx.digest);
evavirseda marked this conversation as resolved.
Show resolved Hide resolved
setTxDigest(tx.digest);
panteleymonchuk marked this conversation as resolved.
Show resolved Hide resolved
setView(MigrationDialogView.TransactionDetails);
},
},
)
.then(() => {
toast.success('Migration transaction has been sent');
})
.catch(() => {
toast.error('Migration transaction was not sent');
});
}

return (
<Dialog open={open} onOpenChange={setOpen}>
{view === MigrationDialogView.Confirmation && (
<ConfirmMigrationView
basicOutputObjects={basicOutputObjects}
nftOutputObjects={nftOutputObjects}
onSuccess={handleMigrate}
setOpen={setOpen}
isTimelocked={isTimelocked}
migrateData={migrateData}
isMigrationPending={isMigrationPending}
isMigrationError={isMigrationError}
isSendingTransaction={isSendingTransaction}
/>
)}
{view === MigrationDialogView.TransactionDetails && (
<TransactionDialogView txDigest={txDigest} onClose={handleClose} />
evavirseda marked this conversation as resolved.
Show resolved Hide resolved
)}
</Dialog>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export * from './view.enums';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export enum MigrationDialogView {
Confirmation = 'Confirmation',
TransactionDetails = 'TransactionDetails',
}
6 changes: 6 additions & 0 deletions apps/wallet-dashboard/components/Dialogs/migration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export * from './MigrationDialog';

export * from './views';
Loading
Loading