* Add timeout to all wallet API calls * Pass timeout signal to wallet API * Fix timeout error message not shown on timeout * Fix cross-fetch throws generic error message on abort * Fix wrong method in error message * Always use FetchTimeoutError * Catch NDK timeout error to replace with custom timeout error * Also use 15s for NWC connect timeout * Add timeout delay
17 lines
564 B
JavaScript
17 lines
564 B
JavaScript
import { getNwc, supportedMethods, nwcTryRun } from '@/wallets/nwc'
|
|
export * from '@/wallets/nwc'
|
|
|
|
export async function testSendPayment ({ nwcUrl }, { signal }) {
|
|
const supported = await supportedMethods(nwcUrl, { signal })
|
|
if (!supported.includes('pay_invoice')) {
|
|
throw new Error('pay_invoice not supported')
|
|
}
|
|
}
|
|
|
|
export async function sendPayment (bolt11, { nwcUrl }, { signal }) {
|
|
const nwc = await getNwc(nwcUrl, { signal })
|
|
// TODO: support AbortSignal
|
|
const result = await nwcTryRun(() => nwc.payInvoice(bolt11))
|
|
return result.preimage
|
|
}
|