mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-08 00:34:25 +01:00
Fix clipboard for android
This commit is contained in:
committed by
Tony Giorgio
parent
d951fceaca
commit
de6cfa185c
@@ -5,6 +5,8 @@ import { Button } from "~/components/layout";
|
||||
import { showToast } from "~/components/Toaster";
|
||||
import { useMegaStore } from "~/state/megaStore";
|
||||
import { toParsedParams } from "~/logic/waila";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
|
||||
export default function Scanner() {
|
||||
const [state, actions] = useMegaStore();
|
||||
@@ -22,7 +24,17 @@ export default function Scanner() {
|
||||
|
||||
async function handlePaste() {
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
let text;
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
const { value } = await Clipboard.read({
|
||||
type: "string"
|
||||
});
|
||||
text = value;
|
||||
} else {
|
||||
text = await navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
const trimText = text.trim();
|
||||
setScanResult(trimText);
|
||||
} catch (e) {
|
||||
|
||||
@@ -45,6 +45,8 @@ import { InfoBox } from "~/components/InfoBox";
|
||||
import { useI18n } from "~/i18n/context";
|
||||
import { ParsedParams, toParsedParams } from "~/logic/waila";
|
||||
import { FeesModal } from "~/components/MoreInfoModal";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
|
||||
export type SendSource = "lightning" | "onchain";
|
||||
|
||||
@@ -384,11 +386,21 @@ export default function Send() {
|
||||
}
|
||||
|
||||
async function handlePaste() {
|
||||
if (!navigator.clipboard.readText)
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
let text;
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
const { value } = await Clipboard.read({
|
||||
type: "string"
|
||||
});
|
||||
text = value;
|
||||
} else {
|
||||
if (!navigator.clipboard.readText) {
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
}
|
||||
text = await navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
const trimText = text.trim();
|
||||
setFieldDestination(trimText);
|
||||
parsePaste(trimText);
|
||||
|
||||
@@ -27,6 +27,8 @@ import { ConfirmDialog } from "~/components/Dialog";
|
||||
import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
|
||||
import { WORDS_EN } from "~/utils/words";
|
||||
import { InfoBox } from "~/components/InfoBox";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
|
||||
type SeedWordsForm = {
|
||||
words: string[];
|
||||
@@ -91,17 +93,27 @@ function TwelveWordsEntry() {
|
||||
});
|
||||
|
||||
async function handlePaste() {
|
||||
if (!navigator.clipboard.readText)
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
let text;
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
const { value } = await Clipboard.read({
|
||||
type: "string"
|
||||
});
|
||||
text = value;
|
||||
} else {
|
||||
if (!navigator.clipboard.readText) {
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
}
|
||||
text = await navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
// split words on space or newline
|
||||
const words = text.split(/[\s\n]+/);
|
||||
|
||||
if (words.length !== 12)
|
||||
if (words.length !== 12) {
|
||||
return showToast(new Error("Wrong number of words"));
|
||||
}
|
||||
|
||||
setValues(seedWordsForm, "words", words);
|
||||
validate(seedWordsForm);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Thanks you https://soorria.com/snippets/use-copy-solidjs
|
||||
import type { Accessor } from "solid-js";
|
||||
import { createSignal } from "solid-js";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
export type UseCopyProps = {
|
||||
copiedTimeout?: number;
|
||||
};
|
||||
@@ -12,7 +14,13 @@ export const useCopy = ({ copiedTimeout = 2000 }: UseCopyProps = {}): [
|
||||
const [copied, setCopied] = createSignal(false);
|
||||
let timeout: number;
|
||||
const copy: CopyFn = async (text) => {
|
||||
await navigator.clipboard.writeText(text);
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
await Clipboard.write({
|
||||
string: text
|
||||
});
|
||||
} else {
|
||||
await navigator.clipboard.writeText(text);
|
||||
}
|
||||
setCopied(true);
|
||||
if (timeout) clearTimeout(timeout);
|
||||
timeout = setTimeout(() => setCopied(false), copiedTimeout);
|
||||
|
||||
Reference in New Issue
Block a user