diff --git a/src/components/BuyerSteps/QrCodeComponent.vue b/src/components/BuyerSteps/QrCodeComponent.vue index 92255a8..44c6b01 100644 --- a/src/components/BuyerSteps/QrCodeComponent.vue +++ b/src/components/BuyerSteps/QrCodeComponent.vue @@ -22,6 +22,8 @@ const pixTimestamp = ref(""); const releaseSignature = ref(""); const solicitationData = ref(null); const pollingInterval = ref(null); +const copyFeedback = ref(false); +const copyFeedbackTimeout = ref(null); // Function to generate QR code SVG const generateQrCodeSvg = async (text: string) => { @@ -80,6 +82,29 @@ const startPolling = () => { pollingInterval.value = setInterval(checkSolicitationStatus, 10000); }; + +const copyToClipboard = async () => { + if (!qrCode.value) { + return; + } + + try { + await navigator.clipboard.writeText(qrCode.value); + + if (copyFeedbackTimeout.value) { + clearTimeout(copyFeedbackTimeout.value); + } + + copyFeedback.value = true; + + copyFeedbackTimeout.value = setTimeout(() => { + copyFeedback.value = false; + }, 2000); + } catch (error) { + console.error("Error copying to clipboard:", error); + } +}; + onMounted(async () => { try { const { tokenAddress, sellerAddress, amount } = await getUnreleasedLockById( @@ -119,6 +144,10 @@ onUnmounted(() => { clearInterval(pollingInterval.value); pollingInterval.value = null; } + if (copyFeedbackTimeout.value) { + clearTimeout(copyFeedbackTimeout.value); + copyFeedbackTimeout.value = null; + } }); @@ -156,13 +185,24 @@ onUnmounted(() => { {{ qrCode }} - Copy PIX code +
+ Copy PIX code + + + Código copiado! + + +