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.
This commit is contained in:
2026-07-11 18:08:33 -07:00
parent 0eab8a8ea2
commit e1d199931c
@@ -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)