-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use strong types for window.webln (#412)
- Loading branch information
1 parent
18854f8
commit cdce5aa
Showing
7 changed files
with
30 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
import log from "loglevel"; | ||
|
||
export function detectWebLNProvider(timeoutParam) { | ||
const timeout = timeoutParam ?? 3000; | ||
export const detectWebLNProvider = (timeout: number = 3000) => { | ||
const interval = 100; | ||
|
||
return new Promise((resolve) => { | ||
const handleWebLn = () => { | ||
resolve(window.webln !== undefined); | ||
}; | ||
|
||
if (window.webln) { | ||
handleWebLN(); | ||
handleWebLn(); | ||
} else { | ||
let i = 0; | ||
const checkInterval = setInterval(function () { | ||
if (window.webln || i >= timeout / interval) { | ||
handleWebLN(); | ||
handleWebLn(); | ||
clearInterval(checkInterval); | ||
} | ||
i++; | ||
}, interval); | ||
} | ||
|
||
function handleWebLN() { | ||
resolve(window.webln !== undefined); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
export async function enableWebln(cb) { | ||
export const enableWebln = async ( | ||
cb: () => Promise<void> | void, | ||
): Promise<void> => { | ||
try { | ||
await window.webln.enable(); | ||
await cb(); | ||
} catch (error) { | ||
log.error("webln call failed", error); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="@webbtc/webln-types" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cdce5aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
webapp-mainnet – ./
webapp-mainnet.vercel.app
webapp-mainnet-git-main-boltz.vercel.app
webapp-mainnet-boltz.vercel.app
beta.boltz.exchange
cdce5aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
webapp – ./
webapp-boltz.vercel.app
staging.boltz.exchange
webapp-nine-nu.vercel.app
webapp-git-main-boltz.vercel.app