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
|
||||
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?.()
|
||||
|
@ -49,12 +49,12 @@ export function useWallet (name) {
|
|||
logger.info('wallet disabled')
|
||||
}, [name, me, logger])
|
||||
|
||||
const save = useCallback(async (values) => {
|
||||
const save = useCallback(async (config) => {
|
||||
try {
|
||||
// validate should log custom INFO and OK message
|
||||
// TODO: add timeout
|
||||
await wallet.validate({ logger, ...values })
|
||||
saveConfig(values)
|
||||
await wallet.validate({ logger, ...config })
|
||||
saveConfig(config)
|
||||
logger.ok('wallet attached')
|
||||
} catch (err) {
|
||||
const message = err.message || err.toString?.()
|
||||
|
|
|
@ -22,8 +22,10 @@ export const card = {
|
|||
badges: ['send only', 'non-custodialish']
|
||||
}
|
||||
|
||||
export async function validate ({ logger, ...config }) {
|
||||
return await getInfo({ logger, ...config })
|
||||
export async function validate ({ logger, url, adminKey }) {
|
||||
logger.info('trying to fetch wallet')
|
||||
await getWallet(url, adminKey)
|
||||
logger.ok('wallet found')
|
||||
}
|
||||
|
||||
export const schema = object({
|
||||
|
@ -51,28 +53,7 @@ export const schema = object({
|
|||
adminKey: string().length(32)
|
||||
})
|
||||
|
||||
async function getInfo ({ logger, ...config }) {
|
||||
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
|
||||
|
||||
export async function sendPayment ({ bolt11, url, adminKey }) {
|
||||
const response = await postPayment(url, adminKey, bolt11)
|
||||
|
||||
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 }) {
|
||||
const { relayUrl, walletPubkey, secret } = parseNwcUrl(config.nwcUrl)
|
||||
export async function sendPayment ({ bolt11, nwcUrl, logger }) {
|
||||
const { relayUrl, walletPubkey, secret } = parseNwcUrl(nwcUrl)
|
||||
|
||||
const relay = await Relay.connect(relayUrl).catch(() => {
|
||||
// NOTE: passed error is undefined for some reason
|
||||
|
|
Loading…
Reference in New Issue