diff --git a/src/routes/Scanner.tsx b/src/routes/Scanner.tsx index e51869b..3017657 100644 --- a/src/routes/Scanner.tsx +++ b/src/routes/Scanner.tsx @@ -74,10 +74,13 @@ export default function Scanner() { history.back(); } - function handlePaste() { - navigator.clipboard.readText().then((text) => { + async function handlePaste() { + try { + const text = await navigator.clipboard.readText(); setScanResult(text); - }); + } catch (e) { + console.error(e); + } } onMount(async () => { diff --git a/src/routes/Send.tsx b/src/routes/Send.tsx index 7f08792..1287e11 100644 --- a/src/routes/Send.tsx +++ b/src/routes/Send.tsx @@ -358,19 +358,17 @@ export default function Send() { parsePaste(text); } - function handlePaste() { + async function handlePaste() { if (!navigator.clipboard.readText) return showToast(new Error("Clipboard not supported")); - navigator.clipboard - .readText() - .then((text) => { - setFieldDestination(text); - parsePaste(text); - }) - .catch((e) => { - showToast(new Error("Failed to read clipboard: " + e.message)); - }); + try { + const text = await navigator.clipboard.readText(); + setFieldDestination(text); + parsePaste(text); + } catch (e) { + console.error(e); + } } async function processContacts( diff --git a/src/utils/useCopy.ts b/src/utils/useCopy.ts index 358b4fe..cb5ec96 100644 --- a/src/utils/useCopy.ts +++ b/src/utils/useCopy.ts @@ -10,7 +10,7 @@ export const useCopy = ({ copiedTimeout = 2000 }: UseCopyProps = {}): [ copied: Accessor ] => { const [copied, setCopied] = createSignal(false); - let timeout: NodeJS.Timeout; + let timeout: number; const copy: CopyFn = async (text) => { await navigator.clipboard.writeText(text); setCopied(true);