diff options
| -rw-r--r-- | lib/utils.js | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/utils.js b/lib/utils.js index b7212639..5a108e81 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -29,13 +29,19 @@ export const pick = (O, K) => K.reduce((o, k) => (typeof O[k] !== "undefined" && (o[k] = O[k]), o), {}); export const bip21 = (address, { amount, memo, tip, type }) => { + if (!(amount || memo)) return address; + let network = { liquid: "liquidnetwork", bitcoin: "bitcoin" }[type]; - let url = amount || memo ? `${network}:${address}?` : address; - if (amount) - url += `amount=${((amount + tip) / SATS).toFixed(8)}${memo ? "&" : ""}`; - if (memo) url += `message=${memo}`; + let url = new URLSearchParams(); + + if (amount) { + url.append("amount", amount); + if (type === "liquid") url.append("asset", config.liquid.btc); + } + + if (memo) url.append("memo", memo); - return url; + return `${network}:${address}?${url.toString()}`; }; export const fields = [ |
