Skip to content

Commit 5b4801f

Browse files
committed
fix: NaN on Transfer/Confirm screen with 0 onchain balance
1 parent 529dc27 commit 5b4801f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/screens/Transfer/Confirm.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import SwipeToConfirm from '../../components/SwipeToConfirm';
1414
import PieChart from '../Lightning/PieChart';
1515
import { addTodo, removeTodo } from '../../store/actions/todos';
1616
import { confirmChannelPurchase } from '../../store/actions/blocktank';
17-
import { useLightningBalance } from '../../hooks/lightning';
1817
import { useBalance } from '../../hooks/wallet';
1918
import useDisplayValues from '../../hooks/displayValues';
2019
import type { TransferScreenProps } from '../../navigation/types';
@@ -34,20 +33,21 @@ const Confirm = ({
3433
const { spendingAmount, orderId } = route.params;
3534
const { t } = useTranslation('lightning');
3635
const { satoshis: onchainBalance } = useBalance({ onchain: true });
36+
const { satoshis: lightningBalance } = useBalance({
37+
lightning: true,
38+
subtractReserveBalance: false,
39+
});
3740
const [loading, setLoading] = useState(false);
38-
const lightningBalance = useLightningBalance();
3941

40-
const savingsAmount = onchainBalance - spendingAmount;
41-
const savingsPercentage = Math.round((savingsAmount / onchainBalance) * 100);
42-
const spendingPercentage = Math.round(
43-
(spendingAmount / onchainBalance) * 100,
44-
);
45-
const currentSpendingAmount = lightningBalance.localBalance;
42+
const totalBalance = onchainBalance + lightningBalance;
43+
const savingsAmount = totalBalance - spendingAmount;
44+
const savingsPercentage = Math.round((savingsAmount / totalBalance) * 100);
45+
const spendingPercentage = Math.round((spendingAmount / totalBalance) * 100);
4646
const spendingCurrentPercentage = Math.round(
47-
(currentSpendingAmount / onchainBalance) * 100,
47+
(lightningBalance / totalBalance) * 100,
4848
);
4949

50-
const isTransferringToSavings = spendingAmount < currentSpendingAmount;
50+
const isTransferringToSavings = spendingAmount < lightningBalance;
5151

5252
const selectedNetwork = useSelector(selectedNetworkSelector);
5353
const orders = useSelector(blocktankOrdersSelector);

0 commit comments

Comments
 (0)