Skip to content

Commit a8652e1

Browse files
committed
fix(transfer): #2451 check for minimum onchain balance
1 parent 12e0ae9 commit a8652e1

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/screens/Transfer/SpendingAmount.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ const SpendingAmount = ({
7373
const availableAmount = onchainBalance - transaction.fee;
7474
const { defaultLspBalance: maxLspBalance } = useTransfer(availableAmount);
7575
const { fee: maxLspFee } = useTransferFee(maxLspBalance, availableAmount);
76-
const feeMaximum = Math.floor(availableAmount - maxLspFee);
76+
const feeMaximum = Math.max(0, Math.floor(availableAmount - maxLspFee));
7777
const maximum = Math.min(maxClientBalance, feeMaximum);
78+
const fee = transaction.fee + maxLspFee;
7879

7980
useFocusEffect(
8081
// biome-ignore lint/correctness/useExhaustiveDependencies: onMount
@@ -116,7 +117,30 @@ const SpendingAmount = ({
116117
setTextFieldValue(result);
117118
};
118119

120+
const checkFeeMinimum = (): boolean => {
121+
if (fee > availableAmount) {
122+
const roundedFee = Math.ceil(fee / 1000) * 1000;
123+
const dv = getDisplayValues({ satoshis: roundedFee });
124+
const description = t('spending_amount.error_min.description', {
125+
amount: dv.bitcoinFormatted,
126+
});
127+
128+
showToast({
129+
type: 'warning',
130+
title: t('spending_amount.error_min.title'),
131+
description,
132+
});
133+
134+
return true;
135+
}
136+
return false;
137+
};
138+
119139
const onNumberPadError = (): void => {
140+
if (checkFeeMinimum()) {
141+
return;
142+
}
143+
120144
const dv = getDisplayValues({ satoshis: maximum });
121145
let description = t('spending_amount.error_max.description', {
122146
amount: dv.bitcoinFormatted,
@@ -134,6 +158,10 @@ const SpendingAmount = ({
134158
};
135159

136160
const onContinue = async (): Promise<void> => {
161+
if (checkFeeMinimum()) {
162+
return;
163+
}
164+
137165
setLoading(true);
138166

139167
const lspBalance = Math.max(defaultLspBalance, minLspBalance);

src/utils/i18n/locales/en/lightning.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@
113113
"quarter": {
114114
"string": "25%"
115115
},
116+
"error_min": {
117+
"title": {
118+
"string": "Savings Balance Minimum"
119+
},
120+
"description": {
121+
"string": "A minimum of ₿ {amount} is needed to set up your spending balance."
122+
}
123+
},
116124
"error_max": {
117125
"title": {
118126
"string": "Spending Balance Maximum"

0 commit comments

Comments
 (0)