diff --git a/index.html b/index.html index 5402d4d..9786baa 100644 --- a/index.html +++ b/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 = ` +
+
+
+ + Insufficient Balance +
+
+
+
+ Current Balance + ${currentBalance.toFixed(6)} ALGO +
+
+ Amount to Send + ${amount.toFixed(6)} ALGO +
+
+ Transaction Fee + ${feeAlgo.toFixed(6)} ALGO +
+
+ Total Required + ${totalAlgo.toFixed(6)} ALGO +
+
+ Shortfall + ${(totalAlgo - currentBalance).toFixed(6)} ALGO +
+
+
+ `; + outputEl.style.display = 'block'; + return; + } + // Store pending transaction data pendingTx = { from: fromAddress,