From e1d199931c81e91046e1815527e55f6efbad0202 Mon Sep 17 00:00:00 2001 From: Satoshi Qazi Muhammed Date: Sat, 11 Jul 2026 18:08:33 -0700 Subject: [PATCH] fix: native TRX fee estimation crashes when amount is not yet entered TronGrid's createtransaction rejects amount=0 with a ContractValidateException. estimateNativeFee called it unguarded (unlike the TRC-20 path, which already wraps its dry run in runCatching), so the send screen's reactive fee loader surfaced this as a generic "Network not responding" error whenever it ran before the user typed an amount - found live testing the send flow end-to-end. --- .../network/tron/transaction/RealTronTransactionService.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/feature-wallet-impl/src/main/java/io/novafoundation/nova/feature_wallet_impl/data/network/tron/transaction/RealTronTransactionService.kt b/feature-wallet-impl/src/main/java/io/novafoundation/nova/feature_wallet_impl/data/network/tron/transaction/RealTronTransactionService.kt index 2568dc1e..19ce0546 100644 --- a/feature-wallet-impl/src/main/java/io/novafoundation/nova/feature_wallet_impl/data/network/tron/transaction/RealTronTransactionService.kt +++ b/feature-wallet-impl/src/main/java/io/novafoundation/nova/feature_wallet_impl/data/network/tron/transaction/RealTronTransactionService.kt @@ -208,7 +208,12 @@ class RealTronTransactionService( } private suspend fun estimateNativeFee(baseUrl: String, ownerHex: String, recipient: AccountId, amountSun: BigInteger): BigInteger { - val unsigned = tronGridApi.createNativeTransfer(baseUrl, ownerHex, recipient.toTronHexAddress(), amountSun) + // TronGrid's createtransaction rejects amount=0 outright with a ContractValidateException (confirmed + // live) - the send screen's fee loader calls calculateFee reactively as the user types, including before + // any amount has been entered. Substitute a minimal placeholder purely for this dry-run construction call; + // it does not affect the real amount used when the transfer is actually built in transact(). + val dryRunAmountSun = amountSun.takeIf { it > BigInteger.ZERO } ?: BigInteger.ONE + val unsigned = tronGridApi.createNativeTransfer(baseUrl, ownerHex, recipient.toTronHexAddress(), dryRunAmountSun) val txSizeBytes = requireNotNull(unsigned.rawDataHex) { "TronGrid returned no raw_data_hex" }.length / 2 val resource = runCatching { tronGridApi.getAccountResource(baseUrl, ownerHex) }.getOrDefault(EMPTY_RESOURCE)