Skip to content

Commit

Permalink
Merge pull request #416 from ericpp/add-lnurl-support
Browse files Browse the repository at this point in the history
Add LNURL support to boost button
  • Loading branch information
daveajones authored Dec 10, 2024
2 parents c33a1e6 + e1f60e4 commit 0e4cf12
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions ui/src/components/Boostagram/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,45 @@ export default class Boostagram extends React.PureComponent<IProps> {
}
}

const sendPayment = async (dest, amount, boostInfo, customRecords) => {
if (dest.type == 'lnaddress') {
const [username, hostname] = dest.address.split('@')

// load their well-known to find the lnurl callback address
let inforesp = await fetch(`https://${hostname}/.well-known/lnurlp/${username}`)
const info = await inforesp.json()

let comment = ""

if (boostInfo.message != "") {
comment += `${boostInfo.message}\n`
}

comment += `From ${boostInfo.sender_name} for ${boostInfo.podcast} - ${boostInfo.episode}`

// request an invoice from the callback
let params = new URLSearchParams({
amount: (amount * 1000).toString(),
comment: comment,
})

let invoiceresp = await fetch(info.callback + `?${params.toString()}`)
const invoice = await invoiceresp.json()

// pay invoice
await webln.sendPayment(invoice.pr)
}
else {
customRecords['7629169'] = JSON.stringify(boostInfo)

await webln.keysend({
destination: dest.address,
amount: amount,
customRecords: customRecords,
})
}
}

let feesDestinations = destinations.filter((v) => v.fee)
let splitsDestinations = destinations.filter((v) => !v.fee)
let runningTotal = this.state.satAmount
Expand Down Expand Up @@ -106,18 +145,14 @@ export default class Boostagram extends React.PureComponent<IProps> {
feeRecord.name = dest.name
feeRecord.value_msat = amount * 1000

let customRecords = { '7629169': JSON.stringify(feeRecord) }
let customRecords = {}

if (dest.customKey) {
customRecords[dest.customKey] = dest.customValue
}

try {
await webln.keysend({
destination: dest.address,
amount: amount,
customRecords: customRecords,
})
await sendPayment(dest, amount, feeRecord, customRecords)
} catch (err) {
alert(`error with ${dest.name}: ${err.message}`)
}
Expand All @@ -134,17 +169,13 @@ export default class Boostagram extends React.PureComponent<IProps> {
record.name = dest.name
record.value_msat = amount * 1000
if (amount >= 1) {
let customRecords = { '7629169': JSON.stringify(record) }
let customRecords = {}
if (dest.customKey) {
customRecords[dest.customKey] = dest.customValue
}

try {
await webln.keysend({
destination: dest.address,
amount: amount,
customRecords: customRecords,
})
await sendPayment(dest, amount, record, customRecords)
} catch (err) {
alert(`error with ${dest.name}: ${err.message}`)
}
Expand Down

0 comments on commit 0e4cf12

Please sign in to comment.