15 lines
4.7 KiB
JavaScript
15 lines
4.7 KiB
JavaScript
var h=Object.defineProperty;var w=(a,e,n)=>e in a?h(a,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):a[e]=n;var u=(a,e,n)=>(w(a,typeof e!="symbol"?e+"":e,n),n);import{i as y,w as p}from"./wait-8f4ae121.js";/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/class b{constructor(){u(this,"startTimer",e=>{const n=new Date().getTime()+e*1e3;document.getElementById("countdown").innerHTML="10:00 min";const c=()=>{const r=new Date().getTime(),t=n-r;if(document.getElementsByClassName("btc-value")[0].innerHTML.includes("Refreshing"))return;if(t<0){refreshBTCPrice();return}const s=Math.floor(t%(1e3*60*60)/(1e3*60)),i=Math.floor(t%(1e3*60)/1e3),d=String(s).padStart(2,"0"),m=String(i).padStart(2,"0");document.getElementById("countdown").innerHTML=d+":"+m+" min"};clearInterval(window.countdownInterval),window.countdownInterval=setInterval(c,1e3)});this.copyToClipboard=this.copyToClipboard.bind(this),this.refreshBTCPrice=this.refreshBTCPrice.bind(this),this.fetchAndDisplayQRCode=this.fetchAndDisplayQRCode.bind(this),this.startTimer=this.startTimer.bind(this)}copyToClipboard(e,n,c){const r=c?n.nextElementSibling:n,t=r.src,o=document.createElement("input"),s=document.getElementById(e),{value:i,innerText:d}=s||{},m=i||d;o.value=m,document.body.appendChild(o),o.select(),document.execCommand("copy"),document.body.removeChild(o),r.src="data:image/svg+xml;base64,"+btoa(`
|
|
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M4.04706 14C4.04706 8.55609 8.46025 4.1429 13.9042 4.1429C19.3482 4.1429 23.7613 8.55609 23.7613 14C23.7613 19.444 19.3482 23.8572 13.9042 23.8572C8.46025 23.8572 4.04706 19.444 4.04706 14Z" stroke="#000" stroke-width="2.19048" stroke-linecap="round" stroke-linejoin="round"/>
|
|
<path d="M9.52325 14L12.809 17.2858L18.2852 11.8096" stroke="#000" stroke-width="2.19048" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
`),setTimeout(()=>{r.src=t},5e3)}async fetchAndDisplayQRCode(e=null){try{const n=document.querySelector('meta[name="btc_address"]').content,r=encodeURIComponent(`bitcoin:${n}?amount=${e||"{{$btc_amount}}"}`),t=await fetch(`/api/v1/get-blockonomics-qr-code?qr_string=${r}`);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const o=await t.text();document.getElementById("qrcode-container").innerHTML=o}catch(n){console.error("Error fetching QR code:",n),document.getElementById("qrcode-container").textContent="Error loading QR code"}}async refreshBTCPrice(){const e=document.querySelector(".icon-refresh");e.classList.add("rotating"),document.getElementsByClassName("btc-value")[0].innerHTML="Refreshing...";const n=async()=>{try{const c=document.querySelector('meta[name="currency"]').content,r=await fetch(`/api/v1/get-btc-price?currency=${c}`);if(!r.ok)throw new Error("Network response was not ok");return(await r.json()).price}catch(c){console.error("There was a problem with the BTC price fetch operation:",c)}};try{const c=await n();if(c){const r=document.querySelector('meta[name="currency"]').content;document.getElementsByClassName("btc-value")[0].innerHTML="1 BTC = "+(c||"N/A")+" "+r+", updates in <span id='countdown'></span>";const t=(document.querySelector('meta[name="amount"]').content/c).toFixed(10);document.querySelector('input[name="btc_price"]').value=c,document.querySelector('input[name="btc_amount"]').value=t,document.getElementById("btc-amount").textContent=t;const o=document.querySelector('meta[name="btc_address"]').content,s=document.getElementById("qr-code-link"),i=document.getElementById("open-in-wallet-link");s.href=`bitcoin:${o}?amount=${t}`,i.href=`bitcoin:${o}?amount=${t}`,await this.fetchAndDisplayQRCode(t),this.startTimer(600)}}finally{e.classList.remove("rotating")}}handle(){window.copyToClipboard=this.copyToClipboard,window.refreshBTCPrice=this.refreshBTCPrice,window.fetchAndDisplayQRCode=this.fetchAndDisplayQRCode,window.startTimer=this.startTimer;const e=()=>{const c=`wss://www.blockonomics.co/payment/${document.querySelector('meta[name="btc_address"]').content}`,r=new WebSocket(c);r.onmessage=function(t){const o=JSON.parse(t.data);console.log("Payment status:",o.status);const s=o.status===0,i=o.status===1,d=o.status===2;(s||i||d)&&(document.querySelector('input[name="txid"]').value=o.txid||"",document.getElementById("server-response").submit())}};startTimer(600),e(),fetchAndDisplayQRCode()}}function l(){new b().handle(),window.bootBlockonomics=l}y()?l():p("#blockonomics-payment").then(()=>l());
|