robosats/frontend/src/utils/webln.ts
KoalaSat 293c0b604d Refactor contexts and models (#921)
* Add SVG icons for map pins

* Add federation basis and new coordinator form (#793)

* Add new coordinator entry issue form

* Add Federation basis

* Fix eslint errors from F2F and fix languages

* Redo eslint @typescript-eslint/strict-boolean-expressions

* Robot Page working

* Contexts Working

* Garage Working

* CurrentOrder working

* Federation model working

---------

Co-authored-by: Reckless_Satoshi <reckless.satoshi@protonmail.com>
Co-authored-by: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com>
2023-12-02 10:40:59 +00:00

30 lines
751 B
TypeScript

import { requestProvider, type WeblnProvider } from 'webln';
const getWebln = async (): Promise<WeblnProvider> => {
const resultPromise = new Promise<WeblnProvider>((resolve, reject) => {
requestProvider()
.then((webln) => {
if (webln != null) {
webln
.enable()
.then(() => {
resolve(webln);
})
.catch(() => {
reject(new Error("Couldn't connect to Webln"));
});
} else {
reject(new Error("Couldn't connect to Webln"));
}
})
.catch((err) => {
console.log("Couldn't connect to Webln", err);
reject(err);
});
});
return await resultPromise;
};
export default getWebln;