mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +00:00
184 lines
6.5 KiB
TypeScript
184 lines
6.5 KiB
TypeScript
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
import { Send, Zap, Loader2, X } from 'lucide-react';
|
|
|
|
interface SendCardProps {
|
|
mode: 'tokens' | 'lightning';
|
|
sendAmount: string;
|
|
setSendAmount: (value: string) => void;
|
|
lightningInvoice: string;
|
|
setLightningInvoice: (value: string) => void;
|
|
lightningAddressInput: string;
|
|
setLightningAddressInput: (value: string) => void;
|
|
lightningAddressAmount: string;
|
|
setLightningAddressAmount: (value: string) => void;
|
|
pendingLightningAddress: string | null;
|
|
setPendingLightningAddress: (value: string | null) => void;
|
|
activeMintUrl: string | null;
|
|
onSend: () => void;
|
|
isResolvingAddress: boolean;
|
|
isLoading: boolean;
|
|
}
|
|
|
|
export function SendCard({
|
|
mode,
|
|
sendAmount,
|
|
setSendAmount,
|
|
lightningInvoice,
|
|
setLightningInvoice,
|
|
lightningAddressInput,
|
|
setLightningAddressInput,
|
|
lightningAddressAmount,
|
|
setLightningAddressAmount,
|
|
pendingLightningAddress,
|
|
setPendingLightningAddress,
|
|
activeMintUrl,
|
|
onSend,
|
|
isResolvingAddress,
|
|
isLoading,
|
|
}: SendCardProps) {
|
|
return (
|
|
<Card className="border-0 shadow-none bg-muted/30">
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center">
|
|
<Send className="h-5 w-5 mr-2" />
|
|
Send
|
|
</CardTitle>
|
|
<CardDescription className="min-h-[2.5rem] flex items-center">
|
|
{mode === 'tokens'
|
|
? 'Generate Cashu token to send'
|
|
: pendingLightningAddress
|
|
? (
|
|
<span className="inline-block px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-md">
|
|
<span className="font-bold text-primary">Sending to:</span>{' '}
|
|
<span className="font-semibold text-foreground">{pendingLightningAddress}</span>
|
|
</span>
|
|
)
|
|
: 'Pay Lightning invoices or addresses from balance'
|
|
}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
{mode === 'tokens' ? (
|
|
<>
|
|
{!activeMintUrl && (
|
|
<div className="text-sm text-muted-foreground bg-muted p-3 rounded">
|
|
Select a mint to send tokens
|
|
</div>
|
|
)}
|
|
<div className="flex gap-2">
|
|
<Input
|
|
placeholder="Amount (sats)"
|
|
type="number"
|
|
value={sendAmount}
|
|
onChange={(e) => setSendAmount(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter' && sendAmount && activeMintUrl && !isLoading) {
|
|
onSend();
|
|
}
|
|
}}
|
|
disabled={!activeMintUrl}
|
|
/>
|
|
<Button onClick={onSend} disabled={!sendAmount || !activeMintUrl || isLoading}>
|
|
<Send className="h-4 w-4 mr-2" />
|
|
Send
|
|
</Button>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<>
|
|
{!activeMintUrl && (
|
|
<div className="text-sm text-muted-foreground bg-muted p-3 rounded">
|
|
Select a mint to pay Lightning invoices
|
|
</div>
|
|
)}
|
|
{pendingLightningAddress ? (
|
|
// Step 2: Show amount input for Lightning address
|
|
<div className="space-y-3">
|
|
<div className="flex gap-2">
|
|
<Input
|
|
placeholder="Amount (sats)"
|
|
type="number"
|
|
value={lightningAddressAmount}
|
|
onChange={(e) => setLightningAddressAmount(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter' && lightningAddressAmount && activeMintUrl && !isResolvingAddress && !isLoading) {
|
|
onSend();
|
|
}
|
|
}}
|
|
autoFocus
|
|
disabled={!activeMintUrl}
|
|
/>
|
|
<Button
|
|
onClick={onSend}
|
|
disabled={!lightningAddressAmount || !activeMintUrl || isResolvingAddress || isLoading}
|
|
>
|
|
{isResolvingAddress ? (
|
|
<>
|
|
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
|
Sending...
|
|
</>
|
|
) : (
|
|
<>
|
|
<Zap className="h-4 w-4 mr-2" />
|
|
Pay
|
|
</>
|
|
)}
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
onClick={() => {
|
|
setPendingLightningAddress(null);
|
|
setLightningAddressAmount('');
|
|
}}
|
|
className="h-10 w-10"
|
|
title="Cancel"
|
|
>
|
|
<X className="h-4 w-4" />
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
// Step 1: Show invoice/address input
|
|
<div className="flex gap-2">
|
|
<Input
|
|
placeholder="lnbc... or [email protected]"
|
|
value={lightningInvoice || lightningAddressInput}
|
|
onChange={(e) => {
|
|
const value = e.target.value;
|
|
if (value.includes('@')) {
|
|
setLightningAddressInput(value);
|
|
setLightningInvoice('');
|
|
} else {
|
|
setLightningInvoice(value);
|
|
setLightningAddressInput('');
|
|
}
|
|
}}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Enter' && (lightningInvoice.trim() || lightningAddressInput.trim()) && activeMintUrl && !isLoading) {
|
|
onSend();
|
|
}
|
|
}}
|
|
className="flex-1"
|
|
disabled={!activeMintUrl}
|
|
/>
|
|
<Button
|
|
onClick={onSend}
|
|
disabled={(!lightningInvoice.trim() && !lightningAddressInput.trim()) || !activeMintUrl || isLoading}
|
|
>
|
|
<>
|
|
<Zap className="h-4 w-4 mr-2" />
|
|
Pay
|
|
</>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|