Skip to content

Commit 5ee1584

Browse files
committed
Explicit promise for requestProvider, fix throws
1 parent d91ac9e commit 5ee1584

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/client.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ export interface GetProviderParameters {
1313
}
1414

1515
export function requestProvider(_: GetProviderParameters = {}): Promise<WebLNProvider> {
16-
if (typeof window === 'undefined') {
17-
throw new Error('Must be called in a browser context');
18-
}
16+
return new Promise((resolve, reject) => {
17+
if (typeof window === 'undefined') {
18+
return reject(new Error('Must be called in a browser context'));
19+
}
1920

20-
const webln: WebLNProvider = (window as any).webln;
21-
if (!webln) {
22-
throw new MissingProviderError('Your browser has no WebLN provider');
23-
}
21+
const webln: WebLNProvider = (window as any).webln;
22+
if (!webln) {
23+
return reject(new MissingProviderError('Your browser has no WebLN provider'));
24+
}
2425

25-
return webln.enable().then(() => webln);
26+
webln.enable().then(() => resolve(webln));
27+
});
2628
}

0 commit comments

Comments
 (0)