feat: add minimum balance check before sending transactions and display detailed error UI
This commit is contained in:
parent
2430b2d687
commit
cd8349ed6f
54
index.html
54
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 = `
|
||||
<div class="tx-details-card card" style="border-left: 4px solid var(--error-color);">
|
||||
<div class="tx-details-header">
|
||||
<div class="tx-status" style="color: var(--error-color);">
|
||||
<i class="fa-solid fa-circle-exclamation"></i>
|
||||
<span>Below Minimum Balance</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tx-details-body">
|
||||
<div class="tx-detail-row">
|
||||
<span class="detail-label">Current Balance</span>
|
||||
<span class="detail-value">${currentBalance.toFixed(6)} ALGO</span>
|
||||
</div>
|
||||
<div class="tx-detail-row">
|
||||
<span class="detail-label">Amount to Send</span>
|
||||
<span class="detail-value">${amount.toFixed(6)} ALGO</span>
|
||||
</div>
|
||||
<div class="tx-detail-row">
|
||||
<span class="detail-label">Transaction Fee</span>
|
||||
<span class="detail-value fee">${feeAlgo.toFixed(6)} ALGO</span>
|
||||
</div>
|
||||
<div class="tx-detail-row highlight" style="color: var(--warning-color);">
|
||||
<span class="detail-label">Remaining After TX</span>
|
||||
<span class="detail-value">${remainingBalance.toFixed(6)} ALGO</span>
|
||||
</div>
|
||||
<div class="tx-detail-row" style="color: var(--error-color); font-weight: 600;">
|
||||
<span class="detail-label">Minimum Required</span>
|
||||
<span class="detail-value">${minBalance.toFixed(6)} ALGO</span>
|
||||
</div>
|
||||
<div class="tx-detail-row" style="color: var(--success-color); font-weight: 600;">
|
||||
<span class="detail-label">Max You Can Send</span>
|
||||
<span class="detail-value">${maxSendable > 0 ? maxSendable.toFixed(6) : '0.000000'} ALGO</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
outputEl.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
// Store pending transaction data
|
||||
pendingTx = {
|
||||
from: fromAddress,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user