2025-07-29 17:53:48 +00:00
|
|
|
<script lang="ts">
|
2026-07-28 16:16:26 +00:00
|
|
|
import {avg, spec} from "@welshman/lib"
|
2025-09-10 22:26:39 +00:00
|
|
|
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
|
|
|
|
import Danger from "@assets/icons/danger-triangle.svg?dataurl"
|
|
|
|
|
import ClockCircle from "@assets/icons/clock-circle.svg?dataurl"
|
|
|
|
|
import CheckCircle from "@assets/icons/check-circle.svg?dataurl"
|
2025-07-29 17:53:48 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import LogOut from "@app/components/LogOut.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {session} from "@app/core"
|
|
|
|
|
import {signerRequests} from "@app/signer"
|
2026-01-09 19:02:32 +00:00
|
|
|
import PomadeSessions from "@app/components/PomadeSessions.svelte"
|
2025-07-29 17:53:48 +00:00
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const finished = $derived($signerRequests.filter(request => request.finishedAt))
|
|
|
|
|
const pending = $derived($signerRequests.filter(request => !request.finishedAt))
|
2026-01-06 23:30:54 +00:00
|
|
|
const success = $derived(finished.filter(spec({ok: true})))
|
2026-07-28 16:16:26 +00:00
|
|
|
const failure = $derived(finished.filter(spec({ok: false})))
|
2026-02-09 19:12:54 +00:00
|
|
|
const cutoff = $derived(Date.now() - 10_000)
|
2026-07-28 16:16:26 +00:00
|
|
|
const recentCompleted = $derived(finished.filter(request => request.finishedAt! > cutoff))
|
|
|
|
|
const recentAvg = $derived(avg(recentCompleted.map(r => r.finishedAt! - r.startedAt)))
|
|
|
|
|
const recentFailure = $derived(recentCompleted.filter(request => !request.ok))
|
|
|
|
|
const recentSuccess = $derived(recentCompleted.filter(request => request.ok))
|
2025-07-29 17:53:48 +00:00
|
|
|
const isDisconnected = $derived(
|
2026-02-09 19:12:54 +00:00
|
|
|
recentCompleted.length > 0 && recentFailure.length === recentCompleted.length,
|
2025-07-29 17:53:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const logout = () => pushModal(LogOut)
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
{#if $session}
|
2026-06-24 20:56:53 +00:00
|
|
|
<div class="card flex flex-col gap-4">
|
2025-09-22 22:09:41 +00:00
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
|
<div class="flex items-center justify-between">
|
|
|
|
|
<span class="text-xl font-bold">Signer Status</span>
|
|
|
|
|
<span class="flex items-center gap-2">
|
|
|
|
|
{#if isDisconnected}
|
|
|
|
|
<Icon icon={CloseCircle} class="text-error" size={4} /> Disconnected
|
2026-01-06 23:30:54 +00:00
|
|
|
{:else if recentFailure.length > 3}
|
2025-09-22 22:09:41 +00:00
|
|
|
<Icon icon={Danger} class="text-warning" size={4} /> Partial Failure
|
2026-02-09 19:12:54 +00:00
|
|
|
{:else if recentAvg > 1000 || pending.length > 10}
|
2025-09-22 22:09:41 +00:00
|
|
|
<Icon icon={ClockCircle} class="text-warning" size={4} /> Slow connection
|
2026-01-06 23:30:54 +00:00
|
|
|
{:else if recentSuccess.length === 0 && recentFailure.length > 0}
|
|
|
|
|
<Icon icon={Danger} class="text-warning" size={4} /> Partial Failure
|
|
|
|
|
{:else}
|
2025-09-22 22:09:41 +00:00
|
|
|
<Icon icon={CheckCircle} class="text-success" size={4} /> Ok
|
|
|
|
|
{/if}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-01-22 22:23:46 +00:00
|
|
|
<div class="flex flex-col justify-between text-sm opacity-75 sm:flex-row">
|
2025-09-22 22:09:41 +00:00
|
|
|
<p>
|
|
|
|
|
Logged in with
|
2026-07-28 16:16:26 +00:00
|
|
|
{#if $session.method === "nip01"}
|
2025-09-22 22:09:41 +00:00
|
|
|
private key
|
2026-07-28 16:16:26 +00:00
|
|
|
{:else if $session.method === "nip07"}
|
2025-09-22 22:09:41 +00:00
|
|
|
browser extension
|
2026-07-28 16:16:26 +00:00
|
|
|
{:else if $session.method === "nip46"}
|
2025-09-22 22:09:41 +00:00
|
|
|
remote signer
|
2026-07-28 16:16:26 +00:00
|
|
|
{:else if $session.method === "nip55"}
|
|
|
|
|
an external signer
|
|
|
|
|
{:else if $session.method === "pomade"}
|
2026-01-12 23:21:58 +00:00
|
|
|
email and password
|
2025-09-22 22:09:41 +00:00
|
|
|
{/if}
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
2026-01-06 23:30:54 +00:00
|
|
|
{success.length} requests succeeded, {failure.length} failed, {pending.length} pending
|
2025-09-22 22:09:41 +00:00
|
|
|
</p>
|
|
|
|
|
</div>
|
2025-07-29 17:53:48 +00:00
|
|
|
</div>
|
2025-09-22 22:09:41 +00:00
|
|
|
{#if isDisconnected}
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-error" onclick={logout}>Logout to Reconnect</Button>
|
2026-01-12 23:21:58 +00:00
|
|
|
{:else}
|
2026-01-09 19:02:32 +00:00
|
|
|
<PomadeSessions />
|
2025-09-22 22:09:41 +00:00
|
|
|
{/if}
|
2025-07-29 17:53:48 +00:00
|
|
|
</div>
|
2025-09-22 22:09:41 +00:00
|
|
|
{/if}
|