From cd8349ed6f33e0725af078742ad49c7caea2fe4d Mon Sep 17 00:00:00 2001 From: void-57 Date: Sat, 6 Dec 2025 13:53:42 +0530 Subject: [PATCH] feat: add minimum balance check before sending transactions and display detailed error UI --- index.html | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index ef55b23..819d758 100644 --- a/index.html +++ b/index.html @@ -1493,13 +1493,17 @@ // Get current balance const accountInfo = await algoAPI.getBalance(fromAddress); const currentBalance = accountInfo.balanceAlgo; + const minBalance = accountInfo.minBalance / 1000000; // Convert microAlgos to ALGO // Get transaction parameters const txParams = await algoAPI.getTransactionParams(); const feeAlgo = txParams.fee / 1000000; const totalAlgo = amount + feeAlgo; - // Check if balance is sufficient + // Calculate remaining balance after transaction + const remainingBalance = currentBalance - totalAlgo; + + // Check if balance is sufficient (must have enough for amount + fee) if (totalAlgo > currentBalance) { const errorMsg = `Insufficient balance! You need ${totalAlgo.toFixed(6)} ALGO (${amount.toFixed(6)} + ${feeAlgo.toFixed(6)} fee) but only have ${currentBalance.toFixed(6)} ALGO available.`; showNotification('❌ ' + errorMsg, 'error'); @@ -1542,6 +1546,54 @@ return; } + // Check if remaining balance meets minimum balance requirement + if (remainingBalance < minBalance) { + const maxSendable = currentBalance - minBalance - feeAlgo; + const errorMsg = `Transaction would leave account below minimum balance! Minimum balance required: ${minBalance.toFixed(6)} ALGO. After sending ${amount.toFixed(6)} ALGO + ${feeAlgo.toFixed(6)} fee, only ${remainingBalance.toFixed(6)} ALGO would remain.`; + showNotification('❌ ' + errorMsg, 'error'); + + // Show error in output area as well + const outputEl = document.getElementById('sendOutput'); + outputEl.innerHTML = ` +
+
+
+ + Below Minimum Balance +
+
+
+
+ Current Balance + ${currentBalance.toFixed(6)} ALGO +
+
+ Amount to Send + ${amount.toFixed(6)} ALGO +
+
+ Transaction Fee + ${feeAlgo.toFixed(6)} ALGO +
+
+ Remaining After TX + ${remainingBalance.toFixed(6)} ALGO +
+
+ Minimum Required + ${minBalance.toFixed(6)} ALGO +
+
+ Max You Can Send + ${maxSendable > 0 ? maxSendable.toFixed(6) : '0.000000'} ALGO +
+
+
+ `; + outputEl.style.display = 'block'; + return; + } + // Store pending transaction data pendingTx = { from: fromAddress,