From 5eb78a4d81d555187ab7fafc9935e0ef3b46174e Mon Sep 17 00:00:00 2001 From: aaron <> Date: Sat, 24 Jan 2026 22:31:49 +0800 Subject: [PATCH] update --- app.js | 22 +++++++++++++++++++--- utils.js | 13 +++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 8974d73..ba8df31 100644 --- a/app.js +++ b/app.js @@ -246,7 +246,9 @@ class BatchTransferApp { async updateGasPrice() { try { const gasPrice = await window.BatchTransfer.getGasPrice(); + console.log('获取到的Gas价格 (Gwei):', gasPrice); this.gasPrice.value = window.TransferUtils.formatNumber(parseFloat(gasPrice), 2); + console.log('设置的Gas价格值:', this.gasPrice.value); this.updateSummary(); } catch (error) { console.error('获取Gas价格失败:', error); @@ -461,10 +463,15 @@ class BatchTransferApp { this.totalAmount.textContent = window.TransferUtils.formatNumber(totalAmount, 4); // 计算Gas费用 - if (window.BatchTransfer.provider && this.gasPrice.value) { + if (window.BatchTransfer.provider && this.gasPrice.value && parseFloat(this.gasPrice.value) > 0) { const gasPrice = parseFloat(this.gasPrice.value); const gasLimit = parseInt(this.gasLimit.value); + console.log('开始计算Gas费用:'); + console.log('- 转账数量:', this.transferData.length); + console.log('- Gas价格 (Gwei):', gasPrice); + console.log('- Gas限制:', gasLimit); + try { const cost = await window.BatchTransfer.calculateTotalCost( this.transferData, @@ -473,11 +480,20 @@ class BatchTransferApp { this.isTokenTransfer ); - this.estimatedGas.textContent = window.TransferUtils.formatNumber(cost.totalGasCost, 4); - this.totalCost.textContent = window.TransferUtils.formatNumber(cost.totalCost, 4); + console.log('计算结果:'); + console.log('- 总Gas费用 (BNB):', cost.totalGasCost); + console.log('- 总成本 (BNB):', cost.totalCost); + + this.estimatedGas.textContent = window.TransferUtils.formatNumber(cost.totalGasCost, 8); + this.totalCost.textContent = window.TransferUtils.formatNumber(cost.totalCost, 8); } catch (error) { console.error('计算Gas费用失败:', error); } + } else { + console.log('无法计算Gas费用:'); + console.log('- Provider存在:', !!window.BatchTransfer.provider); + console.log('- Gas价格值:', this.gasPrice.value); + console.log('- Gas价格>0:', parseFloat(this.gasPrice.value) > 0); } // 启用开始按钮 diff --git a/utils.js b/utils.js index da68378..e442f90 100644 --- a/utils.js +++ b/utils.js @@ -35,8 +35,17 @@ class TransferUtils { } static formatNumber(num, decimals = 4) { - if (isNaN(num)) return '0'; - return parseFloat(num.toFixed(decimals)).toString(); + // 处理各种输入类型 + if (num === null || num === undefined) return '0'; + + // 转换为数字 + const numValue = typeof num === 'string' ? parseFloat(num) : Number(num); + + // 检查是否为有效数字 + if (isNaN(numValue)) return '0'; + + // 格式化并返回 + return parseFloat(numValue.toFixed(decimals)).toString(); } static generateLogMessage(type, message) {