diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index d8e91016..b7524572 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -12,7 +12,7 @@ import {goto} from "$app/navigation" import {page} from "$app/stores" import {context as pomadeContext} from "@pomade/core" - import {sync} from "@welshman/store" + import {sync, throttled} from "@welshman/store" import {setNip55Plugin} from "@welshman/signer" import * as util from "@welshman/util" import * as lib from "@welshman/lib" @@ -26,6 +26,7 @@ import {setupLogging} from "@app/logger" import "@app/policies" import {restoreSession} from "@app/session" + import {signerRequests} from "@app/signer" import {wallet} from "@app/lightning" import {kv, ss, storage} from "@app/storage" import {device} from "@app/device" @@ -235,6 +236,28 @@ }), ) + // Listen for signer errors, report to user via toast + unsubscribers.push( + throttled(10_000, signerRequests).subscribe($requests => { + if ($toast) return + + const longCutoff = Date.now() - 30_000 + const shortCutoff = Date.now() - 10_000 + const pending = $requests.filter(r => !r.finishedAt && r.startedAt < longCutoff) + const completed = $requests.filter(r => r.finishedAt && r.finishedAt > shortCutoff) + const showPendingError = pending.length > 10 + const showCompletedError = completed.length > 5 && completed.filter(r => r.ok).length === 0 + + if (showPendingError || showCompletedError) { + pushToast({ + theme: "error", + timeout: 60_000, + message: "Your signer isn't responding.", + }) + } + }), + ) + // Sync theme and font size unsubscribers.push( activeTheme.subscribe($activeTheme => {