diff --git a/components/wallet/index.js b/components/wallet/index.js index 8c8466ae..4f0bf392 100644 --- a/components/wallet/index.js +++ b/components/wallet/index.js @@ -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) { diff --git a/components/wallet/lnbits.js b/components/wallet/lnbits.js index c1bd0cd1..b791dab9 100644 --- a/components/wallet/lnbits.js +++ b/components/wallet/lnbits.js @@ -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() diff --git a/components/wallet/lnc.js b/components/wallet/lnc.js index 54f9ab14..ecb744b0 100644 --- a/components/wallet/lnc.js +++ b/components/wallet/lnc.js @@ -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() diff --git a/components/wallet/nwc.js b/components/wallet/nwc.js index 3773be77..5ac798ec 100644 --- a/components/wallet/nwc.js +++ b/components/wallet/nwc.js @@ -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(() => {