Add lightning invoice payments

This commit is contained in:
Jon Staab
2025-11-12 16:20:38 -08:00
parent c05d7e99e2
commit 9cae4da9f4
11 changed files with 198 additions and 12 deletions
+38 -1
View File
@@ -5,11 +5,38 @@
const {onscan} = $props()
const changeCamera = async () => {
if (camera && scanner) {
loading = true
try {
await scanner.setCamera(camera)
} catch (error) {
console.error("Failed to switch camera:", error)
} finally {
loading = false
}
}
}
let video: HTMLVideoElement
let scanner: QrScanner
let loading = $state(true)
let cameras = $state<QrScanner.Camera[]>([])
let camera = $state<string>("")
onMount(() => {
QrScanner.listCameras(true)
.then(async () => {
cameras = await QrScanner.listCameras(true)
if (cameras.length > 0) {
camera = cameras[0].id
}
})
.catch(error => {
console.error("Failed to list cameras:", error)
})
scanner = new QrScanner(video, r => onscan(r.data), {
returnDetailedScanResult: true,
})
@@ -22,11 +49,21 @@
})
</script>
<div class="bg-alt flex min-h-48 w-full flex-col items-center justify-center rounded p-px">
<div class="bg-alt relative flex min-h-48 w-full flex-col items-center justify-center rounded p-px">
{#if loading}
<p class="py-20">
<Spinner loading>Loading your camera...</Spinner>
</p>
{/if}
<video class="m-auto rounded" class:h-0={loading} bind:this={video}></video>
{#if cameras.length > 1}
<select
class="select select-bordered select-sm absolute bottom-1 right-1"
bind:value={camera}
onchange={changeCamera}>
{#each cameras as camera}
<option value={camera.id}>{camera.label || `Camera ${camera.id}`}</option>
{/each}
</select>
{/if}
</div>
+7 -6
View File
@@ -1,10 +1,8 @@
import {openDB, deleteDB} from "idb"
import type {IDBPDatabase} from "idb"
import {writable} from "svelte/store"
import type {Unsubscriber} from "svelte/store"
import {call, defer} from "@welshman/lib"
import {call} from "@welshman/lib"
import type {Maybe} from "@welshman/lib"
import {withGetter} from "@welshman/store"
export type IDBAdapter = {
name: string
@@ -83,11 +81,11 @@ export class IDB {
// If we're closing, ignore any lingering requests
if ([IDBStatus.Closed, IDBStatus.Closing].includes(this.status)) return
return f(await this.idbp)
return f(await this.idbp!)
}
getAll = async <T>(table: string): Promise<T[]> =>
this._withIDBP(async idbp => {
getAll = async <T>(table: string): Promise<T[]> => {
const result = await this._withIDBP(async idbp => {
const tx = idbp.transaction(table, "readwrite")
const store = tx.objectStore(table)
const result = await store.getAll()
@@ -97,6 +95,9 @@ export class IDB {
return result
})
return result || []
}
bulkPut = async <T>(table: string, data: Iterable<T>) =>
this._withIDBP(async idbp => {
const tx = idbp.transaction(table, "readwrite")