Fix wallet status when wallet is unreachable (#79) #80

Closed
triesap wants to merge 33 commits from fix/79-wallet-status-unavailable into dev
Showing only changes of commit e24d51310e - Show all commits
+28 -3
View File
1
@@ -68,6 +68,22 @@
}
}
const checkWebLnStatus = async () => {
const webLn = getWebLn()
if (!webLn) {
return "unavailable" as const
}
try {
await withTimeout(webLn.getInfo(), 5000)
return "connected" as const
} catch (error) {
console.warn("WebLN wallet unavailable", error)
return "unavailable" as const
}
}
let walletStatus = $state<"checking" | "connected" | "unavailable">("checking")
let walletStatusRequestId = 0
@@ -80,7 +96,7 @@
)
const connectionVerb = $derived(walletStatus === "connected" ? "Connected to" : "Configured for")
$effect(() => {
const startWalletStatusCheck = () => {
const wallet = $session?.wallet
if (!wallet) {
@@ -93,13 +109,19 @@
walletStatus = "checking"
void (async () => {
const nextStatus =
wallet.type === "nwc" ? await checkNwcStatus() : getWebLn() ? "connected" : "unavailable"
const nextStatus = wallet.type === "nwc" ? await checkNwcStatus() : await checkWebLnStatus()
if (requestId === walletStatusRequestId) {
walletStatus = nextStatus
Outdated
Review

A nice little helper for this pattern is the call function. It's just a little prettier.

A nice little helper for this pattern is the `call` function. It's just a little prettier.
}
})()
}
const retryStatus = () => startWalletStatusCheck()
$effect(() => {
$session?.wallet
startWalletStatusCheck()
})
</script>
@@ -122,6 +144,9 @@
<Icon icon={InfoCircle} size={4} />
Unavailable
{/if}
{#if walletStatus === "unavailable"}
<Button class="btn btn-ghost btn-xs" onclick={retryStatus}>Retry</Button>
{/if}
</div>
{:else}
<Button class="btn btn-primary btn-sm" onclick={connect}>