Skip to content

Commit a36d1de

Browse files
authored
LIVE-3333 fix useAllAmount flow when fees are higher than balance (#918)
fix useAllAmount flow when fees are higher than balance
1 parent 1df2a06 commit a36d1de

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

.changeset/polite-phones-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ledgerhq/live-common": major
3+
---
4+
5+
fix useAllAmount usage when fees are higher than balance

libs/ledger-live-common/src/families/filecoin/bridge/account.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,19 @@ const getTransactionStatus = async (
8282
// This is the worst case scenario (the tx won't cost more than this value)
8383
const estimatedFees = calculateEstimatedFees(gasFeeCap, gasLimit);
8484

85-
const totalSpent = useAllAmount ? balance : amount.plus(estimatedFees);
86-
if (totalSpent.gt(a.spendableBalance)) {
87-
errors.amount = new NotEnoughBalance();
85+
let totalSpent;
86+
if (useAllAmount) {
87+
totalSpent = a.spendableBalance;
88+
amount = totalSpent.minus(estimatedFees);
89+
if (amount.lte(0) || totalSpent.gt(balance)) {
90+
errors.amount = new NotEnoughBalance();
91+
}
8892
} else {
89-
amount = useAllAmount ? balance.minus(estimatedFees) : amount;
90-
if (amount.lte(0)) errors.amount = new AmountRequired();
93+
totalSpent = amount.plus(estimatedFees);
94+
if (amount.eq(0)) {
95+
errors.amount = new AmountRequired();
96+
} else if (totalSpent.gt(a.spendableBalance))
97+
errors.amount = new NotEnoughBalance();
9198
}
9299

93100
// log("debug", "[getTransactionStatus] finish fn");

0 commit comments

Comments
 (0)