From 61db299c4623952eb3623b80131a28f0da1ccbc1 Mon Sep 17 00:00:00 2001 From: Alexandre Alouit Date: Fri, 13 May 2022 19:20:37 +0200 Subject: [PATCH] LIVE-1560 Fix Algorand NotEnoughBalance errors in bot Estimate fees to estimateMaxSpendable --- src/families/algorand/js-estimateMaxSpendable.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/families/algorand/js-estimateMaxSpendable.ts b/src/families/algorand/js-estimateMaxSpendable.ts index 8fd9a3e18a..d82acdc7c6 100644 --- a/src/families/algorand/js-estimateMaxSpendable.ts +++ b/src/families/algorand/js-estimateMaxSpendable.ts @@ -5,6 +5,7 @@ import type { AlgorandTransaction } from "./types"; import { computeAlgoMaxSpendable } from "./logic"; import { createTransaction } from "./js-prepareTransaction"; import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets"; +import { getEstimatedFees } from "./js-getFeesForTransaction"; export const estimateMaxSpendable = async ({ account, @@ -38,14 +39,16 @@ export const estimateMaxSpendable = async ({ if (tokenAccount) { return tokenAccount.balance; } else { + const fees = await getEstimatedFees(mainAccount, tx); + let maxSpendable = computeAlgoMaxSpendable({ accountBalance: mainAccount.balance, nbAccountAssets: algorandResources.nbAssets, mode: tx.mode, }); - if (tx.fees) { - maxSpendable = maxSpendable.minus(tx.fees); - } + + maxSpendable = maxSpendable.minus(fees); + return maxSpendable.gte(0) ? maxSpendable : new BigNumber(0); } };