Skip to content

Commit

Permalink
feat: add copy URL button to share page
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Oct 26, 2024
1 parent 798e8c1 commit e14befd
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/pages/wallet/Share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import QRCode from "qrcode.react";
import { useEffect, useState } from "react";
import { Backbar } from "../../components/Backbar";
import { localStorageKeys } from "../../constants";
import { PopiconsClipboardCheckDuotone, PopiconsClipboardDuotone } from "@popicons/react";

export function Share() {
const [shareURI, setShareURI] = useState("");
const [copied, setCopied] = useState(false);

useEffect(() => {
const nwcUrl = window.localStorage.getItem(localStorageKeys.nwcUrl);
Expand All @@ -15,18 +17,40 @@ export function Share() {
}
}, []);

function copy() {
try {
window.navigator.clipboard.writeText(shareURI);
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 3000);
} catch (error) {
alert("Failed to copy: " + error);
}
}

return (
<>
<Backbar />
<div className="flex flex-grow gap-5 flex-col justify-center items-center">
Let your co-workers scan this QR code
<QRCode value={shareURI} size={256} />
or share this URI with them:
<input
type="text"
value={shareURI}
className="input input-bordered overflow-ellipsis w-full max-w-xs"
/>
<div className="flex border-2 rounded-lg">
<input
type="text"
value={shareURI}
className="input overflow-ellipsis w-full max-w-xs text-sm"
/>
<div className="w-1 h-full border-l-base-200 border-l-2"></div>
<button className="p-4" onClick={copy}>
{copied ? (
<PopiconsClipboardCheckDuotone className="w-4 h-4" />
) : (
<PopiconsClipboardDuotone className="w-4 h-4" />
)}
</button>
</div>
</div>
</>
);
Expand Down

0 comments on commit e14befd

Please sign in to comment.