Riccardo Balbo 9c55f1ebe2
Implement deposit as receive paidAction (#1570)
* 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>
2024-11-15 18:38:14 -06:00

34 lines
927 B
JavaScript

import { msatsSatsFloor } from '@/lib/format'
import { lnAddrOptions } from '@/lib/lnurl'
export * from '@/wallets/lightning-address'
export const testCreateInvoice = async ({ address }) => {
return await createInvoice({ msats: 1000 }, { address })
}
export const createInvoice = async (
{ msats, description },
{ address }
) => {
const { callback, commentAllowed } = await lnAddrOptions(address)
const callbackUrl = new URL(callback)
// most lnurl providers suck nards so we have to floor to nearest sat
msats = msatsSatsFloor(msats)
callbackUrl.searchParams.append('amount', msats)
if (commentAllowed >= description?.length) {
callbackUrl.searchParams.append('comment', description)
}
// call callback with amount and conditionally comment
const res = await (await fetch(callbackUrl.toString())).json()
if (res.status === 'ERROR') {
throw new Error(res.reason)
}
return res.pr
}