From fc6e0832571b677332572757b2371262c0a2bc66 Mon Sep 17 00:00:00 2001 From: Philipp Walter Date: Thu, 8 Feb 2024 14:10:22 +0100 Subject: [PATCH] fix(lightning): use min0ConfTxFee only for orders with 0 client balance --- src/screens/Lightning/CustomSetup.tsx | 3 +++ src/store/utils/blocktank.ts | 31 +++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/screens/Lightning/CustomSetup.tsx b/src/screens/Lightning/CustomSetup.tsx index 357461509..ccbedb8b1 100644 --- a/src/screens/Lightning/CustomSetup.tsx +++ b/src/screens/Lightning/CustomSetup.tsx @@ -274,6 +274,9 @@ const CustomSetup = ({ } const getChannelOpenCost = async (): Promise => { + if (amount === 0) { + return; + } const res = await estimateOrderFee({ lspBalanceSat: amount, channelExpiryWeeks: DEFAULT_CHANNEL_DURATION, diff --git a/src/store/utils/blocktank.ts b/src/store/utils/blocktank.ts index 2c1910d5b..3793a98dc 100644 --- a/src/store/utils/blocktank.ts +++ b/src/store/utils/blocktank.ts @@ -2,7 +2,12 @@ import { err, ok, Result } from '@synonymdev/result'; import { resetSendTransaction, updateSendTransaction } from '../actions/wallet'; import { setLightningSetupStep } from '../slices/user'; -import { getBlocktankStore, getWalletStore, dispatch } from '../helpers'; +import { + getBlocktankStore, + getWalletStore, + dispatch, + getFeesStore, +} from '../helpers'; import * as blocktank from '../../utils/blocktank'; import { createOrder, @@ -276,14 +281,20 @@ export const startChannelPurchase = async ({ } const { onchainBalance } = getBalance({ selectedNetwork, selectedWallet }); - const min0ConfTxFee = await getMin0ConfTxFee(orderData.value.id); - if (min0ConfTxFee.isErr()) { - return err(min0ConfTxFee.error.message); + + // Get transaction fee + const fees = getFeesStore().onchain; + let satPerVByteFee = fees.fast; + if (remoteBalance === 0) { + // For orders with 0 client balance, we use the min 0-conf tx fee from BT to get a turbo channel. + const min0ConfTxFee = await getMin0ConfTxFee(orderData.value.id); + if (min0ConfTxFee.isErr()) { + return err(min0ConfTxFee.error.message); + } + satPerVByteFee = Math.ceil(min0ConfTxFee.value.satPerVByte); // might be float } - const satPerVByteFee = Math.ceil(min0ConfTxFee.value.satPerVByte); // might be float - let txFeeInSats = getTotalFee({ - satsPerByte: satPerVByteFee, - }); + + let txFeeInSats = getTotalFee({ satsPerByte: satPerVByteFee }); const buyChannelDataFeeSat = Math.ceil(buyChannelData.feeSat); const buyChannelDataClientBalanceFeeSat = Math.ceil( buyChannelData.clientBalanceSat, @@ -316,9 +327,7 @@ export const startChannelPurchase = async ({ }, }); - const feeRes = updateFee({ - satsPerByte: satPerVByteFee, - }); + const feeRes = updateFee({ satsPerByte: satPerVByteFee }); if (feeRes.isErr()) { return err(feeRes.error.message); }