react-native-webln
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -1,2 +0,2 @@ | ||
declare const _default: "(() => {\n \"use strict\";\n if (!window.ReactNativeWebView) {\n return;\n }\n const WebLNPromiseCallback = {};\n const timeout = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));\n let requestId = 0;\n let weblnEnabled = false;\n window.webln = {\n enable: async () => {\n if (document.domain !== \"tippin.me\") {\n weblnEnabled = true;\n }\n return;\n },\n getInfo: async () => {\n return await postMessage({\n type: \"getInfo\",\n data: null,\n });\n },\n makeInvoice: async (args) => {\n const result = await postMessage({\n type: \"makeInvoice\",\n data: args,\n });\n checkedInvoices.push((\"lightning:\" + result.paymentRequest).toUpperCase());\n return result;\n },\n sendPayment: async (paymentRequest) => {\n return await postMessage({\n type: \"sendPayment\",\n data: paymentRequest,\n });\n },\n signMessage: async () => {\n return {\n message: \"\",\n signature: \"\",\n };\n },\n verifyMessage: async () => {\n return;\n },\n };\n const postMessage = async (message, waitForCallback = true) => {\n const currentId = requestId++;\n window.ReactNativeWebView.postMessage(JSON.stringify({\n ...message,\n id: currentId,\n }));\n if (!waitForCallback) {\n return;\n }\n while (!WebLNPromiseCallback[currentId]) {\n await timeout(1000);\n }\n if (WebLNPromiseCallback[currentId] instanceof Error) {\n throw WebLNPromiseCallback[currentId];\n }\n return WebLNPromiseCallback[currentId];\n };\n document.addEventListener(\"webln\", (event) => {\n WebLNPromiseCallback[event.detail.id] = event.detail.data;\n });\n const checkedInvoices = [];\n if (window.reactNativeWebLNCheckTags) {\n const checkATags = async () => {\n const aTags = document.querySelectorAll(\"a\");\n for (const aTag of aTags) {\n if (aTag.href &&\n aTag.href.toUpperCase().startsWith(\"LIGHTNING:\") &&\n aTag.href.length > \"LIGHTNING:\".length) {\n const invoice = aTag.href.toUpperCase().replace(\"LIGHTNING:\", \"\");\n if (checkedInvoices.includes(invoice)) {\n return;\n }\n if (weblnEnabled && invoice.startsWith(\"LNBC\")) {\n return;\n }\n debug(\"Found: \" + aTag.href);\n checkedInvoices.push(invoice);\n await postMessage({\n type: \"nonwebln_foundInvoice\",\n data: invoice\n }, false);\n break;\n }\n }\n };\n const check = setInterval(() => {\n if (weblnEnabled) {\n clearInterval(check);\n }\n checkATags();\n }, 900);\n }\n const debug = async (message) => {\n if (window.reactNativeWebLNDebug) {\n await postMessage({\n type: \"debug\",\n data: message,\n }, false);\n }\n };\n})();"; | ||
declare const _default: "(() => {\n \"use strict\";\n if (!window.ReactNativeWebView) {\n return;\n }\n const WebLNPromiseCallback = {};\n const timeout = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));\n let requestId = 0;\n let weblnEnabled = false;\n window.webln = {\n enable: async () => {\n if (document.domain !== \"tippin.me\") {\n weblnEnabled = true;\n }\n return;\n },\n getInfo: async () => {\n return await postMessage({\n type: \"getInfo\",\n data: null,\n });\n },\n makeInvoice: async (args) => {\n const result = await postMessage({\n type: \"makeInvoice\",\n data: args,\n });\n checkedInvoices.push((\"lightning:\" + result.paymentRequest).toUpperCase());\n return result;\n },\n sendPayment: async (paymentRequest) => {\n return await postMessage({\n type: \"sendPayment\",\n data: paymentRequest,\n });\n },\n signMessage: async () => {\n return {\n message: \"\",\n signature: \"\",\n };\n },\n verifyMessage: async () => {\n return;\n },\n };\n const postMessage = async (message, waitForCallback = true) => {\n const currentId = requestId++;\n window.ReactNativeWebView.postMessage(JSON.stringify({\n ...message,\n id: currentId,\n }));\n if (!waitForCallback) {\n return;\n }\n while (!WebLNPromiseCallback[currentId]) {\n await timeout(1000);\n }\n if (WebLNPromiseCallback[currentId] instanceof Error) {\n throw WebLNPromiseCallback[currentId];\n }\n return WebLNPromiseCallback[currentId];\n };\n document.addEventListener(\"webln\", (event) => {\n WebLNPromiseCallback[event.detail.id] = event.detail.data;\n });\n const checkedInvoices = [];\n if (window.reactNativeWebLNCheckTags) {\n const checkATags = async () => {\n const aTags = document.querySelectorAll(\"a\");\n for (const aTag of aTags) {\n if (aTag.href &&\n aTag.href.toUpperCase().startsWith(\"LIGHTNING:\") &&\n aTag.href.length > \"LIGHTNING:\".length) {\n const invoice = aTag.href.toUpperCase().replace(\"LIGHTNING:\", \"\");\n if (checkedInvoices.includes(invoice)) {\n return;\n }\n if (weblnEnabled && invoice.startsWith(\"LNBC\")) {\n return;\n }\n debug(\"Found: \" + aTag.href);\n checkedInvoices.push(invoice);\n await postMessage({\n type: \"nonwebln_foundInvoice\",\n data: invoice\n }, false);\n break;\n }\n }\n };\n setInterval(() => {\n checkATags();\n }, 850);\n }\n const debug = async (message) => {\n if (window.reactNativeWebLNDebug) {\n await postMessage({\n type: \"debug\",\n data: message,\n }, false);\n }\n };\n})();"; | ||
export default _default; |
@@ -94,8 +94,5 @@ "use strict"; | ||
}; | ||
const check = setInterval(() => { | ||
if (weblnEnabled) { | ||
clearInterval(check); | ||
} | ||
setInterval(() => { | ||
checkATags(); | ||
}, 900); | ||
}, 850); | ||
} | ||
@@ -102,0 +99,0 @@ const debug = async (message) => { |
@@ -118,3 +118,4 @@ import { WebLNProvider, RequestInvoiceResponse } from "webln"; | ||
} | ||
// Disable BOLT11 invoices if WebLN is enabled | ||
// Disable BOLT11 invoices if WebLN is enabled. | ||
// LNURL is not affected by this | ||
if (weblnEnabled && invoice.startsWith("LNBC")) { | ||
@@ -134,8 +135,5 @@ return; | ||
const check = setInterval(() => { | ||
if (weblnEnabled) { | ||
clearInterval(check); | ||
} | ||
setInterval(() => { | ||
checkATags(); | ||
}, 900); | ||
}, 850); | ||
} | ||
@@ -142,0 +140,0 @@ |
{ | ||
"name": "react-native-webln", | ||
"description": "Library for supporting WebLN in a WebView", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"main": "dist/index", | ||
@@ -6,0 +6,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26760
499