From 057707f37a28d972bc9b2e8ee3f32f67b2fdd5aa Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 2 Jan 2024 17:53:56 -0800 Subject: fix bip21 url for liquid --- lib/utils.js | 16 +++++++++++----- 1 file 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 = [ -- cgit v1.2.3