/* BitAddy app: make a page or a quick link (home), and manage your pages (edit). Plain JS, no build step, no third-party trackers (only BitAddy's own anonymous funnel steps, see ev.js). All user text goes in via textContent. Dialogs are in-page (never the browser's alert/confirm/prompt). */ (function () { "use strict"; var ROOT = document.getElementById("ba-app"); if (!ROOT) return; var VIEW = ROOT.getAttribute("data-view") || "home"; var CFG = null, ME = null; /* funnel steps (ev.js): anonymous, per browser tab, see the file's note */ window.baEv = window.baEv || function () { (window.baEv.q = window.baEv.q || []).push(arguments); }; (function () { var s = document.createElement("script"); s.src = "/_b/static/ev.js?v=1"; s.async = true; document.head.appendChild(s); })(); function ev(step, detail, onceKey) { try { window.baEv(step, detail, onceKey); } catch (e) {} } function payWhat(req) { return req.kind === "item" ? req.sku : req.kind; } /* sharing (share.js): the phone's share menu when there is one, and a QR picture to save */ function shareBtn(url, title, where, cls) { if (!(window.baShare && baShare.can)) return null; return el("button", { type: "button", class: "ba-btn" + (cls || ""), text: "Share", onclick: function () { ev("share_link", where); baShare.link(url, title).catch(function () {}); } }); } function qrSaveBtn(data, line1, line2, name, where) { if (!window.baShare) return null; return el("button", { type: "button", class: "ba-btn sm", text: "Save QR picture", onclick: function () { ev("qr_save", where); baShare.saveQr(data, line1, line2, name).then(function () { toast("QR picture saved"); }, function () { toast("The picture couldn't be made"); }); } }); } /* printable QR cards for Pro pages (cards.js, loaded when first needed) */ function withCards(fn) { if (window.baCards) return fn(); var s = document.createElement("script"); s.src = "/_b/static/cards.js?v=1"; s.onload = fn; s.onerror = function () { toast("The card maker didn't load. Please try again."); }; document.head.appendChild(s); } function cardsBtn(p) { return el("button", { type: "button", class: "ba-btn sm", text: "QR cards", onclick: function () { withCards(function () { cardsSheet(p); }); } }); } function cardsSheet(p) { var o = { url: location.origin + "/" + p.name, title: p.title || ("bitaddy.com/" + p.name), coins: (p.coins || []).map(function (c) { return c.coin; }), color: (CFG.themes || {})[p.theme] || "#5538ee" }; var body = el("div"), s = sheet("Printable QR cards", body); var lay = el("select", { "aria-label": "Layout" }, Object.keys(baCards.LAYOUTS).map(function (k) { return el("option", { value: k, text: baCards.LAYOUTS[k].label }); })); var line = el("input", { type: "text", maxlength: "40", value: "Tip me in crypto", "aria-label": "Line on the card" }); var prev = el("div", { class: "bp-preview", style: "background:#fff;border:1px solid var(--line);border-radius:12px;padding:10px;overflow:auto;max-height:46vh;margin:.6rem 0" }); function draw() { var root = baCards.build(o, lay.value, line.value.trim() || "Tip me in crypto"); prev.textContent = ""; var copyOf = root.firstChild.cloneNode(true); copyOf.style.zoom = lay.value === "tent" ? "0.32" : "0.55"; prev.appendChild(copyOf); } lay.onchange = draw; line.oninput = draw; body.appendChild(el("label", { text: "Layout" })); body.appendChild(lay); body.appendChild(el("label", { text: "Line on the card" })); body.appendChild(line); body.appendChild(prev); body.appendChild(el("p", { class: "ba-hint", text: "Fits A4 and US Letter. Print at 100% (“Actual size”). To save a PDF instead, choose “Save as PDF” in the print window. The QR code opens bitaddy.com/" + p.name + "." })); body.appendChild(el("div", { class: "ba-row end" }, el("button", { type: "button", class: "ba-btn p", text: "Print", onclick: function () { ev("cards_print", lay.value); draw(); window.print(); } }))); draw(); } function shareItemBtn(url, line1, line2, name) { return el("button", { type: "button", class: "ba-btn sm", text: "Share", onclick: function () { var body = el("div"), s = sheet("Share " + line1, body); body.appendChild(el("div", { class: "ba-big" }, el("a", { href: url, text: line1 }))); body.appendChild(el("div", { class: "ba-row" }, el("button", { type: "button", class: "ba-btn p", text: "Copy link", onclick: function () { ev("copy_link", "mylinks"); copy(url); } }), shareBtn(url, line1, "mylinks"))); body.appendChild(qr(url + "?q=1", 5)); body.appendChild(el("div", { class: "ba-row" }, qrSaveBtn(url + "?q=1", line1, line2, name, "mylinks"))); body.appendChild(el("p", { class: "ba-hint", text: "The QR code opens this address. Print it, post it, or send the picture." })); } }); } /* ---------- helpers ---------- */ function el(tag, attrs) { var n = document.createElement(tag); if (attrs) for (var k in attrs) { var v = attrs[k]; if (v == null || v === false) continue; if (k === "class") n.className = v; else if (k === "text") n.textContent = v; else if (k.slice(0, 2) === "on") n.addEventListener(k.slice(2), v); else if (v === true) n.setAttribute(k, ""); else n.setAttribute(k, v); } for (var i = 2; i < arguments.length; i++) add(n, arguments[i]); return n; } function add(n, c) { if (c == null || c === false) return; if (Array.isArray(c)) return c.forEach(function (x) { add(n, x); }); n.appendChild(typeof c === "string" || typeof c === "number" ? document.createTextNode(String(c)) : c); } function api(path, body) { var o = { method: body === undefined ? "GET" : "POST", headers: { "X-BitAddy": "1" }, credentials: "same-origin" }; if (body !== undefined) { o.headers["Content-Type"] = "application/json"; o.body = JSON.stringify(body); } return fetch("/_b/" + path, o).then(function (r) { return r.json().catch(function () { return {}; }).then(function (j) { if (!r.ok) throw new Error(j.error || "Something went wrong (" + r.status + ")."); return j; }); }); } function toast(t) { var d = document.querySelector(".ba-toast"); if (!d) { d = el("div", { class: "ba-toast", role: "status" }); document.body.appendChild(d); } d.textContent = t; d.classList.add("on"); clearTimeout(d._t); d._t = setTimeout(function () { d.classList.remove("on"); }, 2600); } function dialog(title, body, buttons) { return new Promise(function (res) { var d = el("div", { class: "ba-dlg" }), box = el("div", { class: "ba-dl", role: "dialog", "aria-modal": "true", "aria-label": title }, el("h2", { text: title })); if (body) box.appendChild(typeof body === "string" ? el("p", { text: body }) : body); var row = el("div", { class: "ba-row end" }); (buttons || [{ label: "OK", kind: "p", value: true }]).forEach(function (b) { row.appendChild(el("button", { type: "button", class: "ba-btn " + (b.kind || ""), text: b.label, onclick: function () { if (b.check && !b.check()) return; close(b.value); } })); }); box.appendChild(row); d.appendChild(box); document.body.appendChild(d); function close(v) { d.remove(); document.removeEventListener("keydown", esc); res(v); } function esc(e) { if (e.key === "Escape") close(null); } document.addEventListener("keydown", esc); setTimeout(function () { var f = box.querySelector("input,textarea,select") || row.lastChild; f && f.focus({ preventScroll: true }); box.scrollTop = 0; }, 30); }); } function confirmBox(t, m, yes, danger) { return dialog(t, m, [{ label: "Cancel", value: false }, { label: yes, kind: danger ? "d" : "p", value: true }]); } function copy(t, msg) { (navigator.clipboard ? navigator.clipboard.writeText(t) : Promise.reject()).then(function () { toast(msg || "Copied"); }, function () { toast("Select the text and copy it"); }); } function qr(text, size) { var q = qrcode(0, "M"); q.addData(text); q.make(); var w = el("div", { class: "ba-qr" }); w.innerHTML = q.createSvgTag({ cellSize: size || 5, margin: 2, scalable: true }); return w; } function fmtDate(ts) { return new Date(ts * 1000).toLocaleDateString([], { year: "numeric", month: "short", day: "numeric" }); } function coinName(id) { var c = (CFG.coins || []).filter(function (x) { return x.id === id; })[0]; return c ? c.name : id; } function hex(str) { return Array.from(new TextEncoder().encode(str)).map(function (b) { return b.toString(16).padStart(2, "0"); }).join(""); } function b64(bytes) { var s = ""; for (var i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]); return btoa(s); } /* bech32 -> hex (for Cardano addresses) */ function bech32hex(s) { var CH = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", p = s.lastIndexOf("1"), data = []; for (var i = p + 1; i < s.length - 6; i++) data.push(CH.indexOf(s[i])); var acc = 0, bits = 0, out = []; data.forEach(function (v) { acc = (acc << 5) | v; bits += 5; while (bits >= 8) { bits -= 8; out.push((acc >> bits) & 255); } }); return out.map(function (b) { return b.toString(16).padStart(2, "0"); }).join(""); } /* ---------- wallets ---------- */ function cardanoWallets() { var c = window.cardano || {}; return Object.keys(c).filter(function (k) { return c[k] && typeof c[k].enable === "function" && c[k].name; }).map(function (k) { return { key: k, name: c[k].name, icon: c[k].icon }; }); } function solProvider() { return (window.phantom && window.phantom.solana) || window.solflare || (window.backpack && window.backpack.solana) || window.solana || null; } function pickCardano() { var list = cardanoWallets(); if (!list.length) return Promise.reject(new Error("No Cardano wallet found in this browser. Install one (like Eternl or Lace) and reload.")); if (list.length === 1) return Promise.resolve(list[0].key); var box = el("div", { class: "ba-list" }); return new Promise(function (res) { var p = dialog("Which Cardano wallet?", box, [{ label: "Cancel", value: null }]); list.forEach(function (w) { box.appendChild(el("button", { type: "button", class: "ba-btn wide", text: w.name, onclick: function () { document.querySelector(".ba-dlg").remove(); res(w.key); } })); }); p.then(function (v) { if (v === null) res(null); }); }); } /* sign our sign-in message with a wallet. expectAddr: the page address that must sign (verification) */ function walletSign(chain, expectAddr) { return api("signin/nonce").then(function (n) { if (chain === "ADA") { return pickCardano().then(function (k) { if (!k) throw new Error("Cancelled."); return window.cardano[k].enable().then(function (w) { var addrP = expectAddr ? Promise.resolve(bech32hex(expectAddr)) : w.getUsedAddresses().then(function (a) { return a && a[0] ? a[0] : w.getChangeAddress(); }); return addrP.then(function (ah) { return w.signData(ah, hex(n.message)).then(function (s) { return { chain: "ADA", nonce: n.nonce, address_hex: ah, signature: s.signature, key: s.key }; }); }); }); }); } if (chain === "ETH") { var e = window.ethereum; if (!e) throw new Error("No Ethereum wallet found in this browser (like MetaMask or Rabby)."); return e.request({ method: "eth_requestAccounts" }).then(function (acc) { var a = acc[0]; if (expectAddr) { var m = acc.filter(function (x) { return x.toLowerCase() === expectAddr.toLowerCase(); })[0]; if (!m) throw new Error("Switch your wallet to the account " + expectAddr.slice(0, 6) + "…" + expectAddr.slice(-4) + " and try again."); a = m; } return e.request({ method: "personal_sign", params: ["0x" + hex(n.message), a] }).then(function (sig) { return { chain: "ETH", nonce: n.nonce, address: a, signature: sig }; }); }); } if (chain === "SOL") { var p = solProvider(); if (!p) throw new Error("No Solana wallet found in this browser (like Phantom or Solflare)."); return p.connect().then(function (r) { var pk = ((r && r.publicKey) || p.publicKey).toString(); if (expectAddr && pk !== expectAddr) throw new Error("Switch your wallet to " + expectAddr.slice(0, 4) + "…" + expectAddr.slice(-4) + " and try again."); return p.signMessage(new TextEncoder().encode(n.message), "utf8").then(function (s) { var sig = s.signature || s; return { chain: "SOL", nonce: n.nonce, address: pk, signature: b64(sig) }; }); }); } throw new Error("Unknown wallet type."); }); } /* ---------- shared form bits ---------- */ function coinRow(item, onRemove) { var sel = el("select", { "aria-label": "Coin" }, el("option", { value: "", text: "Coin…" })); CFG.coins.forEach(function (c) { sel.appendChild(el("option", { value: c.id, text: c.name + " (" + c.id + ")", selected: item && item.coin === c.id })); }); var addr = el("input", { type: "text", placeholder: "Paste the address", "aria-label": "Address", spellcheck: "false", autocomplete: "off", value: item ? item.address : "" }); var label = el("input", { type: "text", placeholder: "Label (optional), e.g. Tips", "aria-label": "Label", maxlength: "40", value: item ? (item.label || "") : "" }); var note = el("div", { class: "ba-note" }); var t; addr.addEventListener("input", function () { clearTimeout(t); t = setTimeout(function () { if (!addr.value.trim()) { note.textContent = ""; return; } api("detect", { address: addr.value }).then(function (j) { if (j.coins.length === 1) { sel.value = j.coins[0]; note.textContent = "✓ Looks like a valid " + coinName(j.coins[0]) + " address. Ends in " + addr.value.trim().slice(-6); note.className = "ba-note ok"; } else if (j.coins.length > 1) { note.textContent = "This could be " + j.coins.map(coinName).join(" or ") + ": pick the coin."; note.className = "ba-note"; } else { note.textContent = "That doesn't look like an address we know. Check for typos."; note.className = "ba-note bad"; } }).catch(function () {}); }, 350); }); var row = el("div", { class: "ba-coinrow" }, el("div", { class: "ba-row" }, sel, el("button", { type: "button", class: "ba-btn sm d", text: "Remove", "aria-label": "Remove this address", onclick: function () { row.remove(); onRemove && onRemove(); } })), addr, label, note); row.get = function () { return { coin: sel.value, address: addr.value.trim(), label: label.value.trim(), verified: item && item.verified && item.address === addr.value.trim() }; }; return row; } function linkRow(item) { var label = el("input", { type: "text", placeholder: "Label, e.g. X or YouTube", "aria-label": "Link label", maxlength: "30", value: item ? item.label : "" }); var url = el("input", { type: "url", placeholder: "https://…", "aria-label": "Link address", value: item ? item.url : "" }); var row = el("div", { class: "ba-row linkrow" }, label, url, el("button", { type: "button", class: "ba-btn sm d", text: "×", "aria-label": "Remove link", onclick: function () { row.remove(); } })); row.get = function () { return { label: label.value.trim(), url: url.value.trim() }; }; return row; } /* The owner key box. It must never be mistaken for a wallet's seed phrase, so it says plainly what it is and isn't. SOURCE_URL: where BitAddy's code can be read (the page on the site itself, until it has its own public code home). */ var SOURCE_URL = "/source/"; function keyBox(key) { var dl = el("a", { class: "ba-btn", text: "Download as a file", onclick: function () { ev("save_key", "download"); }, download: "bitaddy-owner-key.txt", href: URL.createObjectURL(new Blob(["Your BitAddy owner key\n\n" + key + "\n\nThis is NOT a seed phrase (recovery phrase). It has nothing to do with your wallet and can't touch your coins.\nIt does one thing: it lets you edit or delete your BitAddy pages at https://bitaddy.com/edit/\nKeep it private: anyone with it can edit your BitAddy pages.\n\nIf you lose it, your coins and addresses are not affected. You just can't edit the page any more,\nand a free page that nobody visits is removed after a year.\n\nBitAddy never asks for, stores, or has any access to your seed phrase.\n"], { type: "text/plain" })) }); var facts = el("ul", { class: "ba-facts" }, el("li", { class: "no" }, el("b", { text: "Not a seed phrase." }), " It has nothing to do with your wallet and can't see, move or touch your coins."), el("li", { class: "yes" }, el("b", { text: "Lost it?" }), " Your coins and addresses are not affected. You just can't edit the page any more, and a free page nobody visits is removed after a year."), el("li", { class: "no" }, el("b", { text: "BitAddy never asks for your seed phrase," }), " never stores one and can't see one. Never type yours into any website.")); if (SOURCE_URL) facts.appendChild(el("li", { class: "yes" }, "Don't take our word for it: ", el("a", { href: SOURCE_URL, target: "_blank", rel: "noopener", text: "read BitAddy's source code" }), ".")); return el("div", { class: "ba-key" }, el("p", null, el("b", { text: "Your owner key is not a seed phrase." }), " It only lets you edit or delete your BitAddy page later. It's shown once, so save it now."), el("div", { class: "ba-secret", text: key }), el("div", { class: "ba-row ba-keybtns" }, el("button", { type: "button", class: "ba-btn p", text: "Copy key", onclick: function () { ev("save_key", "copy"); copy(key, "Key copied. Save it somewhere safe."); } }), dl), facts); } /* ---------- small things kept on this device only ---------- */ function lsGet(k, d) { try { var v = localStorage.getItem(k); return v ? JSON.parse(v) : d; } catch (e) { return d; } } function lsSet(k, v) { try { if (v == null) localStorage.removeItem(k); else localStorage.setItem(k, JSON.stringify(v)); } catch (e) {} } function openOrders() { return lsGet("ba_orders", []).filter(function (o) { return o.expires * 1000 > Date.now() - 86400000; }); } function rememberOrder(o) { var l = openOrders().filter(function (x) { return x.id !== o.id; }); l.unshift({ id: o.id, secret: o.secret, label: o.label, expires: o.expires }); lsSet("ba_orders", l.slice(0, 8)); } function forgetOrder(id) { lsSet("ba_orders", openOrders().filter(function (x) { return x.id !== id; })); } function usd(x) { var n = Number(x); return "$" + (n % 1 ? n.toFixed(2) : String(n)); } function spanText(d) { return d % 365 === 0 ? (d === 365 ? " a year" : " for " + d / 365 + " years") : " for " + d + " days"; } function priceText(it) { return usd(it.usd) + (it.days ? spanText(it.days) : ", once"); } function tokenIn(text) { var m = /bt-[A-Za-z0-9_\-]{20,40}/.exec(text || ""); return m ? m[0] : ""; } function sheet(title, body) { var d = el("div", { class: "ba-dlg" }), x = el("button", { type: "button", class: "ba-btn sm", text: "Close", "aria-label": "Close" }); var box = el("div", { class: "ba-dl", role: "dialog", "aria-modal": "true", "aria-label": title }, el("div", { class: "ba-row spread" }, el("h2", { text: title, style: "margin:0" }), x), body); d.appendChild(box); document.body.appendChild(d); var s = { onclose: null, close: function () { d.remove(); document.removeEventListener("keydown", esc); s.onclose && s.onclose(); } }; function esc(e) { if (e.key === "Escape") s.close(); } document.addEventListener("keydown", esc); x.onclick = s.close; return s; } /* ---------- paying: on the spot in any coin, or from a top-up link ---------- */ function toUnits(amount, dec) { var p = String(amount).split("."), f = (p[1] || "").padEnd(dec, "0").slice(0, dec); return (p[0] + f).replace(/^0+(?=\d)/, ""); } function payUri(o) { if (!o.uri) return o.address; if (o.uri === "ethereum") return "ethereum:" + o.address + "?value=" + toUnits(o.amount, 18); return o.uri + ":" + o.address + "?amount=" + o.amount; } function coinGrid(onPick) { var g = el("div", { class: "ba-coins" }); CFG.assets.forEach(function (a) { g.appendChild(el("button", { type: "button", class: "ba-coin", "data-asset": a.id, onclick: function () { onPick(a.id, this); } }, el("b", { text: a.symbol }), el("span", { text: a.name }))); }); return g; } /* req: {kind:"item", sku, page_id|code, name} | {kind:"topup", token, usd} | {kind:"tip", usd}; what: words for the thing; price: dollars */ function payFlow(req, what, price, done) { if (!CFG.pay_on) { ev("pay_closed", payWhat(req)); dialog("Not for sale yet", "Paying isn't switched on yet. Please check back soon."); return; } var body = el("div"), s = sheet("Pay with crypto", body), stop = null; ev("pay_open", payWhat(req)); s.onclose = function () { stop && stop(); refreshOpen(); }; function finished(text) { ev("paid", payWhat(req)); body.textContent = ""; body.appendChild(el("div", { class: "ba-pay-status ok", role: "status", text: "✓ " + text })); body.appendChild(el("div", { class: "ba-row end" }, el("button", { type: "button", class: "ba-btn p", text: "Done", onclick: function () { s.close(); } }))); s.onclose = function () { refreshOpen(); done && done(); }; } function choose() { body.textContent = ""; var err = el("div", { class: "ba-err", role: "alert" }); body.appendChild(el("div", { class: "ba-sum total" }, el("span", { text: what }), el("span", { text: usd(price) }))); if (req.kind === "item") { var saved = lsGet("ba_topup", ""), tk = el("input", { type: "password", placeholder: "Paste your top-up link", "aria-label": "Top-up link", autocomplete: "off", value: saved }); var use = el("button", { type: "button", class: "ba-btn p", text: "Pay from it", onclick: function () { err.textContent = ""; var t = tokenIn(tk.value); if (!t) { err.textContent = "Paste your whole top-up link first."; return; } use.disabled = true; ev("pay_topup", payWhat(req)); api("spend", Object.assign({ token: t }, req)).then(function (j) { finished(j.result + " Your top-up link now holds $" + j.balance + "."); }).catch(function (e) { err.textContent = e.message; use.disabled = false; }); } }); body.appendChild(el("h3", { text: "From a top-up link" })); body.appendChild(el("p", { class: "ba-hint" }, "Instant, no waiting. ", el("a", { href: "/topup/", text: "What is a top-up link?" }))); body.appendChild(el("div", { class: "ba-row" }, tk, use)); body.appendChild(el("h3", { text: "Or pay now, in the coin you like" })); } else body.appendChild(el("h3", { text: "Pick the coin you want to pay with" })); body.appendChild(coinGrid(function (asset, btn) { err.textContent = ""; body.querySelectorAll(".ba-coin").forEach(function (b) { b.disabled = true; }); btn.classList.add("on"); ev("pay_coin", asset); api("order", Object.assign({ asset: asset }, req)).then(function (o) { rememberOrder(o); stop = payView(body, o, finished); }) .catch(function (e) { err.textContent = e.message; body.querySelectorAll(".ba-coin").forEach(function (b) { b.disabled = false; }); btn.classList.remove("on"); }); })); body.appendChild(el("p", { class: "ba-hint", text: "No account, no card, no email. The network fee is paid by the sender; it is smallest on Litecoin, Dogecoin, XRP, TRON, Solana and Cardano." })); body.appendChild(err); } choose(); return s; } /* the "send exactly this" screen; returns a function that stops its timers */ function payView(body, o, finished) { body.textContent = ""; var status = el("div", { class: "ba-pay-status", "aria-live": "polite", text: "Waiting for your payment…" }), left = el("b"); var steps = el("ol", { class: "ba-steps" }); steps.appendChild(el("li", null, "Send exactly ", el("b", { text: o.amount + " " + o.symbol }), o.symbol !== o.asset ? " (" + o.asset_name + ")" : "", el("div", { class: "ba-row" }, el("div", { class: "ba-secret", id: "pay-amount", text: o.amount }), el("button", { type: "button", class: "ba-btn sm", text: "Copy amount", onclick: function () { copy(o.amount, "Amount copied"); } })))); steps.appendChild(el("li", null, "To this " + o.asset_name.replace(/^USD[TC] on /, "") + " address (ends in ", el("b", { text: o.address.slice(-6) }), ")", el("div", { class: "ba-secret", id: "pay-address", text: o.address }), el("button", { type: "button", class: "ba-btn sm", text: "Copy address", onclick: function () { copy(o.address, "Address copied. Check the ending: " + o.address.slice(-6)); } }))); if (o.tag) steps.appendChild(el("li", null, "With this destination tag (some apps call it a memo)", el("div", { class: "ba-row" }, el("div", { class: "ba-secret", id: "pay-tag", text: String(o.tag) }), el("button", { type: "button", class: "ba-btn sm", text: "Copy tag", onclick: function () { copy(String(o.tag), "Tag copied"); } })))); body.appendChild(el("div", { class: "ba-sum total" }, el("span", { text: o.label }), el("span", { text: usd(o.usd) }))); body.appendChild(steps); var q = qr(payUri(o), 4); q.id = "pay-qr"; /* XRP, TRON and tokens have no QR format wallets agree on for an amount: the code holds only the address, so say so plainly */ /* Ethereum's QR has the amount in the official format (MetaMask reads it), but many wallets (Trust Wallet, for one) ignore it */ if (!o.uri || o.uri === "ethereum") body.appendChild(el("p", { class: "ba-warn-amt", role: "note", style: "border:2px solid #d97706;background:rgba(217,119,6,.1);border-radius:10px;padding:.6rem .75rem;margin:.5rem 0;font-weight:600" }, o.uri ? "Some wallets don't fill in the amount from this QR code. " : "Your wallet won't fill in the amount from this QR code. ", "Tap ", el("b", { text: "Copy amount" }), " and paste it into your wallet, then check it reads exactly " + o.amount + " before you send.")); body.appendChild(el("div", { class: "ba-row" }, q, el("p", { class: "ba-hint", style: "flex:1;min-width:150px" }, "Or scan with your wallet app. ", el("b", { text: "The exact amount is how BitAddy knows the payment is yours" }), ", so please don't round it. Sending from an exchange? Add its fee on top so the full amount arrives."))); body.appendChild(el("p", { class: "ba-hint" }, "Order " + o.id + ". Please pay within ", left, ". After you send, it shows up here in " + o.wait + ". You can close this window: your order keeps going and is listed under “Open orders”.")); body.appendChild(status); function tickLeft() { var sec = Math.max(0, o.expires - Date.now() / 1000); left.textContent = Math.ceil(sec / 60) + " min"; } function look() { api("order?id=" + encodeURIComponent(o.id) + "&s=" + encodeURIComponent(o.secret)).then(function (x) { if (x.status === "paid") { stop(); forgetOrder(o.id); finished(x.result || "Paid. Thank you!"); } else if (x.note) status.textContent = "We see your payment: " + x.note + "…"; else if (x.status === "expired") { status.textContent = "This order has closed. If you did pay, write to hello@bitaddy.com with order " + o.id + "."; stop(); forgetOrder(o.id); } else if (o.expires * 1000 < Date.now()) status.textContent = "The hour is over, but a payment sent in time still counts for a day."; }).catch(function () {}); } tickLeft(); var t1 = setInterval(tickLeft, 5000), t2 = setInterval(look, 12000); function stop() { clearInterval(t1); clearInterval(t2); } return stop; } /* "Open orders": orders this device started that aren't paid yet. Redrawn whenever a pay window closes. */ function openOrdersCard(parent, done) { var h = el("div", { class: "ba-open" }); h._done = done; parent.appendChild(h); fillOpen(h); } function refreshOpen() { document.querySelectorAll(".ba-open").forEach(fillOpen); } function fillOpen(holder) { holder.textContent = ""; var list = openOrders(), done = holder._done; if (!list.length) return; var c = el("div", { class: "ba-card" }, el("h3", { text: "Open orders" })); list.forEach(function (x) { c.appendChild(el("div", { class: "ba-item" }, el("span", { text: x.label + " · " + x.id }), el("div", { class: "ba-row" }, el("button", { type: "button", class: "ba-btn sm", text: "Show", onclick: function () { api("order?id=" + encodeURIComponent(x.id) + "&s=" + encodeURIComponent(x.secret)).then(function (o) { o.secret = x.secret; var body = el("div"), s = sheet("Pay with crypto", body), stop = null; function fin(text) { ev("paid", "open order"); body.textContent = ""; body.appendChild(el("div", { class: "ba-pay-status ok", text: "✓ " + text })); forgetOrder(o.id); s.onclose = function () { refreshOpen(); done && done(); }; } if (o.status === "paid") fin(o.result || "Paid. Thank you!"); else if (o.status === "expired") { forgetOrder(o.id); refreshOpen(); s.close(); toast("That order has closed."); } else { stop = payView(body, o, fin); s.onclose = function () { stop && stop(); }; } }).catch(function (e) { toast(e.message); forgetOrder(x.id); refreshOpen(); }); } }), el("button", { type: "button", class: "ba-btn sm", text: "Forget", onclick: function () { forgetOrder(x.id); refreshOpen(); } })))); }); holder.appendChild(c); } function buyKeep(code, done) { var it = CFG.items.keep; payFlow({ kind: "item", sku: "keep", code: code }, "Keep bitaddy.com/" + code + (it.days ? spanText(it.days) : " for good"), it.usd, done); } /* ---------- asking for a reserved name ---------- */ function requestLink(name) { return el("button", { type: "button", class: "ba-link", style: "margin-left:.4rem", text: "Request this name", onclick: function () { requestName(name); } }); } function requestName(name) { var email = el("input", { type: "text", id: "rq-email", inputmode: "email", autocomplete: "email", placeholder: "you@example.com" }); var note = el("textarea", { id: "rq-note", maxlength: "300", placeholder: "For example: it's my name, my brand or my project (optional)" }); var err = el("div", { class: "ba-err", role: "alert" }), body = el("div"); var send = el("button", { type: "button", class: "ba-btn p", text: "Send request" }); body.appendChild(el("p", null, el("b", { text: "bitaddy.com/" + name }), " is reserved, so nobody can simply take it. If you think it should be yours, ask for it and a person will look at it.")); body.appendChild(el("label", { for: "rq-email", text: "Your email, so we can answer" })); body.appendChild(email); body.appendChild(el("label", { for: "rq-note", text: "Why should it be yours?" })); body.appendChild(note); body.appendChild(el("p", { class: "ba-hint", text: "Your email is used only to answer this request, and is deleted afterwards. BitAddy needs no email for anything else." })); body.appendChild(err); body.appendChild(el("div", { class: "ba-row end" }, send)); var s = sheet("Request this name", body); send.onclick = function () { err.textContent = ""; send.disabled = true; api("name-request", { name: name, email: email.value.trim(), note: note.value }).then(function () { ev("name_request"); body.textContent = ""; body.appendChild(el("div", { class: "ba-pay-status ok", role: "status", text: "✓ Request sent. We'll email you about bitaddy.com/" + name + "." })); body.appendChild(el("div", { class: "ba-row end" }, el("button", { type: "button", class: "ba-btn p", text: "Done", onclick: function () { s.close(); } }))); }).catch(function (e) { err.textContent = e.message; send.disabled = false; }); }; setTimeout(function () { email.focus(); }, 40); } /* ---------- HOME: short link / page ---------- */ function home() { ROOT.textContent = ""; var tabs = el("div", { class: "ba-tabs", role: "tablist" }); var body = el("div"); [["link", "Short link"], ["page", "Page for all my coins"]].forEach(function (t, i) { tabs.appendChild(el("button", { type: "button", role: "tab", class: i ? "" : "on", text: t[1], onclick: function () { tabs.querySelectorAll("button").forEach(function (b) { b.classList.remove("on"); }); this.classList.add("on"); if (t[0] === "page") ev("tab_page", "", "tab_page"); (t[0] === "page" ? makePage : makeLink)(body); } })); }); ROOT.appendChild(tabs); ROOT.appendChild(body); makeLink(body); var sp = document.getElementById("ba-sponsor"); if (sp && CFG.sponsor) { sp.textContent = ""; sp.appendChild(el("span", { text: "Sponsor" })); sp.appendChild(el("a", { href: CFG.sponsor.url, rel: "sponsored nofollow noopener", target: "_blank", text: CFG.sponsor.text })); sp.hidden = false; } } function makePage(body) { body.textContent = ""; var L = CFG.limits, maxCoins = L.free_coins, maxLinks = L.free_links; var name = el("input", { type: "text", id: "bn", placeholder: "yourname", autocapitalize: "none", spellcheck: "false", maxlength: "30", autocomplete: "off" }); var avail = el("div", { class: "ba-note", "aria-live": "polite" }); var title = el("input", { type: "text", id: "bt", placeholder: "Your name or project", maxlength: "60" }); var bio = el("textarea", { id: "bb", placeholder: "A short line about you (optional)", maxlength: "280" }); var coinsBox = el("div"), linksBox = el("div"), err = el("div", { class: "ba-err", role: "alert" }); var t; name.addEventListener("input", function () { ev("page_start", "", "page_start"); name.value = name.value.toLowerCase().replace(/[^a-z0-9-]/g, ""); clearTimeout(t); t = setTimeout(function () { if (!name.value) { avail.textContent = ""; return; } api("check-name", { name: name.value }).then(function (j) { if (j.ok && j.short) { avail.textContent = "bitaddy.com/" + name.value + " is a short name, a paid extra (" + usd(j.usd) + (j.days ? " a year" : " once") + "). Make your page with a longer name first, then switch to it in My links."; avail.className = "ba-note"; } else { avail.textContent = j.ok ? "✓ bitaddy.com/" + name.value + " is free" : j.why; avail.className = "ba-note " + (j.ok ? "ok" : "bad"); if (j.request) avail.appendChild(requestLink(name.value)); } }); }, 300); }); function addCoin(item) { if (coinsBox.children.length >= maxCoins) { toast("Up to " + maxCoins + " addresses on a free page (" + L.pro_coins + " with Pro)."); return; } coinsBox.appendChild(coinRow(item)); } function addLink() { if (linksBox.children.length >= maxLinks) { toast("Up to " + maxLinks + " links on a free page (" + L.pro_links + " with Pro)."); return; } linksBox.appendChild(linkRow()); } addCoin(); var go = el("button", { type: "button", class: "ba-btn p big", text: "Create my page" }); go.onclick = function () { err.textContent = ""; var cl = Array.prototype.map.call(coinsBox.children, function (r) { return r.get(); }).filter(function (x) { return x.address; }); var ll = Array.prototype.map.call(linksBox.children, function (r) { return r.get(); }).filter(function (x) { return x.url; }); if (!name.value) { err.textContent = "Pick a name for your page."; ev("problem", "page: " + err.textContent); return; } if (!cl.length) { err.textContent = "Add at least one address."; ev("problem", "page: " + err.textContent); return; } go.disabled = true; api("page/create", { name: name.value, title: title.value, bio: bio.value, coins: cl, links: ll }).then(function (j) { ev("page_made", cl.map(function (x) { return x.coin; }).join(",")); created(body, j); }) .catch(function (e) { err.textContent = e.message; ev("problem", "page: " + e.message); go.disabled = false; }); }; body.appendChild(el("div", { class: "ba-card" }, el("label", { for: "bn", text: "Your page address" }), el("div", { class: "ba-prefix" }, el("span", { text: "bitaddy.com/" }), name), avail, el("p", { class: "ba-hint", text: L.min_free_name + " to 30 lowercase letters, numbers or dashes." }), el("label", { for: "bt", text: "Display name" }), title, el("label", { for: "bb", text: "Short bio" }), bio, el("h3", { text: "Your addresses" }), coinsBox, el("button", { type: "button", class: "ba-btn sm", text: "+ Add another address", onclick: function () { addCoin(); } }), el("h3", { text: "Links (optional)" }), linksBox, el("button", { type: "button", class: "ba-btn sm", text: "+ Add a link", onclick: addLink }), el("p", { class: "ba-hint", text: ME && ME.signed_in ? "This page joins the ones your owner key or wallet already opens." : "No sign-up. You'll get an owner key to edit the page later." }), err, go)); } function created(body, j) { body.textContent = ""; var url = location.origin + "/" + j.name; var c = el("div", { class: "ba-card" }, el("h2", { text: "🎉 Your page is ready" }), el("div", { class: "ba-big" }, el("a", { href: "/" + j.name, text: "bitaddy.com/" + j.name })), el("div", { class: "ba-row" }, el("button", { type: "button", class: "ba-btn p", text: "Copy link", onclick: function () { ev("copy_link", "page"); copy(url); } }), shareBtn(url, "bitaddy.com/" + j.name, "page"), el("a", { class: "ba-btn", href: "/" + j.name, text: "Open my page", onclick: function () { ev("open_made", "page"); } })), el("div", { class: "ba-row" }, qrSaveBtn(url + "?q=1", "bitaddy.com/" + j.name, "All my crypto addresses", "bitaddy-" + j.name, "page"))); if (j.key) c.appendChild(keyBox(j.key)); c.appendChild(el("p", { class: "ba-hint" }, "Edit it any time under ", el("a", { href: "/edit/", text: "My links" }), ". There you can also add your wallet as a second way in, verify your addresses, and add extras like a short name or your picture.")); body.appendChild(c); api("me").then(function (m) { ME = m; }); } function makeLink(body) { body.textContent = ""; var addr = el("input", { type: "text", id: "qa", class: "ba-in-big", placeholder: "Paste any crypto address", spellcheck: "false", autocomplete: "off", autocapitalize: "none" }); var label = el("input", { type: "text", id: "ql", placeholder: "Label (optional), e.g. Tips", maxlength: "40" }); var chips = el("div", { class: "ba-chips" }), note = el("div", { class: "ba-note" }), err = el("div", { class: "ba-err", role: "alert" }), out = el("div"); var coin = "", t; addr.addEventListener("input", function () { ev("link_start", "", "link_start"); clearTimeout(t); coin = ""; chips.textContent = ""; t = setTimeout(function () { if (!addr.value.trim()) { note.textContent = ""; return; } api("detect", { address: addr.value }).then(function (j) { if (j.coins.length === 1) { coin = j.coins[0]; note.textContent = "✓ " + coinName(coin) + " address · ends in " + addr.value.trim().slice(-6); note.className = "ba-note ok"; } else if (j.coins.length > 1) { note.textContent = "Which coin is this for?"; note.className = "ba-note"; j.coins.forEach(function (c) { chips.appendChild(el("button", { type: "button", class: "ba-btn sm", text: coinName(c), onclick: function () { coin = c; chips.querySelectorAll("button").forEach(function (b) { b.classList.remove("p"); }); this.classList.add("p"); } })); }); } else { note.textContent = "That doesn't look like an address we know. Check for typos."; note.className = "ba-note bad"; } }); }, 300); }); var go = el("button", { type: "button", class: "ba-btn p big", text: "Make my short link" }); go.onclick = function () { err.textContent = ""; go.disabled = true; api("link", { address: addr.value, coin: coin, label: label.value }).then(function (j) { ev("link_made", coin || "other"); var url = location.origin + "/" + j.code, K = CFG.items.keep; out.textContent = ""; out.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "Your short link" }), el("div", { class: "ba-big" }, el("a", { href: "/" + j.code, text: "bitaddy.com/" + j.code })), el("div", { class: "ba-row" }, el("button", { type: "button", class: "ba-btn p", text: "Copy link", onclick: function () { ev("copy_link", "link"); copy(url); } }), shareBtn(url, "bitaddy.com/" + j.code, "link"), el("a", { class: "ba-btn", href: "/" + j.code, text: "Open it", onclick: function () { ev("open_made", "link"); } })), qr(url + "?q=1", 5), el("div", { class: "ba-row" }, qrSaveBtn(url + "?q=1", "bitaddy.com/" + j.code, (coin ? coinName(coin) + " · " : "") + "ends in " + addr.value.trim().slice(-6), "bitaddy-" + j.code, "link")), el("p", { class: "ba-hint", text: "Free. It keeps working as long as it's used: a link nobody visits for 180 days expires. Same address and label = same link." }), K && K.on && CFG.pay_on ? el("p", { class: "ba-hint" }, K.days ? "Want it kept even if nobody uses it for a while? " : "Want it to never expire? ", el("button", { type: "button", class: "ba-link", text: "Keep it" + (K.days ? spanText(K.days) : " for good") + " for " + usd(K.usd), onclick: function () { buyKeep(j.code); } }), ".") : null)); go.disabled = false; out.scrollIntoView({ behavior: "smooth", block: "nearest" }); }).catch(function (e) { err.textContent = e.message; ev("problem", "link: " + e.message); go.disabled = false; }); }; body.appendChild(el("div", { class: "ba-card" }, el("label", { for: "qa", text: "Address" }), addr, note, chips, el("label", { for: "ql", text: "Label" }), label, err, go)); body.appendChild(out); } /* ---------- MY LINKS: open with the owner key or a wallet, then manage ---------- */ function edit() { ROOT.textContent = ""; if (!ME || !ME.signed_in) return signIn(); dashboard(); } function signIn() { var err = el("div", { class: "ba-err", role: "alert" }); var key = el("input", { type: "password", id: "ok", placeholder: "ba-…", autocomplete: "off", spellcheck: "false" }); var c = el("div", { class: "ba-card" }, el("h2", { text: "Open your pages and links" }), el("p", { class: "ba-hint", text: "BitAddy has no accounts, no email and no passwords. Your pages open with the owner key you saved, or with your wallet." }), el("h3", { text: "With your owner key" }), el("label", { for: "ok", text: "Owner key" }), key, el("button", { type: "button", class: "ba-btn p", style: "margin-top:.5rem", text: "Open", onclick: function () { err.textContent = ""; api("signin/key", { key: key.value.trim() }).then(function () { ev("signin", "key"); return reload(); }).catch(function (e) { err.textContent = e.message; }); } }), el("h3", { text: "With your wallet" }), el("p", { class: "ba-hint", text: "Your wallet signs a short message. It costs nothing and moves no funds." }), el("div", { class: "ba-row" }, ["ADA", "ETH", "SOL"].map(function (ch) { return el("button", { type: "button", class: "ba-btn", text: { ADA: "Cardano", ETH: "Ethereum", SOL: "Solana" }[ch], onclick: function () { err.textContent = ""; walletSign(ch).then(function (s) { return api("signin/wallet", s); }).then(function () { ev("signin", ch); return reload(); }).catch(function (e) { err.textContent = e.message; }); } }); }))); c.appendChild(err); c.appendChild(el("p", { class: "ba-hint" }, "Nothing yet? ", el("a", { href: "/", text: "Make a link or a page" }), ".")); ROOT.appendChild(c); openOrdersCard(ROOT); alertsCard(ROOT); reqCard(ROOT); } function reload() { return api("me").then(function (m) { ME = m; edit(); }); } /* payment alerts saved on this device (alert links), with their state; shown in My links */ function alertsCard(parent) { var saved = alertsSaved(); var c = el("div", { class: "ba-card" }, el("div", { class: "ba-row spread" }, el("h3", { text: "Payment alerts", style: "margin:0" }), el("a", { class: "ba-btn sm", href: "/alerts/", text: "+ New alert" }))); if (!saved.length) { c.appendChild(el("p", { class: "ba-hint", text: "No payment alerts on this device. An alert sends you a message on Telegram, Discord or a webhook when an address is paid." })); parent.appendChild(c); return; } saved.forEach(function (x) { var sub = el("div", { class: "ba-hint", text: "Checking…" }), pill = el("span"); c.appendChild(el("div", { class: "ba-item" }, el("div", null, el("a", { href: "/alerts/#" + x.t, text: x.label || "Payment alert" }), pill, sub), el("div", { class: "ba-row" }, el("a", { class: "ba-btn sm", href: "/alerts/#" + x.t, text: "Open" })))); api("alert/get", { token: x.t }).then(function (a) { pill.replaceWith(el("span", { class: "ba-pill " + (a.active ? "ok" : "bad"), text: a.active ? "on" : a.ended ? "ended" : "not started" })); sub.textContent = a.coin_name + " · ends in " + a.address.slice(-6) + " · " + ({ telegram: "Telegram", discord: "Discord", webhook: "webhook" }[a.channel]) + (a.connected ? "" : " (not connected yet)") + (a.active ? (a.until ? " · until " + fmtDate(a.until) : "") : "") + " · " + a.sent + " message" + (a.sent === 1 ? "" : "s") + " sent"; }).catch(function () { sub.textContent = "This alert no longer exists."; pill.replaceWith(el("span", { class: "ba-pill bad", text: "gone" })); }); }); c.appendChild(el("p", { class: "ba-hint", text: "Alerts are kept by their private alert links, so they show on the device where you made or opened them." })); parent.appendChild(c); } function dashboard() { ROOT.appendChild(el("div", { class: "ba-row spread" }, el("h2", { text: "My links", style: "margin:0" }), el("button", { type: "button", class: "ba-btn sm", text: "Close on this device", onclick: function () { api("signout", {}).then(function () { ME = null; edit(); }); } }))); openOrdersCard(ROOT, reload); var pc = el("div", { class: "ba-card" }, el("div", { class: "ba-row spread" }, el("h3", { text: "Pages", style: "margin:0" }), el("a", { class: "ba-btn sm", href: "/", text: "+ New page" }))); if (!ME.pages.length) pc.appendChild(el("p", { class: "ba-hint", text: "No pages yet." })); ME.pages.forEach(function (p) { var sub = p.coins.length + " address" + (p.coins.length === 1 ? "" : "es") + " · " + p.views + " views · " + p.scans + " QR scans"; sub += p.pro ? (p.pro_until ? " · Pro until " + fmtDate(p.pro_until) : " · Pro for good") : p.expired ? " · expired: nobody visited for a year. Bring it back before " + fmtDate(p.deleted_at) + ", or it is removed." : " · free: expires if nobody visits for a year"; if (p.short && p.name_until) sub += p.name_until * 1000 > Date.now() ? " · short name until " + fmtDate(p.name_until) : " · short name ended: renew before " + fmtDate(p.name_back); pc.appendChild(el("div", { class: "ba-item" }, el("div", null, el("a", { href: "/" + p.name, text: "bitaddy.com/" + p.name }), p.pro ? el("span", { class: "ba-pill ok", text: "Pro" }) : null, p.expired ? el("span", { class: "ba-pill bad", text: "expired" }) : null, p.hidden ? el("span", { class: "ba-pill bad", text: "hidden: under review" }) : null, el("div", { class: "ba-hint", text: sub })), el("div", { class: "ba-row" }, !p.expired && !p.hidden ? shareItemBtn(location.origin + "/" + p.name, "bitaddy.com/" + p.name, "All my crypto addresses", "bitaddy-" + p.name) : null, p.pro && !p.expired && !p.hidden ? cardsBtn(p) : null, p.expired ? el("button", { type: "button", class: "ba-btn sm p", text: "Bring it back", onclick: function () { api("revive", { id: p.id }).then(function () { toast("It's back"); reload(); }).catch(function (e) { toast(e.message); }); } }) : null, el("button", { type: "button", class: "ba-btn sm" + (p.expired ? "" : " p"), text: "Edit", onclick: function () { pageEditor(p); } }), el("button", { type: "button", class: "ba-btn sm d", text: "Delete", onclick: function () { confirmBox("Delete bitaddy.com/" + p.name + "?", "The page disappears right away, the name becomes free for others" + (p.pro || p.short ? ", and its paid extras end with it." : "."), "Delete", true).then(function (ok) { if (ok) api("page/delete", { id: p.id }).then(reload); }); } })))); }); ROOT.appendChild(pc); if (ME.links.length) { var lc = el("div", { class: "ba-card" }, el("h3", { text: "Short links" })), K = CFG.items.keep; ME.links.forEach(function (l) { lc.appendChild(el("div", { class: "ba-item" }, el("div", null, el("a", { href: "/" + l.code, text: "bitaddy.com/" + l.code }), l.keep ? el("span", { class: "ba-pill ok", text: l.keep_until ? "kept until " + fmtDate(l.keep_until) : "kept for good" }) : null, l.expired ? el("span", { class: "ba-pill bad", text: "expired" }) : null, el("div", { class: "ba-hint", text: coinName(l.coin) + " · ends in " + l.address.slice(-6) + " · " + l.views + " views" + (l.keep ? "" : l.expired ? " · nobody used it for 180 days. Bring it back before " + fmtDate(l.deleted_at) + ", or it is removed." : " · free: expires if nobody uses it for 180 days") })), el("div", { class: "ba-row" }, !l.expired ? shareItemBtn(location.origin + "/" + l.code, "bitaddy.com/" + l.code, coinName(l.coin) + " · ends in " + l.address.slice(-6), "bitaddy-" + l.code) : null, l.expired ? el("button", { type: "button", class: "ba-btn sm p", text: "Bring it back", onclick: function () { api("revive", { code: l.code }).then(function () { toast("It's back"); reload(); }).catch(function (e) { toast(e.message); }); } }) : null, !l.keep && K && K.on && CFG.pay_on ? el("button", { type: "button", class: "ba-btn sm", text: "Keep · " + usd(K.usd), onclick: function () { buyKeep(l.code, reload); } }) : null, el("button", { type: "button", class: "ba-btn sm d", text: "Delete", onclick: function () { confirmBox("Delete this link?", "bitaddy.com/" + l.code + " stops working.", "Delete", true).then(function (ok) { if (ok) api("link/delete", { code: l.code }).then(reload); }); } })))); }); ROOT.appendChild(lc); } alertsCard(ROOT); reqCard(ROOT); identsCard(); } function identsCard() { var c = el("div", { class: "ba-card" }, el("h3", { text: "Ways to open My links" }), el("p", { class: "ba-hint", text: "Add more than one, so you can't get locked out. There is no email reset: nobody but you can open your pages." })); ME.idents.forEach(function (i) { c.appendChild(el("div", { class: "ba-item" }, el("span", { text: i.kind === "key" ? "Owner key" : (i.label || "Wallet") + ": " + i.value.split(":")[1].slice(0, 10) + "…" + i.value.slice(-6) }), ME.idents.length > 1 ? el("button", { type: "button", class: "ba-btn sm d", text: "Remove", onclick: function () { confirmBox("Remove this way in?", "You won't be able to use it to open your pages any more.", "Remove", true).then(function (ok) { if (ok) api("ident/remove", { kind: i.kind, value: i.value }).then(reload).catch(function (e) { toast(e.message); }); }); } }) : null)); }); var err = el("div", { class: "ba-err" }); c.appendChild(el("div", { class: "ba-row" }, ["ADA", "ETH", "SOL"].map(function (ch) { return el("button", { type: "button", class: "ba-btn sm", text: "+ " + { ADA: "Cardano", ETH: "Ethereum", SOL: "Solana" }[ch] + " wallet", onclick: function () { err.textContent = ""; walletSign(ch).then(function (s) { s.link = true; return api("signin/wallet", s); }).then(function () { toast("Wallet added"); reload(); }).catch(function (e) { err.textContent = e.message; }); } }); }), el("button", { type: "button", class: "ba-btn sm", text: "New owner key", onclick: function () { confirmBox("Make a new owner key?", "Any old owner key stops working.", "Make key").then(function (ok) { if (ok) api("newkey", {}).then(function (j) { dialog("Your new owner key", keyBox(j.key), [{ label: "I saved it", kind: "p", value: 1 }]).then(reload); }); }); } }))); c.appendChild(err); ROOT.appendChild(c); } function freshPage(id) { return api("me").then(function (m) { ME = m; return m.pages.filter(function (x) { return x.id === id; })[0]; }); } function pageEditor(p) { ROOT.textContent = ""; var pro = p.pro, L = CFG.limits, I = CFG.items; var maxCoins = pro ? L.pro_coins : L.free_coins, maxLinks = pro ? L.pro_links : L.free_links; var title = el("input", { type: "text", id: "et", maxlength: "60", value: p.title || "" }); var bio = el("textarea", { id: "eb", maxlength: "280" }); bio.value = p.bio || ""; var coinsBox = el("div"), linksBox = el("div"), err = el("div", { class: "ba-err", role: "alert" }); function again() { return freshPage(p.id).then(function (np) { if (np) pageEditor(np); else reload(); }); } p.coins.forEach(function (c, i) { var r = coinRow(c); if (c.verified) r.insertBefore(el("span", { class: "ba-pill ok", text: "✓ Verified" }), r.firstChild.nextSibling); else if (["ADA", "ETH", "SOL"].indexOf(c.coin) >= 0) r.appendChild(el("button", { type: "button", class: "ba-btn sm", text: "Verify with my wallet", onclick: function () { err.textContent = ""; walletSign(c.coin, c.address).then(function (s) { s.page_id = p.id; s.index = i; return api("verify/address", s); }).then(function () { toast("Verified ✓"); return again(); }).catch(function (e) { err.textContent = e.message; }); } })); coinsBox.appendChild(r); }); p.links.forEach(function (l) { linksBox.appendChild(linkRow(l)); }); var theme = el("select", { id: "eth", disabled: !pro }); Object.keys(CFG.themes).forEach(function (k) { theme.appendChild(el("option", { value: k, text: k.charAt(0).toUpperCase() + k.slice(1), selected: (p.theme || "violet") === k })); }); var avatar = p.avatar, avBox = el("div", { class: "ba-row" }); var file = el("input", { type: "file", accept: "image/png,image/jpeg,image/webp", hidden: true }); function drawAv() { avBox.textContent = ""; if (avatar) avBox.appendChild(el("img", { src: "/_b/img/" + avatar, alt: "", class: "ba-av" })); avBox.appendChild(el("button", { type: "button", class: "ba-btn sm", text: avatar ? "Change picture" : "Add a picture", disabled: !pro, onclick: function () { file.click(); } })); if (avatar) avBox.appendChild(el("button", { type: "button", class: "ba-btn sm d", text: "Remove", onclick: function () { avatar = null; drawAv(); } })); } file.onchange = function () { var f = file.files[0]; if (!f) return; var r = new FileReader(); r.onload = function () { api("avatar", { page_id: p.id, data: String(r.result).split(",")[1], type: f.type }).then(function (j) { avatar = j.avatar; drawAv(); }).catch(function (e) { toast(e.message); }); }; r.readAsDataURL(f); }; drawAv(); var save = el("button", { type: "button", class: "ba-btn p big", text: "Save changes", onclick: function () { err.textContent = ""; var cl = Array.prototype.map.call(coinsBox.children, function (r) { return r.get(); }).filter(function (x) { return x.address; }); var ll = Array.prototype.map.call(linksBox.children, function (r) { return r.get(); }).filter(function (x) { return x.url; }); var body = { id: p.id, title: title.value, bio: bio.value, coins: cl, links: ll }; if (pro) { body.theme = theme.value; body.avatar = avatar; } api("page/save", body).then(function () { toast("Saved"); return reload(); }).catch(function (e) { err.textContent = e.message; }); } }); var rename = el("button", { type: "button", class: "ba-btn sm", text: "Change address", onclick: function () { var i = el("input", { type: "text", "aria-label": "New name", value: p.short ? (p.free_name || "") : p.name }); dialog("Change bitaddy.com/" + p.name, el("div", null, el("p", { class: "ba-hint", text: "The old address stops working and becomes free for others." + (p.short ? " This page gives up its paid short name." : "") + " For a 3 or 4 letter name, use Extras below." }), i), [{ label: "Cancel", value: null }, { label: "Change", kind: "p", value: 1 }]).then(function (v) { if (v) api("page/rename", { id: p.id, name: i.value.toLowerCase() }).then(function () { toast("Changed"); reload(); }).catch(function (e) { toast(e.message); }); }); } }); ROOT.appendChild(el("div", { class: "ba-card" }, el("div", { class: "ba-row spread" }, el("h2", { text: "bitaddy.com/" + p.name, style: "margin:0" }), el("div", { class: "ba-row" }, el("a", { class: "ba-btn sm", href: "/" + p.name, target: "_blank", rel: "noopener", text: "View ↗" }), rename)), el("label", { for: "et", text: "Display name" }), title, el("label", { for: "eb", text: "Short bio" }), bio, el("h3", { text: "Addresses" }), el("p", { class: "ba-hint", text: "Verify Cardano, Ethereum and Solana addresses by signing with that wallet: visitors then see ✓ Verified. Free." }), coinsBox, el("button", { type: "button", class: "ba-btn sm", text: "+ Add another address", onclick: function () { if (coinsBox.children.length >= maxCoins) return toast("Up to " + maxCoins + " addresses" + (pro ? "." : " on a free page (" + L.pro_coins + " with Pro).")); coinsBox.appendChild(coinRow()); } }), el("h3", { text: "Links" }), linksBox, el("button", { type: "button", class: "ba-btn sm", text: "+ Add a link", onclick: function () { if (linksBox.children.length >= maxLinks) return toast("Up to " + maxLinks + " links" + (pro ? "." : " on a free page (" + L.pro_links + " with Pro).")); linksBox.appendChild(linkRow()); } }), el("h3", { text: "Look" + (pro ? "" : " (comes with Pro)") }), el("label", { for: "eth", text: "Colour" }), theme, el("label", { text: "Picture" }), avBox, file, err, el("div", { class: "ba-row" }, save, el("button", { type: "button", class: "ba-btn", text: "Back", onclick: function () { reload(); } })))); /* extras for this page */ var x = el("div", { class: "ba-card hi", id: "ba-extras" }, el("h2", { text: "Extras for this page" }), el("p", { class: "ba-hint", text: "Paid in crypto, for this page only. No account, no card, no email." })); if (I.pro && (I.pro.on || pro)) { var st = pro ? (p.pro_until ? "On until " + fmtDate(p.pro_until) : "On for good") : (p.pro_until ? "Ended " + fmtDate(p.pro_until) : ""); x.appendChild(el("div", { class: "ba-extra" }, el("div", { style: "flex:1;min-width:200px" }, el("h4", null, "Pro page", st ? el("span", { class: "ba-pill " + (pro ? "ok" : "bad"), text: st }) : null), el("p", { text: "Your picture and colour, up to " + L.pro_coins + " addresses and " + L.pro_links + " links, day-by-day visit counts, no sponsor line, and the page never expires." })), I.pro.on && !(pro && !p.pro_until) ? el("div", { class: "ba-row" }, el("span", { class: "pr", text: priceText(I.pro) }), el("button", { type: "button", class: "ba-btn p", text: pro ? "Add time" : "Get Pro", onclick: function () { payFlow({ kind: "item", sku: "pro", page_id: p.id }, "Pro page: bitaddy.com/" + p.name, I.pro.usd, again); } })) : null)); } if ((I.name3 && I.name3.on) || (I.name4 && I.name4.on) || p.short) { var nm = el("input", { type: "text", placeholder: "e.g. sam", maxlength: "4", autocapitalize: "none", spellcheck: "false", "aria-label": "Short name", style: "max-width:9rem" }); var nnote = el("div", { class: "ba-note", "aria-live": "polite" }), nbuy = el("button", { type: "button", class: "ba-btn p", text: "Get it", disabled: true }), found = null, nt; nm.addEventListener("input", function () { nm.value = nm.value.toLowerCase().replace(/[^a-z0-9-]/g, ""); nbuy.disabled = true; found = null; clearTimeout(nt); nt = setTimeout(function () { if (!nm.value) { nnote.textContent = ""; return; } api("check-name", { name: nm.value, page_id: p.id }).then(function (j) { if (j.ok && j.short) { found = j; nnote.textContent = "✓ bitaddy.com/" + nm.value + " is free to take: " + usd(j.usd) + (j.days ? spanText(j.days) : ", once"); nnote.className = "ba-note ok"; nbuy.disabled = false; } else { nnote.textContent = j.ok ? "That one is long enough to be free: use “Change address” above." : j.why; nnote.className = "ba-note " + (j.ok ? "" : "bad"); if (j.request) nnote.appendChild(requestLink(nm.value)); } }); }, 300); }); nbuy.onclick = function () { if (found) payFlow({ kind: "item", sku: "name", name: nm.value, page_id: p.id }, "Short name: bitaddy.com/" + nm.value, found.usd, again); }; var cur = null; if (p.short && p.name_until != null) { var live = !p.name_until || p.name_until * 1000 > Date.now(), sk = p.name.length <= 3 ? I.name3 : I.name4; cur = el("p", null, el("b", { text: "bitaddy.com/" + p.name }), el("span", { class: "ba-pill " + (live ? "ok" : "bad"), text: !p.name_until ? "yours for good" : live ? "yours until " + fmtDate(p.name_until) : "ended: renew before " + fmtDate(p.name_back) }), p.name_until && sk && sk.on ? el("button", { type: "button", class: "ba-btn sm", style: "margin-left:.5rem", text: "Add time · " + usd(sk.usd), onclick: function () { payFlow({ kind: "item", sku: "name", name: p.name, page_id: p.id }, "Short name: bitaddy.com/" + p.name, sk.usd, again); } }) : null); } x.appendChild(el("div", { class: "ba-extra" }, el("div", { style: "flex:1;min-width:200px" }, el("h4", { text: "Short name" }), el("p", { text: "A 3 or 4 letter address. Your current address keeps working and stays yours." + (I.name3 && I.name4 ? " 4 letters " + priceText(I.name4) + ", 3 letters " + priceText(I.name3) + "." : "") }), cur, el("div", { class: "ba-row" }, el("div", { class: "ba-prefix", style: "flex:0 1 auto" }, el("span", { text: "bitaddy.com/" }), nm), nbuy), nnote))); } ROOT.appendChild(x); if (pro) { var sc = el("div", { class: "ba-card" }, el("h3", { text: "Visits, last 30 days" })); ROOT.appendChild(sc); api("stats?page=" + p.id).then(function (j) { var v = 0, s = 0, max = 1; j.rows.forEach(function (r) { v += r.views; s += r.scans; max = Math.max(max, r.views + r.scans); }); sc.appendChild(el("p", null, el("b", { text: String(v) }), " views · ", el("b", { text: String(s) }), " QR scans")); if (j.rows.length) { var bars = el("div", { class: "ba-bars", role: "img", "aria-label": v + " views and " + s + " QR scans in the last 30 days" }); j.rows.forEach(function (r) { bars.appendChild(el("i", { style: "height:" + Math.max(4, Math.round((r.views + r.scans) / max * 100)) + "%", title: r.day + ": " + r.views + " views, " + r.scans + " scans" })); }); sc.appendChild(bars); } else sc.appendChild(el("p", { class: "ba-hint", text: "No visits yet. Share your link!" })); }).catch(function () {}); } } /* ---------- FREE & PAID ---------- */ function pricing() { ROOT.textContent = ""; var L = CFG.limits, I = CFG.items; openOrdersCard(ROOT); ROOT.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "Free, for everyone" }), el("ul", { class: "ba-ul" }, el("li", { text: "Short links and QR codes for Bitcoin, Ethereum, Cardano, Solana, Litecoin, Dogecoin, XRP and TRON addresses" }), el("li", { text: "Your own page at bitaddy.com/yourname (names of " + L.min_free_name + " letters or more), with up to " + L.free_coins + " addresses and " + L.free_links + " links" }), el("li", { text: "Typo checks on every address, a big “check the ending” box, and reporting pages that look wrong" }), el("li", { text: "The ✓ Verified tick: prove an address is yours by signing with its wallet" }), el("li", { text: "Links that ask for an exact amount" }), el("li", { text: "Editing any time with your owner key or wallet" })), el("p", { class: "ba-hint", text: "Free links and pages keep working as long as they are used. A short link nobody visits for " + CFG.idle.link_days + " days, or a page nobody visits for a year, expires: it stops working and says so. It can be brought back for " + CFG.idle.keep_days + " days, and is removed after that." }), el("a", { class: "ba-btn p", href: "/", text: "Make a link or a page" }))); var x = el("div", { class: "ba-card hi" }, el("h2", { text: "Extras" }), el("p", { class: "ba-hint", text: "Each extra belongs to one page or one link, never to a person. So there is no account, no card and no email: you pay in crypto and it switches on." })); function row(h, text, price, btn) { x.appendChild(el("div", { class: "ba-extra" }, el("div", { style: "flex:1;min-width:200px" }, el("h4", { text: h }), el("p", { text: text })), el("div", { class: "ba-row" }, el("span", { class: "pr", text: price }), btn))); } if (I.pro && I.pro.on) row("Pro page", "Your picture and colour, up to " + L.pro_coins + " addresses and " + L.pro_links + " links, day-by-day visit and QR-scan counts, printable QR cards, no sponsor line, and the page never expires while Pro lasts.", priceText(I.pro), el("a", { class: "ba-btn", href: "/edit/", text: "Add to my page" })); if (I.name4 && I.name4.on) row("4-letter name", "A short page address like bitaddy.com/abcd.", priceText(I.name4), el("a", { class: "ba-btn", href: "/edit/", text: "Add to my page" })); if (I.name3 && I.name3.on) row("3-letter name", "A very short page address like bitaddy.com/sam. There are only so many.", priceText(I.name3), el("a", { class: "ba-btn", href: "/edit/", text: "Add to my page" })); if (I.keep && I.keep.on) { var kc = el("input", { type: "text", placeholder: "bitaddy.com/aB3x9Q", "aria-label": "The short link to keep", style: "max-width:13rem", id: "keep-code", value: (new URLSearchParams(location.search).get("keep") || "") }); row("Keep a short link", (I.keep.days ? "The link doesn't expire for" + spanText(I.keep.days).replace(/^ for/, "") + ", used or not." : "The link never expires, used or not.") + " Anyone can pay this for any link, so you can also do it for a friend. It also brings an expired link back.", priceText(I.keep), el("div", { class: "ba-row" }, kc, el("button", { type: "button", class: "ba-btn", text: "Keep it", onclick: function () { var m = /([A-Za-z0-9]{6})\/?$/.exec(kc.value.trim()); if (!m) return toast("Type the short link, like bitaddy.com/aB3x9Q"); buyKeep(m[1]); } }))); } if (I.alert && I.alert.on) row("Payment alerts", "A message on Telegram, in Discord or to your own server when one address receives a payment. Also watches USDT and USDC on that network. Try a free test first.", priceText(I.alert), el("a", { class: "ba-btn", href: "/alerts/", text: "Set up an alert" })); x.appendChild(el("p", { class: "ba-hint", text: "When paid time ends nothing is deleted: the extra simply switches off, and a short name waits 30 days for you before it goes back. BitAddy can't remind you (it has no way to reach you), so the end date is always shown in My links. Extras last as long as BitAddy runs: if BitAddy ever has to close, it will say so on this site at least 90 days before, so you can save your page and link details." })); ROOT.appendChild(x); var how = el("div", { class: "ba-card" }, el("h2", { text: "How paying works" }), el("ol", { class: "ba-steps" }, el("li", { text: "Pick the extra, then the coin you want to pay with." }), el("li", { text: "Send the exact amount shown to the address shown, from any wallet or exchange." }), el("li", { text: "BitAddy sees it on the blockchain and switches your extra on by itself, usually within minutes." })), el("h3", { text: "You can pay with" }), el("div", { class: "ba-chips" }, CFG.assets.length ? CFG.assets.map(function (a) { return el("span", { class: "ba-pill", style: "margin:0", text: a.name }); }) : el("span", { class: "ba-hint", text: "Paying isn't switched on yet." })), el("h3", { text: "Buying more than once? Use a top-up link" }), el("p", { class: "ba-hint", text: "A top-up link is a private link that holds a balance. Pay into it once, then use it for any extra with one tap and no waiting. You can also give it to someone." + (CFG.bonus_pct ? " Top up " + usd(CFG.bonus_from) + " or more and get " + CFG.bonus_pct + "% extra." : "") }), el("a", { class: "ba-btn", href: "/topup/", text: "Make or open a top-up link" })); ROOT.appendChild(how); var from = document.getElementById("ba-from"); if (new URLSearchParams(location.search).get("keep") && I.keep && I.keep.on) { var m = /^[A-Za-z0-9]{6}$/.exec(new URLSearchParams(location.search).get("keep")); if (m) buyKeep(m[0]); } } /* ---------- TOP-UP LINK ---------- */ function topup() { ROOT.textContent = ""; var token = tokenIn(location.hash) || ""; if (token) return topupOpen(token); var saved = lsGet("ba_topup", ""); var paste = el("input", { type: "password", placeholder: "Paste your top-up link", "aria-label": "Top-up link", autocomplete: "off" }), err = el("div", { class: "ba-err", role: "alert" }); ROOT.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "What is a top-up link?" }), el("p", null, "A private link that holds a balance for BitAddy extras. Pay into it once, in the coin you like; then any extra is one tap, with no waiting for a blockchain. No account, no email."), el("ul", { class: "ba-ul" }, el("li", { text: "Whoever has the link can spend it, so keep it private, like cash. That also makes it an easy gift." }), el("li", { text: "BitAddy can't recover a lost link: there is no account behind it. Save it when it's shown." }), CFG.bonus_pct ? el("li", { text: "Top up " + usd(CFG.bonus_from) + " or more and get " + CFG.bonus_pct + "% extra." }) : null, el("li", { text: "The balance is for BitAddy extras only and can't be paid back out." })), el("button", { type: "button", class: "ba-btn p big", text: "Make a top-up link", onclick: function () { api("topup/new", {}).then(function (j) { topupMade(j.token); }).catch(function (e) { err.textContent = e.message; }); } }), err)); var have = el("div", { class: "ba-card" }, el("h3", { text: "Already have one?" })); if (saved) have.appendChild(el("p", null, el("button", { type: "button", class: "ba-btn", text: "Open the one saved on this device", onclick: function () { location.hash = saved; topup(); } }))); have.appendChild(el("div", { class: "ba-row" }, paste, el("button", { type: "button", class: "ba-btn", text: "Open", onclick: function () { var t = tokenIn(paste.value); if (!t) return toast("That doesn't look like a top-up link."); location.hash = t; topup(); } }))); ROOT.appendChild(have); openOrdersCard(ROOT); } function topupLink(token) { return location.origin + "/topup/#" + token; } function topupMade(token) { var link = topupLink(token), rem = el("input", { type: "checkbox", id: "tr" }); var dl = el("a", { class: "ba-btn", text: "Download as a file", download: "bitaddy-top-up-link.txt", href: URL.createObjectURL(new Blob(["Your BitAddy top-up link\n\n" + link + "\n\nKeep this private. Anyone with it can spend its balance on BitAddy extras.\nBitAddy can't recover it if it's lost.\n"], { type: "text/plain" })) }); var b = el("div", null, el("div", { class: "ba-key", style: "margin-top:0" }, el("p", null, el("b", { text: "Save this link now." }), " It is shown only this once, and it is the only way to its balance. Keep it private, like cash."), el("div", { class: "ba-secret", id: "topup-link", text: link }), el("div", { class: "ba-row" }, el("button", { type: "button", class: "ba-btn p", text: "Copy link", onclick: function () { copy(link, "Link copied. Save it somewhere safe."); } }), dl)), el("label", { for: "tr", style: "display:flex;gap:.5rem;align-items:center;font-weight:500" }, rem, "Also remember it on this device (don't tick this on a shared computer)")); dialog("Your top-up link", b, [{ label: "I saved it", kind: "p", value: 1 }]).then(function () { if (rem.checked) lsSet("ba_topup", token); location.hash = token; topup(); }); } function topupOpen(token) { api("topup", { token: token }).then(function (t) { ROOT.textContent = ""; var saved = lsGet("ba_topup", "") === token; var c = el("div", { class: "ba-card hi" }, el("div", { class: "ba-row spread" }, el("h2", { text: "Your top-up link", style: "margin:0" }), el("button", { type: "button", class: "ba-btn sm", text: "Copy link", onclick: function () { copy(topupLink(token), "Link copied. Keep it private."); } })), el("div", { class: "ba-bal", id: "topup-balance", text: "$" + t.balance }), el("p", { class: "ba-hint", text: "Use it for any extra: pick “From a top-up link” when you pay. It can't be paid back out." })); var amount = CFG.bonus_from && Number(CFG.bonus_from) <= 25 ? 25 : 10, custom = el("input", { type: "number", min: CFG.min_topup, max: CFG.max_topup, step: "1", placeholder: "Other", "aria-label": "Other amount in dollars", style: "max-width:6.5rem" }); var chips = el("div", { class: "ba-amounts" }), bonus = el("div", { class: "ba-note" }); function pick(v) { amount = v; chips.querySelectorAll("button").forEach(function (b) { b.classList.toggle("on", Number(b.dataset.v) === v); }); var extra = CFG.bonus_pct && v >= Number(CFG.bonus_from) ? v * CFG.bonus_pct / 100 : 0; bonus.textContent = extra ? "You pay " + usd(v) + " and get " + usd(v + extra) + " (" + CFG.bonus_pct + "% extra)." : (CFG.bonus_pct ? "Top up " + usd(CFG.bonus_from) + " or more for " + CFG.bonus_pct + "% extra." : ""); bonus.className = "ba-note" + (extra ? " ok" : ""); } [5, 10, 25, 50].filter(function (v) { return v >= Number(CFG.min_topup) && v <= Number(CFG.max_topup); }).forEach(function (v) { chips.appendChild(el("button", { type: "button", class: "ba-btn", "data-v": v, text: "$" + v, onclick: function () { custom.value = ""; pick(v); } })); }); chips.appendChild(custom); custom.addEventListener("input", function () { if (custom.value) pick(Number(custom.value)); }); pick(amount); c.appendChild(el("h3", { text: "Add money" })); c.appendChild(chips); c.appendChild(bonus); c.appendChild(el("button", { type: "button", class: "ba-btn p big", text: "Add it", onclick: function () { if (!(amount >= Number(CFG.min_topup) && amount <= Number(CFG.max_topup))) return toast("Between " + usd(CFG.min_topup) + " and " + usd(CFG.max_topup) + "."); payFlow({ kind: "topup", token: token, usd: String(amount) }, "Top-up", amount, function () { topupOpen(token); }); } })); ROOT.appendChild(c); openOrdersCard(ROOT, function () { topupOpen(token); }); var hc = el("div", { class: "ba-card" }, el("h3", { text: "What happened with it" })); if (!t.history.length) hc.appendChild(el("p", { class: "ba-hint", text: "Nothing yet." })); t.history.forEach(function (r) { hc.appendChild(el("div", { class: "ba-item" }, el("span", { text: r.what }), el("span", { class: "ba-hint", text: (r.cents < 0 ? "−$" : "+$") + (Math.abs(r.cents) / 100).toFixed(2) + " · " + fmtDate(r.ts) }))); }); ROOT.appendChild(hc); ROOT.appendChild(el("div", { class: "ba-card" }, el("div", { class: "ba-row spread" }, el("span", { class: "ba-hint", text: saved ? "This link is remembered on this device." : "This link is not remembered on this device." }), el("button", { type: "button", class: "ba-btn sm", text: saved ? "Forget it here" : "Remember it here", onclick: function () { lsSet("ba_topup", saved ? null : token); topupOpen(token); } })), el("p", { class: "ba-hint" }, el("a", { href: "/pricing/", text: "See what it can buy" }), " · ", el("a", { href: "/edit/", text: "Go to My links" })))); }).catch(function (e) { ROOT.textContent = ""; ROOT.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "That link didn't open" }), el("p", { text: e.message }), el("button", { type: "button", class: "ba-btn", text: "Back", onclick: function () { history.replaceState(null, "", location.pathname); topup(); } }))); }); } /* ---------- TIP ---------- */ function tip() { ROOT.textContent = ""; if (!CFG.tips) { ROOT.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "Thank you for the thought!" }), el("p", { text: "Tips aren't switched on right now." }))); return; } var amount = 5, chips = el("div", { class: "ba-amounts" }), custom = el("input", { type: "number", min: CFG.min_pay, max: "1000", step: "1", placeholder: "Other", "aria-label": "Other amount in dollars", style: "max-width:6.5rem" }); function pick(v) { amount = v; chips.querySelectorAll("button").forEach(function (b) { b.classList.toggle("on", Number(b.dataset.v) === v); }); } [3, 5, 10, 25].filter(function (v) { return v >= Number(CFG.min_pay); }).forEach(function (v) { chips.appendChild(el("button", { type: "button", class: "ba-btn", "data-v": v, text: "$" + v, onclick: function () { custom.value = ""; pick(v); } })); }); chips.appendChild(custom); custom.addEventListener("input", function () { if (custom.value) pick(Number(custom.value)); }); pick(amount); ROOT.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "Tip BitAddy" }), el("p", { text: "Short links, pages and safety checks are free for everyone. Tips help pay for the server and the domain. Thank you!" }), chips, el("button", { type: "button", class: "ba-btn p big", text: "Send a tip", onclick: function () { if (!(amount >= Number(CFG.min_pay))) return toast("At least " + usd(CFG.min_pay) + ", because of network fees."); payFlow({ kind: "tip", usd: String(amount) }, "Tip for BitAddy", amount); } }), el("p", { class: "ba-hint", text: "A tip buys nothing and can't be refunded. The smallest is " + usd(CFG.min_pay) + " because network fees would eat anything less." }))); openOrdersCard(ROOT); } /* ---------- PAYMENT ALERTS: a message when an address receives a payment (ba_alerts.py) ---------- */ function alertToken(text) { var m = /al-[A-Za-z0-9_\-]{20,40}/.exec(text || ""); return m ? m[0] : ""; } function alertsSaved() { return lsGet("ba_alerts", []); } function alertRemember(t, label) { var l = alertsSaved().filter(function (x) { return x.t !== t; }); l.unshift({ t: t, label: label }); lsSet("ba_alerts", l.slice(0, 20)); } function alertForget(t) { lsSet("ba_alerts", alertsSaved().filter(function (x) { return x.t !== t; })); } function alerts() { ROOT.textContent = ""; var token = alertToken(location.hash); if (token) return alertOpen(token); var it = (CFG.items || {}).alert || {}; var addr = el("input", { type: "text", id: "aa", class: "ba-in-big", placeholder: "Paste the address to watch", spellcheck: "false", autocomplete: "off", autocapitalize: "none" }); var label = el("input", { type: "text", id: "al", placeholder: "Label (optional), e.g. Shop tips", maxlength: "40" }); var note = el("div", { class: "ba-note" }), chips = el("div", { class: "ba-chips" }), err = el("div", { class: "ba-err", role: "alert" }), coin = "", t; addr.addEventListener("input", function () { ev("alert_start", "", "alert_start"); clearTimeout(t); coin = ""; chips.textContent = ""; t = setTimeout(function () { if (!addr.value.trim()) { note.textContent = ""; return; } api("detect", { address: addr.value }).then(function (j) { if (j.coins.length === 1) { coin = j.coins[0]; note.textContent = "✓ " + coinName(coin) + " address · ends in " + addr.value.trim().slice(-6); note.className = "ba-note ok"; } else if (j.coins.length > 1) { note.textContent = "Which coin is this for?"; note.className = "ba-note"; j.coins.forEach(function (c) { chips.appendChild(el("button", { type: "button", class: "ba-btn sm", text: coinName(c), onclick: function () { coin = c; chips.querySelectorAll("button").forEach(function (b) { b.classList.remove("p"); }); this.classList.add("p"); } })); }); } else { note.textContent = "That doesn't look like an address we know. Check for typos."; note.className = "ba-note bad"; } }); }, 300); }); var ch = "telegram", url = el("input", { type: "url", id: "au", placeholder: "", autocomplete: "off", spellcheck: "false" }), urlBox = el("div", { hidden: true }), urlHint = el("p", { class: "ba-hint" }); var opts = el("div", { class: "ba-row", role: "radiogroup", "aria-label": "Where to send the alerts" }); [["telegram", "Telegram"], ["discord", "Discord"], ["webhook", "Webhook"]].forEach(function (o, i) { opts.appendChild(el("button", { type: "button", role: "radio", "aria-checked": i ? "false" : "true", class: "ba-btn" + (i ? "" : " p"), text: o[1], onclick: function () { ch = o[0]; opts.querySelectorAll("button").forEach(function (b) { b.classList.remove("p"); b.setAttribute("aria-checked", "false"); }); this.classList.add("p"); this.setAttribute("aria-checked", "true"); urlBox.hidden = ch === "telegram"; url.placeholder = ch === "discord" ? "https://discord.com/api/webhooks/…" : "https://your-server.example/bitaddy"; urlHint.textContent = ch === "discord" ? "In Discord: channel settings → Integrations → Webhooks → New Webhook → Copy Webhook URL." : "BitAddy sends a signed JSON message (POST) to this address. Details are shown after you create the alert."; } })); }); urlBox.appendChild(el("label", { for: "au", text: "Address to send to" })); urlBox.appendChild(url); urlBox.appendChild(urlHint); var go = el("button", { type: "button", class: "ba-btn p big", text: "Create alert" }); go.onclick = function () { err.textContent = ""; go.disabled = true; api("alert/new", { address: addr.value, coin: coin, label: label.value, channel: ch, url: url.value }).then(function (j) { ev("alert_made", j.coin + ":" + j.channel); alertRemember(j.token, j.label || coinName(j.coin) + " …" + j.address.slice(-6)); location.hash = j.token; alertOpen(j.token, j); }).catch(function (e) { err.textContent = e.message; ev("problem", "alert: " + e.message); go.disabled = false; }); }; ROOT.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "Get told when you're paid" }), el("p", { class: "ba-hint", text: "BitAddy watches one address and sends you a message the moment a payment to it is confirmed: on Telegram, in a Discord channel, or to your own server. " + (it.usd ? usd(it.usd) + " a year per address. " : "") + "Try it with a free test message before you pay. No account." }), el("label", { for: "aa", text: "Address" }), addr, note, chips, el("label", { for: "al", text: "Label" }), label, el("h3", { text: "Where to send the alerts" }), opts, urlBox, err, go, el("p", { class: "ba-hint", text: "Also watches USDT and USDC on the same network (Ethereum, Solana and TRON addresses)." }))); var saved = alertsSaved(), have = el("div", { class: "ba-card" }, el("h3", { text: "Your alerts" })); if (saved.length) saved.forEach(function (x) { have.appendChild(el("div", { class: "ba-item" }, el("span", { text: x.label || "Alert" }), el("button", { type: "button", class: "ba-btn sm", text: "Open", onclick: function () { location.hash = x.t; alerts(); } }))); }); var paste = el("input", { type: "password", placeholder: "Paste your alert link", "aria-label": "Alert link", autocomplete: "off" }); have.appendChild(el("div", { class: "ba-row" }, paste, el("button", { type: "button", class: "ba-btn", text: "Open", onclick: function () { var t = alertToken(paste.value); if (!t) return toast("That doesn't look like an alert link."); location.hash = t; alerts(); } }))); ROOT.appendChild(have); openOrdersCard(ROOT); } function alertOpen(token, first) { ROOT.textContent = ""; var box = el("div"); ROOT.appendChild(box); function show(a) { box.textContent = ""; var link = location.origin + "/alerts/#" + token; var st = a.active ? (a.until ? "On until " + fmtDate(a.until) : "On for good") : a.ended ? "Ended " + fmtDate(a.until) : "Not started yet: activate it to start getting payment alerts"; var c = el("div", { class: "ba-card" }, el("div", { class: "ba-row spread" }, el("h2", { text: (a.label ? a.label + " · " : "") + a.coin_name + " alert", style: "margin:0" }), el("span", { class: "ba-pill " + (a.active ? "ok" : "bad"), text: a.active ? "on" : a.ended ? "ended" : "not started" })), el("p", { class: "ba-hint", text: "Address ending " + a.address.slice(-6) + " · watches " + a.watches.join(", ") }), el("p", null, el("b", { text: st }))); /* delivery */ var d = el("div", { class: "ba-extra" }); if (a.channel === "telegram") { d.appendChild(el("h4", { text: "Telegram" })); if (a.connected) d.appendChild(el("p", { text: "✓ Connected to a Telegram chat." })); else if (a.telegram_link) d.appendChild(el("p", null, el("a", { class: "ba-btn p", href: a.telegram_link, target: "_blank", rel: "noopener", text: "Connect Telegram", onclick: function () { ev("alert_tg_connect"); } }), el("span", { class: "ba-hint", text: " Opens @" + a.telegram_link.split("/")[3].split("?")[0] + " in Telegram: tap Start. Then come back and refresh." }))); } else if (a.channel === "discord") { d.appendChild(el("h4", { text: "Discord" })); d.appendChild(el("p", { text: "Sends to: " + a.target })); } else { d.appendChild(el("h4", { text: "Webhook" })); d.appendChild(el("p", { class: "ba-secret", text: a.target })); d.appendChild(el("p", { class: "ba-hint", text: "Each alert is a POST with a JSON body ({\"event\": \"payment\", \"coin\", \"asset\", \"amount\", \"address\", \"transaction\", ...}) and the header X-BitAddy-Signature: sha256=. Your secret:" })); d.appendChild(el("div", { class: "ba-row" }, el("div", { class: "ba-secret", text: a.secret }), el("button", { type: "button", class: "ba-btn sm", text: "Copy", onclick: function () { copy(a.secret, "Secret copied"); } }))); } d.appendChild(el("div", { class: "ba-row" }, el("button", { type: "button", class: "ba-btn sm", text: "Send a test alert", onclick: function () { ev("alert_test"); api("alert/test", { token: token }).then(function () { toast("Test sent. Check " + ({ telegram: "Telegram", discord: "Discord", webhook: "your server" }[a.channel])); load(); }).catch(function (e) { dialog("The test didn't arrive", e.message); load(); }); } }), el("button", { type: "button", class: "ba-btn sm", text: "Change where alerts go", onclick: function () { changeDelivery(a); } }), el("button", { type: "button", class: "ba-btn sm", text: "Refresh", onclick: load }))); if (a.last_error) d.appendChild(el("p", { class: "ba-note bad", text: "Last try didn't arrive: " + a.last_error })); c.appendChild(d); /* paying */ var it = (CFG.items || {}).alert; if (it && it.on && CFG.pay_on) c.appendChild(el("div", { class: "ba-row" }, el("span", { class: "pr", text: priceText(it) }), el("button", { type: "button", class: "ba-btn p", text: a.active ? "Add a year" : a.ended ? "Renew" : "Activate", onclick: function () { payFlow({ kind: "item", sku: "alert", alert: token }, "Payment alerts: " + a.coin_name + " ending " + a.address.slice(-6), it.usd, load); } }))); else if (!a.active) c.appendChild(el("p", { class: "ba-hint", text: "Paying isn't switched on yet. You can already set up and test your alert." })); /* history */ if (a.log.length) { var lg = el("div", { class: "ba-extra" }, el("h4", { text: "Recent messages" })); a.log.forEach(function (x) { lg.appendChild(el("p", { class: "ba-hint", text: fmtDate(x.ts) + " · " + ({ payment: "payment", test: "test", reminder: "reminder", ended: "ended" }[x.kind] || x.kind) + " · " + (x.ok ? "delivered" : "didn't arrive: " + (x.detail || "")) })); }); c.appendChild(lg); } box.appendChild(c); /* the alert link itself */ var keep = el("div", { class: "ba-card" + (first ? " hi" : "") }, el("h3", { text: first ? "Save your alert link" : "Your alert link" }), el("p", { class: "ba-hint", text: "It's the only way to manage this alert: there is no account and BitAddy can't send it to you again. Keep it private." }), el("div", { class: "ba-row" }, el("div", { class: "ba-secret", text: link }), el("button", { type: "button", class: "ba-btn sm p", text: "Copy", onclick: function () { copy(link, "Alert link copied. Save it somewhere safe."); } }), el("a", { class: "ba-btn sm", text: "Download", download: "bitaddy-alert-link.txt", href: URL.createObjectURL(new Blob(["Your BitAddy payment alert link\n\n" + link + "\n\nKeep it private: it manages your alert. BitAddy can't send it to you again.\n"], { type: "text/plain" })) })), el("div", { class: "ba-row" }, el("a", { class: "ba-btn sm", href: "/alerts/", text: "Back to alerts", onclick: function () { location.hash = ""; } }), el("button", { type: "button", class: "ba-btn sm d", text: "Delete this alert", onclick: function () { confirmBox("Delete this alert?", a.active ? "Alerts stop right away and the paid time is lost." : "It's removed right away.", "Delete", true).then(function (ok) { if (ok) api("alert/delete", { token: token }).then(function () { alertForget(token); toast("Deleted"); location.hash = ""; alerts(); }); }); } }))); box.appendChild(keep); openOrdersCard(ROOT, load); first = null; } function load() { return api("alert/get", { token: token }).then(function (a) { alertRemember(token, a.label || a.coin_name + " …" + a.address.slice(-6)); show(a); }).catch(function (e) { box.textContent = ""; box.appendChild(el("div", { class: "ba-card" }, el("p", { class: "ba-err", text: e.message }), el("a", { class: "ba-btn", href: "/alerts/", text: "Back to alerts", onclick: function () { location.hash = ""; } }))); }); } function changeDelivery(a) { var body = el("div"), ch = a.channel, url = el("input", { type: "url", placeholder: "https://…", autocomplete: "off" }), err = el("div", { class: "ba-err", role: "alert" }); var sel = el("select", { "aria-label": "Where alerts go" }, ["telegram", "discord", "webhook"].map(function (k) { return el("option", { value: k, text: { telegram: "Telegram", discord: "Discord", webhook: "Webhook" }[k], selected: k === ch }); })); function upd() { url.hidden = sel.value === "telegram"; } sel.onchange = upd; upd(); var s = sheet("Change where alerts go", body); body.appendChild(sel); body.appendChild(url); body.appendChild(err); body.appendChild(el("div", { class: "ba-row end" }, el("button", { type: "button", class: "ba-btn p", text: "Save", onclick: function () { api("alert/update", { token: token, channel: sel.value, url: url.value }).then(function (x) { s.close(); show(x); }).catch(function (e) { err.textContent = e.message; }); } }))); } if (first) show(first); else load(); } /* ---------- PAYMENT REQUESTS: a page that asks for an amount and shows "Paid" by itself (ba_payreq.py) ---------- */ function reqSaved() { return lsGet("ba_reqs", []); } function reqRemember(t, code, label) { var l = reqSaved().filter(function (x) { return x.t !== t; }); l.unshift({ t: t, code: code, label: label }); lsSet("ba_reqs", l.slice(0, 30)); } function reqForget(t) { lsSet("ba_reqs", reqSaved().filter(function (x) { return x.t !== t; })); } var STABLE = { ETH: ["USDT-ETH", "USDC-ETH"], SOL: ["USDT-SOL", "USDC-SOL"], TRX: ["USDT-TRX"] }; function reqStatus(r) { return { pending: "waiting", paid: "paid ✓", cancelled: "cancelled", expired: "expired" }[r.status] || r.status; } function request() { ROOT.textContent = ""; var qs = new URLSearchParams(location.search); var addr = el("input", { type: "text", id: "ra", class: "ba-in-big", placeholder: "The address to be paid at", spellcheck: "false", autocomplete: "off", autocapitalize: "none", value: qs.get("addr") || "" }); var what = el("select", { id: "rc", "aria-label": "What to ask for" }), amount = el("input", { type: "text", id: "rm", inputmode: "decimal", placeholder: "e.g. 25", autocomplete: "off" }); var note = el("input", { type: "text", id: "rn", placeholder: "Note (optional), e.g. Invoice #12", maxlength: "80" }); var info = el("div", { class: "ba-note" }), err = el("div", { class: "ba-err", role: "alert" }), out = el("div"), t; function fill(chain) { what.textContent = ""; if (!chain) { what.appendChild(el("option", { value: "", text: "Paste an address first" })); return; } [chain].concat(STABLE[chain] || []).forEach(function (a) { what.appendChild(el("option", { value: a, text: a === chain ? coinName(chain) + " (" + chain + ")" : a.replace("-", " on ").replace(" on ETH", " on Ethereum").replace(" on SOL", " on Solana").replace(" on TRX", " on TRON") })); }); } function detect() { clearTimeout(t); t = setTimeout(function () { if (!addr.value.trim()) { info.textContent = ""; fill(""); return; } api("detect", { address: addr.value }).then(function (j) { var want = (qs.get("coin") || "").toUpperCase(); var c = j.coins.length === 1 ? j.coins[0] : j.coins.indexOf(want) >= 0 ? want : j.coins[0]; if (!c) { info.textContent = "That doesn't look like an address we know. Check for typos."; info.className = "ba-note bad"; fill(""); return; } info.textContent = "✓ " + coinName(c) + " address · ends in " + addr.value.trim().slice(-6); info.className = "ba-note ok"; fill(c); }); }, 300); } addr.addEventListener("input", function () { ev("req_start", "", "req_start"); detect(); }); fill(""); if (addr.value) detect(); var go = el("button", { type: "button", class: "ba-btn p big", text: "Make the request" }); go.onclick = function () { err.textContent = ""; go.disabled = true; api("payreq/new", { address: addr.value, asset: what.value, amount: amount.value, note: note.value }).then(function (r) { ev("req_made", r.asset); reqRemember(r.token, r.code, r.amount + " " + r.symbol + (r.note ? " · " + r.note : "")); go.disabled = false; made(r); drawMine(); }).catch(function (e) { err.textContent = e.message; ev("problem", "request: " + e.message); go.disabled = false; }); }; function made(r) { out.textContent = ""; out.appendChild(el("div", { class: "ba-card hi" }, el("h2", { text: "Your payment request is ready" }), el("div", { class: "ba-big" }, el("a", { href: r.url, text: r.url.replace(/^https?:\/\//, "") })), el("p", { class: "ba-hint", text: "Asks for " + r.amount + " " + r.symbol + (r.note ? " · " + r.note : "") + ". The page shows “✓ Paid” by itself once the payment has arrived." }), el("div", { class: "ba-row" }, el("button", { type: "button", class: "ba-btn p", text: "Copy link", onclick: function () { ev("copy_link", "request"); copy(r.url); } }), shareBtn(r.url, "Pay " + r.amount + " " + r.symbol, "request"), el("a", { class: "ba-btn", href: r.url, text: "Open it" })), el("div", { class: "ba-row" }, qrSaveBtn(r.url, "Pay " + r.amount + " " + r.symbol, r.note || "bitaddy.com/r/" + r.code, "bitaddy-request-" + r.code, "request")), el("p", { class: "ba-hint", text: "This device remembers it under “Your requests” below and in My links, where you can also cancel it." }))); out.scrollIntoView({ behavior: "smooth", block: "nearest" }); } ROOT.appendChild(el("div", { class: "ba-card" }, el("h2", { text: "Ask for a payment" }), el("p", { class: "ba-hint", text: "Make a link that asks for an exact amount. Its page shows the amount, the address and a QR code, and turns into “✓ Paid” by itself when the payment arrives. Free, no account." }), el("label", { for: "ra", text: "Address" }), addr, info, el("label", { for: "rc", text: "Ask for" }), what, el("label", { for: "rm", text: "Amount" }), amount, el("label", { for: "rn", text: "Note" }), note, err, go, el("p", { class: "ba-hint", text: "Marked paid when a payment of at least this amount reaches the address after the request is made (watched for 30 days)." }))); ROOT.appendChild(out); var mine = el("div"); ROOT.appendChild(mine); function drawMine() { mine.textContent = ""; reqCard(mine); } drawMine(); } function reqCard(parent) { var saved = reqSaved(); var c = el("div", { class: "ba-card" }, el("div", { class: "ba-row spread" }, el("h3", { text: "Payment requests", style: "margin:0" }), el("a", { class: "ba-btn sm", href: "/request/", text: "+ New request" }))); parent.appendChild(c); if (!saved.length) { c.appendChild(el("p", { class: "ba-hint", text: "No payment requests on this device. A request asks for an exact amount and shows “✓ Paid” when it arrives." })); return; } var list = el("div"); c.appendChild(list); api("payreq/mine", { tokens: saved.map(function (x) { return x.t; }) }).then(function (j) { saved.forEach(function (x, i) { var r = j.requests[i]; if (!r) return; var row = el("div", { class: "ba-item" }, el("div", null, el("a", { href: r.url, text: r.amount + " " + r.symbol + (r.note ? " · " + r.note : "") }), el("span", { class: "ba-pill " + (r.status === "paid" ? "ok" : r.status === "pending" ? "" : "bad"), text: reqStatus(r) }), el("div", { class: "ba-hint", text: "bitaddy.com/r/" + r.code + " · to ends in " + r.address_ending + (r.status === "paid" ? " · paid " + fmtDate(r.paid_at) : " · made " + fmtDate(r.created)) })), el("div", { class: "ba-row" }, el("a", { class: "ba-btn sm", href: r.url, text: "Open" }), r.status === "pending" ? el("button", { type: "button", class: "ba-btn sm d", text: "Cancel", onclick: function () { confirmBox("Cancel this request?", "Its page will say it was cancelled, so nobody pays it.", "Cancel request", true).then(function (ok) { if (ok) api("payreq/cancel", { token: x.t }).then(function () { toast("Cancelled"); parent.textContent = ""; reqCard(parent); }); }); } }) : el("button", { type: "button", class: "ba-btn sm", text: "Remove", onclick: function () { reqForget(x.t); parent.textContent = ""; reqCard(parent); } }))); list.appendChild(row); }); }).catch(function () { list.appendChild(el("p", { class: "ba-hint", text: "Couldn't load your requests right now." })); }); } /* ---------- NEED A WALLET? (partner links, clearly marked) ---------- */ function partners() { ROOT.textContent = ""; if (!CFG.refs.length) return; var c = el("div", { class: "ba-card" }, el("h2", { text: "Places to start" }), el("p", { class: "ba-hint", text: "Links marked “partner” may pay BitAddy a small commission if you buy something, at no cost to you. That helps keep BitAddy free. We only list makers' own official sites." })); CFG.refs.forEach(function (r) { c.appendChild(el("div", { class: "ba-extra" }, el("div", { style: "flex:1;min-width:200px" }, el("h4", null, r.name, r.paid ? el("span", { class: "ba-pill", text: "partner" }) : null), r.note ? el("p", { text: r.note }) : null), el("a", { class: "ba-btn", href: r.url, target: "_blank", rel: (r.paid ? "sponsored " : "") + "nofollow noopener", text: "Visit ↗" }))); }); ROOT.appendChild(c); } /* ---------- start ---------- */ Promise.all([api("config"), api("me")]).then(function (r) { CFG = r[0]; ME = r[1]; ev("view", VIEW); ({ edit: edit, pricing: pricing, topup: topup, tip: tip, partners: partners, alerts: alerts, request: request }[VIEW] || home)(); }).catch(function () { ev("problem", "the app didn't load"); ROOT.textContent = "BitAddy can't load right now. Please try again in a moment."; }); })();