aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-01-02 17:53:56 -0800
committerAdam Soltys <[email protected]>2024-01-02 17:53:59 -0800
commit057707f37a28d972bc9b2e8ee3f32f67b2fdd5aa (patch)
tree629a78f4ee63d8a7cd8111aceba95ed1b14849e1 /lib/utils.js
parent8bcf278790bb0c8e904215c1a563e301076fca14 (diff)
downloadcoinos-server-057707f37a28d972bc9b2e8ee3f32f67b2fdd5aa.tar.gz
coinos-server-057707f37a28d972bc9b2e8ee3f32f67b2fdd5aa.zip
fix bip21 url for liquid
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js16
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 = [