2022-09-09 17:18:04 +00:00
|
|
|
import { requestProvider, WeblnProvider } from 'webln';
|
2022-08-25 08:50:48 +00:00
|
|
|
|
2022-10-30 19:13:01 +00:00
|
|
|
const getWebln = async (): Promise<WeblnProvider> => {
|
2022-08-25 08:50:48 +00:00
|
|
|
const resultPromise = new Promise<WeblnProvider>(async (resolve, reject) => {
|
|
|
|
try {
|
2022-09-09 17:18:04 +00:00
|
|
|
const webln = await requestProvider();
|
2022-08-25 08:50:48 +00:00
|
|
|
if (webln) {
|
2022-09-09 17:18:04 +00:00
|
|
|
webln.enable();
|
|
|
|
resolve(webln);
|
2022-08-25 08:50:48 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2022-09-09 17:18:04 +00:00
|
|
|
console.log("Coulnd't connect to Webln");
|
|
|
|
reject();
|
2022-08-25 08:50:48 +00:00
|
|
|
}
|
2022-09-09 17:18:04 +00:00
|
|
|
});
|
2022-08-25 08:50:48 +00:00
|
|
|
|
2022-09-09 17:33:29 +00:00
|
|
|
return await resultPromise;
|
2022-09-09 17:18:04 +00:00
|
|
|
};
|
2022-10-30 19:13:01 +00:00
|
|
|
|
|
|
|
export default getWebln;
|