chore: cleanup

This commit is contained in:
2023-11-01 00:40:12 +09:00
parent 8f90daa840
commit c65bb7a992
56 changed files with 344 additions and 221 deletions

View File

@ -1,5 +1,5 @@
import { EmailRegex } from "./const";
import { bech32ToText, unwrap } from "./utils";
import { bech32ToText, throwIfOffline, unwrap } from "./utils";
const PayServiceTag = "payRequest";
@ -93,6 +93,7 @@ export class LNURL {
}
async load() {
throwIfOffline();
const rsp = await fetch(this.#url);
if (rsp.ok) {
this.#service = await rsp.json();
@ -108,6 +109,7 @@ export class LNURL {
* @returns
*/
async getInvoice(amount: number, comment?: string, zap?: object) {
throwIfOffline();
const callback = new URL(unwrap(this.#service?.callback));
const query = new Map<string, string>();

View File

@ -215,3 +215,15 @@ export function normalizeReaction(content: string) {
return Reaction.Positive;
}
}
export class OfflineError extends Error {}
export function throwIfOffline() {
if (isOffline()) {
throw new OfflineError("Offline");
}
}
export function isOffline() {
return !("navigator" in globalThis && globalThis.navigator.onLine);
}