From d650647d8ff8aa7fbf4794f0888ac80519136bc3 Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Sat, 14 Feb 2026 15:42:01 -0500 Subject: [PATCH] fix(machine): detect LNURL-withdraw completion from spent status The polling was checking for `data.used > 0` but the LNURL endpoint returns `{ status: 'ERROR', reason: 'Withdraw link is spent.' }` when the link has been claimed. Check for this error response instead. Co-Authored-By: Claude Opus 4.5 --- lamassu-next/apps/machine/src/services/lightning.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lamassu-next/apps/machine/src/services/lightning.ts b/lamassu-next/apps/machine/src/services/lightning.ts index f522bba..7e76b65 100644 --- a/lamassu-next/apps/machine/src/services/lightning.ts +++ b/lamassu-next/apps/machine/src/services/lightning.ts @@ -280,8 +280,12 @@ function startLnurlCompletionPolling( const data = await response.json() - // Check if the link has been used - if (data.link?.used > 0 || data.used > 0) { + // The LNURL endpoint returns: + // - { tag: 'withdrawRequest', ... } when link is still available + // - { status: 'ERROR', reason: 'Withdraw link is spent.' } when claimed + const isSpent = data.status === 'ERROR' && data.reason?.includes('spent') + + if (isSpent) { console.log('[LNURL Poll] Withdrawal claimed!', uniqueHash) clearInterval(pollInterval) @@ -294,6 +298,7 @@ function startLnurlCompletionPolling( // Use a placeholder preimage since LNURL-withdraw doesn't provide one directly onComplete(`lnurl-withdraw-${uniqueHash}`) } + // Note: Don't log on every poll - it can cause EPIPE errors in Electron } catch (e) { console.warn('[LNURL Poll] Error checking status:', e) }