Paywell / website · paywell.company / assets / pay.js
| 1 | (function(){ |
| 2 | var $=function(id){return document.getElementById(id)}; |
| 3 | var q=new URLSearchParams(location.search);var u=q.get('u');var r=q.get('r'); |
| 4 | if(!u||!/^bitcoin:/i.test(u))return; |
| 5 | var body=u.slice(8);var addr=body.split('?')[0];var params=new URLSearchParams(body.split('?')[1]||''); |
| 6 | var btc=parseFloat(params.get('amount')||'');var label=params.get('label'); |
| 7 | $('p-none').hidden=true;$('p-req').hidden=false; |
| 8 | $('p-for').textContent=(label?label+' · ':'')+'To '+addr.slice(0,10)+'…'+addr.slice(-6); |
| 9 | $('p-open').href=u; |
| 10 | $('p-usd').textContent=btc?'Loading amount…':'Any amount'; |
| 11 | if(btc){$('p-btc').textContent=btc.toFixed(8)+' BTC'; |
| 12 | fetch('/api/rate/price').then(function(x){return x.json()}).then(function(j){if(j.usd)$('p-usd').textContent='$'+(btc*j.usd).toLocaleString('en-US',{minimumFractionDigits:2,maximumFractionDigits:2});else $('p-usd').textContent=btc.toFixed(8)+' BTC';}).catch(function(){$('p-usd').textContent=btc.toFixed(8)+' BTC';});} |
| 13 | $('p-copy').addEventListener('click',function(){try{navigator.clipboard.writeText(addr);this.textContent='Copied';}catch(e){}}); |
| 14 | if(r&&/^https:\/\/paywell\.ai\//.test(r)){$('p-rate').hidden=false;$('p-rate-a').href=r;} |
| 15 | })(); |