Fix autowithdraw loop
This commit is contained in:
parent
bd0e4d906c
commit
6bee659f2f
|
@ -40,7 +40,7 @@ export async function autoWithdraw ({ data: { id }, models, lnd }) {
|
||||||
|
|
||||||
// get the wallets in order of priority
|
// get the wallets in order of priority
|
||||||
const wallets = await models.wallet.findMany({
|
const wallets = await models.wallet.findMany({
|
||||||
where: { userId: user.id },
|
where: { userId: user.id, enabled: true },
|
||||||
orderBy: [
|
orderBy: [
|
||||||
{ priority: 'desc' },
|
{ priority: 'desc' },
|
||||||
// use id as tie breaker (older wallet first)
|
// use id as tie breaker (older wallet first)
|
||||||
|
@ -49,27 +49,14 @@ export async function autoWithdraw ({ data: { id }, models, lnd }) {
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const wallet of wallets) {
|
for (const wallet of wallets) {
|
||||||
|
const w = SERVER_WALLET_DEFS.find(({ default: w }) => w.server.walletType === wallet.type)
|
||||||
try {
|
try {
|
||||||
for (const w of SERVER_WALLET_DEFS) {
|
const { server: { walletType, walletField, createInvoice } } = w.default
|
||||||
const { server: { walletType, walletField, createInvoice } } = w.default || w
|
return await autowithdraw(
|
||||||
if (wallet.type === walletType) {
|
{ walletType, walletField, createInvoice },
|
||||||
await autowithdraw(
|
{ amount, maxFee },
|
||||||
{ walletType, walletField, createInvoice },
|
{ me: user, models, lnd }
|
||||||
{ amount, maxFee },
|
)
|
||||||
{ me: user, models, lnd }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: implement CLN autowithdrawal
|
|
||||||
// ------
|
|
||||||
// if (wallet.type === Wallet.CLN.type) {
|
|
||||||
// await autowithdrawCLN(
|
|
||||||
// { amount, maxFee },
|
|
||||||
// { models, me: user, lnd })
|
|
||||||
// }
|
|
||||||
|
|
||||||
return
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
// LND errors are in this shape: [code, type, { err: { code, details, metadata } }]
|
// LND errors are in this shape: [code, type, { err: { code, details, metadata } }]
|
||||||
|
|
Loading…
Reference in New Issue