robosats/frontend/src/utils/webln.ts

19 lines
453 B
TypeScript
Raw Normal View History

2022-09-09 17:18:04 +00:00
import { requestProvider, WeblnProvider } from 'webln';
export const getWebln = async (): Promise<WeblnProvider> => {
const resultPromise = new Promise<WeblnProvider>(async (resolve, reject) => {
try {
2022-09-09 17:18:04 +00:00
const webln = await requestProvider();
if (webln) {
2022-09-09 17:18:04 +00:00
webln.enable();
resolve(webln);
}
} catch (err) {
2022-09-09 17:18:04 +00:00
console.log("Coulnd't connect to Webln");
reject();
}
2022-09-09 17:18:04 +00:00
});
2022-09-09 17:18:04 +00:00
return resultPromise;
};