Monitor signer status

This commit is contained in:
Jon Staab
2025-07-30 15:54:10 -07:00
parent 8697cc23be
commit 03b42c8276
5 changed files with 46 additions and 7 deletions

View File

@@ -234,7 +234,7 @@ export const checkRelayAccess = async (url: string, claim = "") => {
if (error) {
const message =
socket.auth.details?.replace(/^\w+: /, "") ||
error?.replace(/^\w+: /, "") ||
error.replace(/^\w+: /, "") ||
"join request rejected"
// If it's a strict NIP 29 relay don't worry about requesting access

View File

@@ -4,6 +4,11 @@
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import {toast, popToast} from "@app/toast"
const onActionClick = () => {
$toast!.action!.onclick()
popToast($toast!.id)
}
</script>
{#if $toast}
@@ -18,6 +23,11 @@
class:alert-error={theme === "error"}>
<p class="welshman-content-error">
{@html renderAsHtml(parse({content: $toast.message}))}
{#if $toast.action}
<Button class="cursor-pointer underline" onclick={onActionClick}>
{$toast.action.message}
</Button>
{/if}
</p>
<Button class="flex items-center opacity-75" onclick={() => popToast($toast.id)}>
<Icon icon="close-circle" />

View File

@@ -6,6 +6,10 @@ export type ToastParams = {
message: string
timeout?: number
theme?: "error"
action?: {
message: string
onclick: () => void
}
}
export type Toast = ToastParams & {

View File

@@ -1,6 +1,7 @@
<script lang="ts">
import "@src/app.css"
import "@capacitor-community/safe-area"
import {throttle} from "throttle-debounce"
import {onMount} from "svelte"
import * as nip19 from "nostr-tools/nip19"
import {get, derived} from "svelte/store"
@@ -8,7 +9,7 @@
import {dev} from "$app/environment"
import {goto} from "$app/navigation"
import {sync, localStorageProvider} from "@welshman/store"
import {identity, memoize, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib"
import {identity, memoize, spec, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib"
import type {TrustedEvent, StampedEvent} from "@welshman/util"
import {
WRAP,
@@ -37,6 +38,7 @@
session,
sessions,
signer,
signerLog,
dropSession,
defaultStorageAdapters,
userInboxRelaySelections,
@@ -44,6 +46,7 @@
loginWithNip46,
EventsStorageAdapter,
loadRelaySelections,
SignerLogEntryStatus,
} from "@welshman/app"
import * as lib from "@welshman/lib"
import * as util from "@welshman/util"
@@ -52,11 +55,11 @@
import * as welshmanSigner from "@welshman/signer"
import * as net from "@welshman/net"
import * as app from "@welshman/app"
import {nsecDecode} from "@lib/util"
import AppContainer from "@app/components/AppContainer.svelte"
import ModalContainer from "@app/components/ModalContainer.svelte"
import {setupTracking} from "@app/tracking"
import {setupAnalytics} from "@app/analytics"
import {nsecDecode} from "@lib/util"
import {
INDEXER_RELAYS,
userMembership,
@@ -66,6 +69,7 @@
} from "@app/state"
import {loadUserData, listenForNotifications} from "@app/requests"
import {theme} from "@app/theme"
import {toast, pushToast} from "@app/toast"
import {initializePushNotifications} from "@app/push"
import * as commands from "@app/commands"
import * as requests from "@app/requests"
@@ -265,6 +269,27 @@
}
},
)
// Listen for signer errors, report to user via toast
signerLog.subscribe(
throttle(10_000, $log => {
const recent = $log.slice(-10)
const success = recent.filter(spec({status: SignerLogEntryStatus.Success}))
const failure = recent.filter(spec({status: SignerLogEntryStatus.Failure}))
if (!$toast && failure.length > 5 && success.length === 0) {
pushToast({
theme: "error",
timeout: 60_000,
message: "Your signer appears to be unresponsive.",
action: {
message: "Details",
onclick: () => goto("/settings/profile"),
},
})
}
}),
)
}
})
</script>

View File

@@ -26,7 +26,7 @@
const rooms = Array.from($userRoomsByUrl.get(url) || [])
const checkConnection = async () => {
const checkConnection = async (signal: AbortSignal) => {
const connectionError = await checkRelayConnection(url)
if (connectionError) {
@@ -37,7 +37,7 @@
const error = authError || accessError
if (error) {
if (error && !signal.aborted) {
pushModal(SpaceAuthError, {url, error})
}
}
@@ -50,12 +50,12 @@
})
onMount(() => {
checkConnection()
const relays = [url]
const since = ago(MONTH)
const controller = new AbortController()
checkConnection(controller.signal)
// Load group meta, threads, calendar events, comments, and recent messages
// for user rooms to help with a quick page transition
pullConservatively({