Skip to content

Commit 6dc3a72

Browse files
committed
Refactor wallet migration process and enhance user experience
- Introduced a new dialog for aborting migrations, providing users with clear warnings and options. - Simplified the migration progress indicator, improving clarity on current steps and overall progress. - Enhanced fund transfer logic to monitor pending transactions, ensuring users are informed of transfer statuses. - Updated migration completion checks to validate wallet states and provide feedback on remaining balances and pending transactions. - Improved pre-checks for DRep registrations, ensuring users are guided through necessary steps before migration. - Added detailed certificate handling in transaction displays, enhancing visibility of DRep-related actions.
1 parent 8dd635c commit 6dc3a72

File tree

12 files changed

+1608
-500
lines changed

12 files changed

+1608
-500
lines changed

src/components/pages/wallet/info/migrate-wallet.tsx

Lines changed: 647 additions & 341 deletions
Large diffs are not rendered by default.

src/components/pages/wallet/info/migration/FundTransferStep.tsx

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from "react";
2+
import usePendingTransactions from "@/hooks/usePendingTransactions";
23
import { Button } from "@/components/ui/button";
34
import CardUI from "@/components/ui/card-content";
45
import { Alert, AlertDescription } from "@/components/ui/alert";
@@ -51,6 +52,11 @@ export default function FundTransferStep({
5152
const [isTransferring, setIsTransferring] = useState(false);
5253
const [transferComplete, setTransferComplete] = useState(false);
5354
const [transferTxId, setTransferTxId] = useState<string | null>(null);
55+
const [waitingForTransaction, setWaitingForTransaction] = useState(false);
56+
const [lastSeenPendingCount, setLastSeenPendingCount] = useState<number>(0);
57+
58+
// Monitor pending transactions
59+
const { transactions: pendingTransactions } = usePendingTransactions({ walletId: appWallet.id });
5460

5561
// Get current wallet data
5662
const currentUtxos = walletsUtxos[appWallet.id] || [];
@@ -257,17 +263,15 @@ export default function FundTransferStep({
257263
toastMessage: "Fund transfer transaction created successfully",
258264
});
259265

260-
setTransferComplete(true);
266+
// Set waiting state - we'll monitor the transaction status
267+
setWaitingForTransaction(true);
268+
setIsTransferring(false);
269+
261270
toast({
262271
title: "Transfer Initiated",
263272
description:
264273
"Fund transfer transaction has been created and is pending signatures.",
265274
});
266-
267-
// Automatically proceed to the next step after a short delay
268-
setTimeout(() => {
269-
onContinue();
270-
}, 2000); // 2 second delay to show the success message
271275
} catch (error) {
272276
console.error("Failed to transfer funds:", error);
273277
toast({
@@ -280,6 +284,54 @@ export default function FundTransferStep({
280284
}
281285
};
282286

287+
// Monitor pending transactions to detect when transfer is complete
288+
useEffect(() => {
289+
if (!waitingForTransaction) return;
290+
291+
// Track pending count to detect when transaction disappears (completed)
292+
const currentPendingCount = pendingTransactions?.length || 0;
293+
294+
// If we saw pending transactions before and now there are fewer, transaction might be completed
295+
if (lastSeenPendingCount > 0 && currentPendingCount < lastSeenPendingCount) {
296+
// Transaction likely completed and moved out of pending
297+
setTransferComplete(true);
298+
setWaitingForTransaction(false);
299+
toast({
300+
title: "Transfer Complete",
301+
description: "Fund transfer transaction has been completed successfully.",
302+
});
303+
setTimeout(() => {
304+
onContinue();
305+
}, 2000);
306+
return;
307+
}
308+
309+
if (pendingTransactions && pendingTransactions.length > 0) {
310+
setLastSeenPendingCount(pendingTransactions.length);
311+
312+
// Find the most recent migration transfer transaction
313+
const migrationTx = pendingTransactions
314+
.filter((tx: any) => tx.description?.includes("Migration: Transfer all funds"))
315+
.sort((a: any, b: any) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())[0];
316+
317+
if (migrationTx) {
318+
// Transaction is complete if it has a txHash (submitted) or state is 1 (completed)
319+
if (migrationTx.txHash || migrationTx.state === 1) {
320+
setTransferComplete(true);
321+
setWaitingForTransaction(false);
322+
toast({
323+
title: "Transfer Complete",
324+
description: "Fund transfer transaction has been completed successfully.",
325+
});
326+
// Proceed to next step after a short delay
327+
setTimeout(() => {
328+
onContinue();
329+
}, 2000);
330+
}
331+
}
332+
}
333+
}, [pendingTransactions, waitingForTransaction, onContinue, lastSeenPendingCount]);
334+
283335
if (isLoadingNewWalletData || isLoadingNewWalletDataFallback) {
284336
return (
285337
<CardUI
@@ -295,6 +347,34 @@ export default function FundTransferStep({
295347
);
296348
}
297349

350+
// Show waiting card after transaction is created
351+
if (waitingForTransaction) {
352+
return (
353+
<CardUI
354+
title="Waiting for Transaction"
355+
description="Fund transfer transaction is pending signatures"
356+
cardClassName="col-span-2"
357+
>
358+
<div className="space-y-4">
359+
<Alert className="border-blue-200/50 bg-blue-50 dark:border-blue-800/50 dark:bg-blue-900/20">
360+
<Loader className="h-4 w-4 text-blue-600 dark:text-blue-400 animate-spin" />
361+
<AlertDescription className="text-blue-800 dark:text-blue-200">
362+
<strong>Transaction Created</strong>
363+
<p className="mt-2">
364+
The fund transfer transaction has been created and is waiting for required signatures.
365+
Once all signers have signed and the transaction is submitted, you will automatically proceed to the next step.
366+
</p>
367+
</AlertDescription>
368+
</Alert>
369+
370+
<div className="flex items-center justify-center py-4">
371+
<Loader className="h-8 w-8 animate-spin text-primary" />
372+
</div>
373+
</div>
374+
</CardUI>
375+
);
376+
}
377+
298378
if (newWalletError) {
299379
return (
300380
<CardUI

0 commit comments

Comments
 (0)