9c55f1ebe2
* lnurlp paid action * lnurlp has 10% sybil fee * fix merge issue * Update pages/settings/index.js Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> * fix notifications * fix destructure * pass lud18Data to lnurlp action * minor cleanup * truncate invoice description to permitted length * remove redundant targetUserId * lnurlp paidAction -> receive paidAction * remove redundant user query * improve determining if peer is invoiceable * fix inconsistent relative imports * prevent paying self-proxied invoices and better held invoice cancellation * make gun/horse streak zap specific * unique withdrawal hash should apply to confirmed payments too * prevent receive from exceeding wallet limits * notifications * fix notifications & enhance invoice/withdrawl page * notification indicator, proxy receive based on threshold, refinements --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: k00b <k00b@stacker.news>
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { datePivot } from '@/lib/time'
|
|
import { authenticatedLndGrpc } from '@/lib/lnd'
|
|
import { createInvoice as lndCreateInvoice } from 'ln-service'
|
|
import { TOR_REGEXP } from '@/lib/url'
|
|
|
|
export * from '@/wallets/lnd'
|
|
|
|
export const testCreateInvoice = async ({ cert, macaroon, socket }) => {
|
|
return await createInvoice({ msats: 1000, expiry: 1 }, { cert, macaroon, socket })
|
|
}
|
|
|
|
export const createInvoice = async (
|
|
{ msats, description, descriptionHash, expiry },
|
|
{ cert, macaroon, socket }
|
|
) => {
|
|
try {
|
|
const isOnion = TOR_REGEXP.test(socket)
|
|
|
|
const { lnd } = await authenticatedLndGrpc({
|
|
cert,
|
|
macaroon,
|
|
socket
|
|
}, isOnion)
|
|
|
|
const invoice = await lndCreateInvoice({
|
|
lnd,
|
|
description,
|
|
description_hash: descriptionHash,
|
|
mtokens: String(msats),
|
|
expires_at: datePivot(new Date(), { seconds: expiry })
|
|
})
|
|
|
|
return invoice.request
|
|
} catch (err) {
|
|
// LND errors can be in this shape: [code, type, { err: { code, details, metadata } }]
|
|
const details = err[2]?.err?.details || err.message || err.toString?.()
|
|
throw new Error(details)
|
|
}
|
|
}
|