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 <noreply@anthropic.com>
This commit is contained in:
Patrick Mulligan 2026-02-14 15:42:01 -05:00
commit d650647d8f

View file

@ -280,8 +280,12 @@ function startLnurlCompletionPolling(
const data = await response.json() const data = await response.json()
// Check if the link has been used // The LNURL endpoint returns:
if (data.link?.used > 0 || data.used > 0) { // - { 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) console.log('[LNURL Poll] Withdrawal claimed!', uniqueHash)
clearInterval(pollInterval) clearInterval(pollInterval)
@ -294,6 +298,7 @@ function startLnurlCompletionPolling(
// Use a placeholder preimage since LNURL-withdraw doesn't provide one directly // Use a placeholder preimage since LNURL-withdraw doesn't provide one directly
onComplete(`lnurl-withdraw-${uniqueHash}`) onComplete(`lnurl-withdraw-${uniqueHash}`)
} }
// Note: Don't log on every poll - it can cause EPIPE errors in Electron
} catch (e) { } catch (e) {
console.warn('[LNURL Poll] Error checking status:', e) console.warn('[LNURL Poll] Error checking status:', e)
} }