Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
feat: add success screen for send
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jun 27, 2024
1 parent 4f4d1cb commit dd1f47f
Showing 1 changed file with 76 additions and 26 deletions.
102 changes: 76 additions & 26 deletions frontend/src/screens/wallet/Send.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { CircleCheck, CopyIcon } from "lucide-react";
import React from "react";
import { Link } from "react-router-dom";
import AppHeader from "src/components/AppHeader";
import { Button } from "src/components/ui/button";
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "src/components/ui/card";
import { Input } from "src/components/ui/input";
import { Label } from "src/components/ui/label";
import { LoadingButton } from "src/components/ui/loading-button";
import { useToast } from "src/components/ui/use-toast";
import { useCSRF } from "src/hooks/useCSRF";
import { copyToClipboard } from "src/lib/clipboard";
import { PayInvoiceResponse } from "src/types";
import { request } from "src/utils/request";

Expand All @@ -13,6 +23,9 @@ export default function Send() {
const { toast } = useToast();
const [isLoading, setLoading] = React.useState(false);
const [invoice, setInvoice] = React.useState("");
const [payResponse, setPayResponse] =
React.useState<PayInvoiceResponse | null>(null);
const [paymentDone, setPaymentDone] = React.useState(false);

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
Expand All @@ -32,10 +45,10 @@ export default function Send() {
body: JSON.stringify({ invoice: invoice.trim() }),
}
);
// setSignatureMessage(message);
// setMessage("");
if (payInvoiceResponse) {
// setSignature(signMessageResponse.signature);
setPayResponse(payInvoiceResponse);
setPaymentDone(true);
setInvoice("");
toast({
title: "Successfully paid invoice",
});
Expand All @@ -51,33 +64,70 @@ export default function Send() {
}
};

const copy = () => {
copyToClipboard(payResponse?.preimage as string);
toast({ title: "Copied to clipboard." });
};

return (
<div className="grid gap-5">
<AppHeader title="Send" description="Send sats from your node" />
<div className="max-w-lg">
<form onSubmit={handleSubmit} className="grid gap-5">
<div className="">
<Label htmlFor="recipient">Recipient</Label>
<Input
id="recipient"
type="text"
value={invoice}
placeholder="Paste an invoice"
onChange={(e) => {
setInvoice(e.target.value);
}}
/>
</div>
<div>
<LoadingButton
loading={isLoading}
type="submit"
disabled={!invoice}
>
Continue
</LoadingButton>
</div>
</form>
{paymentDone ? (
<>
<Card className="w-full">
<CardHeader>
<CardTitle className="text-center">
Payment Successful
</CardTitle>
</CardHeader>
<CardContent className="flex flex-col items-center gap-4">
<CircleCheck className="w-32 h-32 mb-2" />
<Button onClick={copy} variant="outline">
<CopyIcon className="w-4 h-4 mr-2" />
Copy Preimage
</Button>
</CardContent>
</Card>
{paymentDone && (
<Link to="/wallet">
<Button
className="mt-4 w-full"
onClick={() => {
setPaymentDone(false);
}}
variant="secondary"
>
Back to Wallet
</Button>
</Link>
)}
</>
) : (
<form onSubmit={handleSubmit} className="grid gap-5">
<div className="">
<Label htmlFor="recipient">Recipient</Label>
<Input
id="recipient"
type="text"
value={invoice}
placeholder="Paste an invoice"
onChange={(e) => {
setInvoice(e.target.value);
}}
/>
</div>
<div>
<LoadingButton
loading={isLoading}
type="submit"
disabled={!invoice}
>
Continue
</LoadingButton>
</div>
</form>
)}
</div>
</div>
);
Expand Down

0 comments on commit dd1f47f

Please sign in to comment.