mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +00:00
cashu wallet restore and addressed some test errors
This commit is contained in:
1 parent
cfd1e7269f
commit
aff1b0add5
6 files changed
+240
-48
No files matched your search
@@ -10,9 +10,8 @@ import { useCopyToClipboard } from '@/hooks/useCopyToClipboard';
|
||||
import { useMintManager } from '@/hooks/cashu/useMintManager';
|
||||
import { useWalletTransactions } from '@/hooks/cashu/useWalletTransactions';
|
||||
import { useHistoryManager } from '@/hooks/cashu/useHistoryManager';
|
||||
import { useNsecAccess } from '@/hooks/useNsecAccess';
|
||||
import { useBitcoinBalance, useBitcoinTransactionHistory, useBitcoinOperations } from '@/hooks/useBitcoinBalance';
|
||||
import { nostrPubkeyToBitcoinAddress, UTXO } from '@/lib/bitcoin';
|
||||
import { nostrPubkeyToBitcoinAddress } from '@/lib/bitcoin';
|
||||
import { QRModal } from '@/components/ui/qr-modal';
|
||||
import { WalletHeader } from './WalletHeader';
|
||||
import { TransactionCard } from './PaymentCard';
|
||||
@@ -54,8 +53,6 @@ export function CashuWallet() {
|
||||
// Bitcoin operations hook
|
||||
const {
|
||||
utxos,
|
||||
isLoadingUtxos,
|
||||
feeRate,
|
||||
isConsolidating,
|
||||
bitcoinMaxAmount,
|
||||
fetchBitcoinUtxos,
|
||||
@@ -141,6 +138,8 @@ export function CashuWallet() {
|
||||
handleReceive,
|
||||
handleSend,
|
||||
handleConfirmInvoicePayment,
|
||||
handleRestoreFromSeedPhrase,
|
||||
isRestoring,
|
||||
mintQuoteUnsubscribeRef,
|
||||
} = useWalletTransactions({
|
||||
coco,
|
||||
@@ -461,6 +460,10 @@ export function CashuWallet() {
|
||||
sentTokenQRCode={sentTokenQRCode}
|
||||
showSeedPhraseInfo={showSeedPhraseInfo}
|
||||
setShowSeedPhraseInfo={setShowSeedPhraseInfo}
|
||||
onRestoreFromSeedPhrase={handleRestoreFromSeedPhrase}
|
||||
isRestoring={isRestoring}
|
||||
mints={mints}
|
||||
activeMintUrl={activeMintUrl}
|
||||
/>
|
||||
|
||||
{/* Bottom Drawer Modals */}
|
||||
|
||||
@@ -23,7 +23,6 @@ interface UTXOSelectorProps {
|
||||
export function UTXOSelector({
|
||||
utxos,
|
||||
showSats,
|
||||
bitcoinAddress,
|
||||
dropdownOpen,
|
||||
setDropdownOpen,
|
||||
onShowConsolidationModal,
|
||||
@@ -89,7 +88,7 @@ export function UTXOSelector({
|
||||
No UTXOs available
|
||||
</DropdownMenuItem>
|
||||
) : (
|
||||
utxos.map((utxo, index) => (
|
||||
utxos.map((utxo) => (
|
||||
<DropdownMenuItem
|
||||
key={`utxo-${utxo.txid}-${utxo.vout}`}
|
||||
className="flex items-center justify-between p-3 text-base"
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { X, Coins, AlertTriangle, RefreshCw, Key, ArrowRightLeft } from 'lucide-react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { X, Coins, AlertTriangle, RefreshCw, Key, ArrowRightLeft, Loader2 } from 'lucide-react';
|
||||
import { QRModal } from '@/components/ui/qr-modal';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { UTXO } from '@/lib/bitcoin';
|
||||
import { useState } from 'react';
|
||||
|
||||
// Helper function to prevent complex template literals
|
||||
const getLightningAddress = (userPubkey?: string, npubCashUserInfo?: { name?: string } | null): string => {
|
||||
@@ -71,6 +74,12 @@ interface WalletModalProps {
|
||||
// Seed Phrase Info Modal
|
||||
showSeedPhraseInfo: boolean;
|
||||
setShowSeedPhraseInfo: (show: boolean) => void;
|
||||
|
||||
// Restore functionality
|
||||
onRestoreFromSeedPhrase: (seedPhrase: string, mintUrl: string) => Promise<void>;
|
||||
isRestoring: boolean;
|
||||
mints: Array<{ url: string; name?: string }>;
|
||||
activeMintUrl: string | null;
|
||||
}
|
||||
|
||||
export function WalletModals({
|
||||
@@ -101,8 +110,15 @@ export function WalletModals({
|
||||
sentTokenQRCode,
|
||||
showSeedPhraseInfo,
|
||||
setShowSeedPhraseInfo,
|
||||
onRestoreFromSeedPhrase,
|
||||
isRestoring,
|
||||
mints,
|
||||
activeMintUrl,
|
||||
}: WalletModalProps) {
|
||||
const { toast } = useToast();
|
||||
|
||||
// Restore state
|
||||
const [seedPhraseInput, setSeedPhraseInput] = useState('');
|
||||
return (
|
||||
<>
|
||||
{/* Proof Breakdown Modal */}
|
||||
@@ -351,7 +367,7 @@ export function WalletModals({
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Seed Phrase Info Modal */}
|
||||
{/* Seed Phrase Restore Modal */}
|
||||
{showSeedPhraseInfo && (
|
||||
<div
|
||||
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
|
||||
@@ -368,48 +384,90 @@ export function WalletModals({
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
<div className="flex items-center mb-4 pr-8">
|
||||
<Key className="h-5 w-5 mr-2" />
|
||||
<h2 className="text-lg font-semibold">What is a Seed Phrase?</h2>
|
||||
<h2 className="text-lg font-semibold">Restore from Seed Phrase</h2>
|
||||
</div>
|
||||
<p className="text-muted-foreground mb-6">
|
||||
Your seed phrase is a secure way to backup and restore your wallet
|
||||
|
||||
<p className="text-muted-foreground mb-4">
|
||||
Enter your seed phrase to restore tokens from the active mint.
|
||||
</p>
|
||||
|
||||
<div className="space-y-4 text-sm">
|
||||
<div>
|
||||
<h4 className="font-semibold mb-2">🔐 Recovery Key</h4>
|
||||
<p className="text-muted-foreground">
|
||||
Your seed phrase is a 12-word recovery key that allows you to restore your wallet
|
||||
on any device. It's generated using industry-standard BIP39 wordlists.
|
||||
{activeMintUrl && (
|
||||
<div className="bg-muted p-3 rounded-md mb-4">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
<strong>Active Mint:</strong> {mints.find(m => m.url === activeMintUrl)?.name || new URL(activeMintUrl).hostname}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
)}
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<h4 className="font-semibold mb-2">💾 Backup Important</h4>
|
||||
<p className="text-muted-foreground">
|
||||
Write down your seed phrase and store it securely offline. Anyone with access
|
||||
to your seed phrase can control your wallet and funds.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h4 className="font-semibold mb-2">🛡️ Security Tips</h4>
|
||||
<ul className="text-muted-foreground space-y-1 ml-4">
|
||||
<li>• Never share your seed phrase with anyone</li>
|
||||
<li>• Store it offline in a secure location</li>
|
||||
<li>• Don't take screenshots or store it digitally</li>
|
||||
<li>• Use it only to restore your wallet</li>
|
||||
</ul>
|
||||
<Label htmlFor="seed-phrase">Seed Phrase</Label>
|
||||
<Input
|
||||
id="seed-phrase"
|
||||
type="text"
|
||||
placeholder="Enter your 12-word seed phrase..."
|
||||
value={seedPhraseInput}
|
||||
onChange={(e) => setSeedPhraseInput(e.target.value)}
|
||||
className="mt-1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="bg-muted p-3 rounded-md">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<strong>Note:</strong> The seed phrase shown above is masked for privacy.
|
||||
Click the copy button to access the actual phrase for backup purposes.
|
||||
<strong>Note:</strong> This will restore tokens from the provided seed phrase and add them to your current wallet balance.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<Button
|
||||
onClick={async () => {
|
||||
if (!seedPhraseInput.trim()) {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Missing Information",
|
||||
description: "Please enter your seed phrase.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!activeMintUrl) {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "No Active Mint",
|
||||
description: "Please select a mint first.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await onRestoreFromSeedPhrase(seedPhraseInput.trim(), activeMintUrl);
|
||||
setSeedPhraseInput('');
|
||||
setShowSeedPhraseInfo(false);
|
||||
} catch (error) {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Restore Failed",
|
||||
description: error instanceof Error ? error.message : "Failed to restore from seed phrase",
|
||||
});
|
||||
}
|
||||
}}
|
||||
disabled={isRestoring || !seedPhraseInput.trim() || !activeMintUrl}
|
||||
className="w-full"
|
||||
>
|
||||
{isRestoring ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
Restoring...
|
||||
</>
|
||||
) : (
|
||||
'Restore Tokens'
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user