Split arguments into [value,] config, context
This commit is contained in:
parent
0ebe097a70
commit
6463e6eec8
|
@ -40,7 +40,7 @@ export function useWallet (name) {
|
|||
const hash = bolt11Tags(bolt11).payment_hash
|
||||
logger.info('sending payment:', `payment_hash=${hash}`)
|
||||
try {
|
||||
const { preimage } = await wallet.sendPayment({ bolt11, ...config, logger })
|
||||
const { preimage } = await wallet.sendPayment(bolt11, config, { logger })
|
||||
logger.ok('payment successful:', `payment_hash=${hash}`, `preimage=${preimage}`)
|
||||
} catch (err) {
|
||||
const message = err.message || err.toString?.()
|
||||
|
@ -70,7 +70,7 @@ export function useWallet (name) {
|
|||
// validate should log custom INFO and OK message
|
||||
// validate is optional since validation might happen during save on server
|
||||
// TODO: add timeout
|
||||
await wallet.validate?.({ me, logger, ...newConfig })
|
||||
await wallet.validate?.(newConfig, { me, logger })
|
||||
await saveConfig(newConfig)
|
||||
logger.ok(_isConfigured ? 'wallet updated' : 'wallet attached')
|
||||
} catch (err) {
|
||||
|
|
|
@ -21,18 +21,18 @@ export const card = {
|
|||
badges: ['send only', 'non-custodialish']
|
||||
}
|
||||
|
||||
export async function validate ({ logger, url, adminKey }) {
|
||||
export async function validate ({ url, adminKey }, { logger }) {
|
||||
logger.info('trying to fetch wallet')
|
||||
await getWallet(url, adminKey)
|
||||
await getWallet({ url, adminKey })
|
||||
logger.ok('wallet found')
|
||||
}
|
||||
|
||||
export const schema = lnbitsSchema
|
||||
|
||||
export async function sendPayment ({ bolt11, url, adminKey }) {
|
||||
const response = await postPayment(url, adminKey, bolt11)
|
||||
export async function sendPayment (bolt11, { url, adminKey }) {
|
||||
const response = await postPayment(bolt11, { url, adminKey })
|
||||
|
||||
const checkResponse = await getPayment(url, adminKey, response.payment_hash)
|
||||
const checkResponse = await getPayment(response.payment_hash, { url, adminKey })
|
||||
if (!checkResponse.preimage) {
|
||||
throw new Error('No preimage')
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ export async function sendPayment ({ bolt11, url, adminKey }) {
|
|||
return { preimage }
|
||||
}
|
||||
|
||||
async function getWallet (baseUrl, adminKey) {
|
||||
const url = baseUrl.replace(/\/+$/, '')
|
||||
async function getWallet ({ url, adminKey }) {
|
||||
url = url.replace(/\/+$/, '')
|
||||
const path = '/api/v1/wallet'
|
||||
|
||||
const headers = new Headers()
|
||||
|
@ -60,8 +60,8 @@ async function getWallet (baseUrl, adminKey) {
|
|||
return wallet
|
||||
}
|
||||
|
||||
async function postPayment (baseUrl, adminKey, bolt11) {
|
||||
const url = baseUrl.replace(/\/+$/, '')
|
||||
async function postPayment (bolt11, { url, adminKey }) {
|
||||
url = url.replace(/\/+$/, '')
|
||||
const path = '/api/v1/payments'
|
||||
|
||||
const headers = new Headers()
|
||||
|
@ -81,8 +81,8 @@ async function postPayment (baseUrl, adminKey, bolt11) {
|
|||
return payment
|
||||
}
|
||||
|
||||
async function getPayment (baseUrl, adminKey, paymentHash) {
|
||||
const url = baseUrl.replace(/\/+$/, '')
|
||||
async function getPayment (paymentHash, { url, adminKey }) {
|
||||
url = url.replace(/\/+$/, '')
|
||||
const path = `/api/v1/payments/${paymentHash}`
|
||||
|
||||
const headers = new Headers()
|
||||
|
|
|
@ -33,7 +33,7 @@ export const card = {
|
|||
|
||||
const XXX_DEFAULT_PASSWORD = 'password'
|
||||
|
||||
export async function validate ({ me, logger, pairingPhrase, password }) {
|
||||
export async function validate ({ pairingPhrase, password }, { me, logger }) {
|
||||
const lnc = await getLNC({ me })
|
||||
try {
|
||||
lnc.credentials.pairingPhrase = pairingPhrase
|
||||
|
@ -61,7 +61,7 @@ export const schema = lncSchema
|
|||
|
||||
const mutex = new Mutex()
|
||||
|
||||
async function unlock ({ lnc, password, status, showModal, logger }) {
|
||||
async function unlock ({ password }, { lnc, status, showModal, logger }) {
|
||||
if (status === Status.Enabled) return password
|
||||
|
||||
return await new Promise((resolve, reject) => {
|
||||
|
@ -103,7 +103,7 @@ async function unlock ({ lnc, password, status, showModal, logger }) {
|
|||
}
|
||||
|
||||
// FIXME: pass me, status, showModal in useWallet hook
|
||||
export async function sendPayment ({ bolt11, pairingPhrase, password: configuredPassword, me, status, showModal, logger }) {
|
||||
export async function sendPayment (bolt11, { pairingPhrase, password: configuredPassword }, { me, status, showModal, logger }) {
|
||||
const hash = bolt11Tags(bolt11).payment_hash
|
||||
|
||||
return await mutex.runExclusive(async () => {
|
||||
|
@ -111,7 +111,7 @@ export async function sendPayment ({ bolt11, pairingPhrase, password: configured
|
|||
try {
|
||||
lnc = await getLNC({ me })
|
||||
// TODO: pass status, showModal to unlock
|
||||
const password = await unlock({ lnc, password: configuredPassword, status, showModal, logger })
|
||||
const password = await unlock({ password: configuredPassword }, { lnc, status, showModal, logger })
|
||||
// credentials need to be decrypted before connecting after a disconnect
|
||||
lnc.credentials.password = password || XXX_DEFAULT_PASSWORD
|
||||
await lnc.connect()
|
||||
|
|
|
@ -20,7 +20,7 @@ export const card = {
|
|||
|
||||
export const schema = nwcSchema
|
||||
|
||||
export async function validate ({ logger, nwcUrl }) {
|
||||
export async function validate ({ nwcUrl }, { logger }) {
|
||||
const { relayUrl, walletPubkey } = parseNwcUrl(nwcUrl)
|
||||
|
||||
logger.info(`requesting info event from ${relayUrl}`)
|
||||
|
@ -73,7 +73,7 @@ export async function validate ({ logger, nwcUrl }) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function sendPayment ({ bolt11, nwcUrl, logger }) {
|
||||
export async function sendPayment (bolt11, { nwcUrl }, { logger }) {
|
||||
const { relayUrl, walletPubkey, secret } = parseNwcUrl(nwcUrl)
|
||||
|
||||
const relay = await Relay.connect(relayUrl).catch(() => {
|
||||
|
|
Loading…
Reference in New Issue