feat: Add private key input validation and implement insufficient balance check for ALGO transactions.
This commit is contained in:
parent
3358208817
commit
3c93a8637e
64
index.html
64
index.html
@ -788,6 +788,23 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate input - reject addresses, only accept private keys
|
||||
const hexOnly = /^[0-9a-fA-F]+$/.test(privateKey);
|
||||
const isHexKey = hexOnly && (privateKey.length === 64 || privateKey.length === 128);
|
||||
const isBase58Key = !hexOnly && privateKey.length >= 50;
|
||||
|
||||
// Check if it looks like an address (ALGO address is 58 chars, BTC/FLO addresses are shorter)
|
||||
if (privateKey.length === 58 || (privateKey.length >= 25 && privateKey.length <= 35 && !isBase58Key)) {
|
||||
showNotification('⚠️ Addresses are not allowed. Please enter a BTC/FLO/ALGO private key', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate private key format
|
||||
if (!isHexKey && !isBase58Key) {
|
||||
showNotification('⚠️ Invalid private key format. Please enter a valid BTC/FLO/ALGO private key', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
showLoading(true);
|
||||
const result = await algoCrypto.generateMultiChain(privateKey);
|
||||
@ -1428,11 +1445,58 @@
|
||||
const fromAddress = walletResult.ALGO.address;
|
||||
const algoPrivateKey = walletResult.ALGO.privateKey;
|
||||
|
||||
// Get current balance
|
||||
const accountInfo = await algoAPI.getBalance(fromAddress);
|
||||
const currentBalance = accountInfo.balanceAlgo;
|
||||
|
||||
// Get transaction parameters
|
||||
const txParams = await algoAPI.getTransactionParams();
|
||||
const feeAlgo = txParams.fee / 1000000;
|
||||
const totalAlgo = amount + feeAlgo;
|
||||
|
||||
// Check if balance is sufficient
|
||||
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');
|
||||
|
||||
// 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>Insufficient 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(--error-color);">
|
||||
<span class="detail-label">Total Required</span>
|
||||
<span class="detail-value">${totalAlgo.toFixed(6)} ALGO</span>
|
||||
</div>
|
||||
<div class="tx-detail-row" style="color: var(--error-color); font-weight: 600;">
|
||||
<span class="detail-label">Shortfall</span>
|
||||
<span class="detail-value">${(totalAlgo - currentBalance).toFixed(6)} 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