Pass config with spread operator
This commit is contained in:
parent
29646eb956
commit
7639390a16
|
@ -30,7 +30,7 @@ export function useWallet (name) {
|
||||||
const hash = bolt11Tags(bolt11).payment_hash
|
const hash = bolt11Tags(bolt11).payment_hash
|
||||||
logger.info('sending payment:', `payment_hash=${hash}`)
|
logger.info('sending payment:', `payment_hash=${hash}`)
|
||||||
try {
|
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}`)
|
logger.ok('payment successful:', `payment_hash=${hash}`, `preimage=${preimage}`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = err.message || err.toString?.()
|
const message = err.message || err.toString?.()
|
||||||
|
@ -49,12 +49,12 @@ export function useWallet (name) {
|
||||||
logger.info('wallet disabled')
|
logger.info('wallet disabled')
|
||||||
}, [name, me, logger])
|
}, [name, me, logger])
|
||||||
|
|
||||||
const save = useCallback(async (values) => {
|
const save = useCallback(async (config) => {
|
||||||
try {
|
try {
|
||||||
// validate should log custom INFO and OK message
|
// validate should log custom INFO and OK message
|
||||||
// TODO: add timeout
|
// TODO: add timeout
|
||||||
await wallet.validate({ logger, ...values })
|
await wallet.validate({ logger, ...config })
|
||||||
saveConfig(values)
|
saveConfig(config)
|
||||||
logger.ok('wallet attached')
|
logger.ok('wallet attached')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = err.message || err.toString?.()
|
const message = err.message || err.toString?.()
|
||||||
|
|
|
@ -22,8 +22,10 @@ export const card = {
|
||||||
badges: ['send only', 'non-custodialish']
|
badges: ['send only', 'non-custodialish']
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function validate ({ logger, ...config }) {
|
export async function validate ({ logger, url, adminKey }) {
|
||||||
return await getInfo({ logger, ...config })
|
logger.info('trying to fetch wallet')
|
||||||
|
await getWallet(url, adminKey)
|
||||||
|
logger.ok('wallet found')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const schema = object({
|
export const schema = object({
|
||||||
|
@ -51,28 +53,7 @@ export const schema = object({
|
||||||
adminKey: string().length(32)
|
adminKey: string().length(32)
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getInfo ({ logger, ...config }) {
|
export async function sendPayment ({ bolt11, url, adminKey }) {
|
||||||
logger.info('trying to fetch wallet')
|
|
||||||
const response = await getWallet(config.url, config.adminKey)
|
|
||||||
logger.ok('wallet found')
|
|
||||||
return {
|
|
||||||
node: {
|
|
||||||
alias: response.name,
|
|
||||||
pubkey: ''
|
|
||||||
},
|
|
||||||
methods: [
|
|
||||||
'getInfo',
|
|
||||||
'getBalance',
|
|
||||||
'sendPayment'
|
|
||||||
],
|
|
||||||
version: '1.0',
|
|
||||||
supports: ['lightning']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function sendPayment ({ bolt11, config }) {
|
|
||||||
const { url, adminKey } = config
|
|
||||||
|
|
||||||
const response = await postPayment(url, adminKey, bolt11)
|
const response = await postPayment(url, adminKey, bolt11)
|
||||||
|
|
||||||
const checkResponse = await getPayment(url, adminKey, response.payment_hash)
|
const checkResponse = await getPayment(url, adminKey, response.payment_hash)
|
||||||
|
|
|
@ -98,8 +98,8 @@ export async function validate ({ logger, nwcUrl }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendPayment ({ bolt11, config, logger }) {
|
export async function sendPayment ({ bolt11, nwcUrl, logger }) {
|
||||||
const { relayUrl, walletPubkey, secret } = parseNwcUrl(config.nwcUrl)
|
const { relayUrl, walletPubkey, secret } = parseNwcUrl(nwcUrl)
|
||||||
|
|
||||||
const relay = await Relay.connect(relayUrl).catch(() => {
|
const relay = await Relay.connect(relayUrl).catch(() => {
|
||||||
// NOTE: passed error is undefined for some reason
|
// NOTE: passed error is undefined for some reason
|
||||||
|
|
Loading…
Reference in New Issue