Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ NEXT_PUBLIC_API_URL=

# Mock mode for local development (skip real API calls)
NEXT_PUBLIC_USE_MOCKS=true

# Pubkey for Lightning boost keysends
NEXT_PUBLIC_BOOST_PUBKEY=
38 changes: 5 additions & 33 deletions src/components/boost/boost-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
import { useCallback, useState } from "react"
import { Zap } from "lucide-react"
import { cn } from "@/lib/utils"
import { isSphinx } from "@/lib/sphinx/detect"
import { api } from "@/lib/api"
import { useMocks } from "@/lib/mock-data"

// eslint-disable-next-line @typescript-eslint/no-require-imports
const sphinx = require("sphinx-bridge")

const SPHINX_PUBKEY = process.env.NEXT_PUBLIC_BOOST_PUBKEY ?? ""

const DEFAULT_BOOST_AMOUNT = 5
const DEFAULT_BOOST_AMOUNT = 10

interface BoostButtonProps {
refId: string
pubkey: string
boostCount?: number
className?: string
}

export function BoostButton({ refId, boostCount = 0, className }: BoostButtonProps) {
export function BoostButton({ refId, pubkey, boostCount = 0, className }: BoostButtonProps) {
const [count, setCount] = useState(boostCount)
const [boosting, setBoosting] = useState(false)
const [flash, setFlash] = useState(false)
Expand All @@ -30,31 +25,8 @@ export function BoostButton({ refId, boostCount = 0, className }: BoostButtonPro
setBoosting(true)

try {
if (isSphinx()) {
// Lightning keysend via Sphinx
let res = await sphinx.enable(true)
if (!res) throw new Error("Sphinx enable failed")

res = await sphinx.keysend(SPHINX_PUBKEY, DEFAULT_BOOST_AMOUNT)

if (!res?.success) {
// Ask for topup then retry
res = await sphinx.topup()
if (!res) res = await sphinx.authorize()
if (!res?.budget || res.budget < DEFAULT_BOOST_AMOUNT) {
throw new Error("Insufficient budget")
}
res = await sphinx.keysend(SPHINX_PUBKEY, DEFAULT_BOOST_AMOUNT)
if (!res?.success) throw new Error("Keysend failed")
}
}

// Record boost on backend
if (!useMocks()) {
await api.post("/boost", {
amount: DEFAULT_BOOST_AMOUNT,
refid: refId,
})
await api.post("/boost", { refid: refId, amount: DEFAULT_BOOST_AMOUNT, pubkey })
}

setCount((c) => c + DEFAULT_BOOST_AMOUNT)
Expand All @@ -65,7 +37,7 @@ export function BoostButton({ refId, boostCount = 0, className }: BoostButtonPro
} finally {
setBoosting(false)
}
}, [refId, boosting])
}, [refId, pubkey, boosting])

return (
<button
Expand Down
Loading