diff --git a/src/components/modals/budget-modal.tsx b/src/components/modals/budget-modal.tsx index cc1445a..4307ee9 100644 --- a/src/components/modals/budget-modal.tsx +++ b/src/components/modals/budget-modal.tsx @@ -129,7 +129,7 @@ export function BudgetModal() { // Sphinx or WebLN: pay the invoice directly if (sphinxConnected || weblnAvailable) { - const payment = await payInvoice(result.payment_request) + const payment = await payInvoice(result.payment_request, macaroon) if (!payment) { setError("Payment was cancelled or failed.") setLoading(false) diff --git a/src/lib/sphinx/bridge.ts b/src/lib/sphinx/bridge.ts index a44071c..2c9a3ad 100644 --- a/src/lib/sphinx/bridge.ts +++ b/src/lib/sphinx/bridge.ts @@ -89,13 +89,22 @@ export function hasWebLN(): boolean { return !!(window as any).webln } -export async function payInvoice(invoice: string): Promise<{ preimage: string } | null> { +export async function payInvoice(invoice: string, macaroon?: string): Promise<{ preimage: string } | null> { if (typeof window === "undefined") return null if (isSphinx()) { try { - const result = await sphinx.sendPayment(invoice) - return result?.preimage ? { preimage: result.preimage } : null + // sphinx-bridge pays invoices via saveLsat (not sendPayment) + const result = await sphinx.saveLsat( + invoice, + macaroon ?? "", + window.location.host + ) + if (result?.lsat) { + const preimage = result.lsat.split(":")[1] + return preimage ? { preimage } : null + } + return null } catch (error) { console.error("Sphinx payment failed:", error) return null