fix: Add another node, handle errors gracefully (#1433)
Adegoke David committed
May 6, 2024 at 20:11 UTC
2a88b32eee6a97c7528c25d5b822e904711d8783
3 files changed
+29
-6
assets/tron_node_list.yml
+4
@@ -1,4 +1,8 @@
1
-
2
uri: api.trongrid.io
3
is_default: true
4
+ useSSL: true
5
+-
6
+ uri: tron-rpc.publicnode.com:443
7
+ is_default: false
8
useSSL: true
\ No newline at end of file
cw_tron/lib/tron_client.dart
+8
-3
@@ -367,7 +367,7 @@ class TronClient {
367
) async {
368
// This is introduce to server as a limit in cases where feeLimit is 0
369
// The transaction signing will fail if the feeLimit is explicitly 0.
370
- int defaultFeeLimit = 100000;
370
+ int defaultFeeLimit = 269000;
371
372
final block = await _provider!.request(TronRequestGetNowBlock());
373
// Create the transfer contract
@@ -401,8 +401,9 @@ class TronClient {
401
final tronBalanceInt = tronBalance.toInt();
402
403
if (feeLimit > tronBalanceInt) {
404
+ final feeInTrx = TronHelper.fromSun(BigInt.parse(feeLimit.toString()));
405
throw Exception(
405
- 'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up.',
406
+ 'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up.\nTransaction fee: $feeInTrx TRX',
407
);
408
}
409
@@ -442,6 +443,9 @@ class TronClient {
443
444
if (!request.isSuccess) {
445
log("Tron TRC20 error: ${request.error} \n ${request.respose}");
446
+ throw Exception(
447
+ 'An error occured while creating the transfer request. Please try again.',
448
+ );
449
}
450
451
final feeLimit = await getFeeLimit(
@@ -454,8 +458,9 @@ class TronClient {
458
final tronBalanceInt = tronBalance.toInt();
459
460
if (feeLimit > tronBalanceInt) {
461
+ final feeInTrx = TronHelper.fromSun(BigInt.parse(feeLimit.toString()));
462
throw Exception(
458
- 'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up.',
463
+ 'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up. Transaction fee: $feeInTrx TRX',
464
);
465
}
466
lib/view_model/send/send_view_model.dart
+17
-3
@@ -247,7 +247,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
247
wallet.type != WalletType.banano &&
248
wallet.type != WalletType.solana &&
249
wallet.type != WalletType.tron;
250
-
250
+
251
@observable
252
CryptoCurrency selectedCryptoCurrency;
253
@@ -363,7 +363,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
363
} catch (e) {
364
if (e is LedgerException) {
365
final errorCode = e.errorCode.toRadixString(16);
366
- final fallbackMsg = e.message.isNotEmpty ? e.message : "Unexpected Ledger Error Code: $errorCode";
366
+ final fallbackMsg =
367
+ e.message.isNotEmpty ? e.message : "Unexpected Ledger Error Code: $errorCode";
368
final errorMsg = ledgerViewModel.interpretErrorCode(errorCode) ?? fallbackMsg;
369
370
state = FailureState(errorMsg);
@@ -444,7 +445,10 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
445
Object _credentials() {
446
final priority = _settingsStore.priority[wallet.type];
447
447
- if (priority == null && wallet.type != WalletType.nano && wallet.type != WalletType.banano && wallet.type != WalletType.solana &&
448
+ if (priority == null &&
449
+ wallet.type != WalletType.nano &&
450
+ wallet.type != WalletType.banano &&
451
+ wallet.type != WalletType.solana &&
452
wallet.type != WalletType.tron) {
453
throw Exception('Priority is null for wallet type: ${wallet.type}');
454
}
@@ -570,6 +574,16 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
574
return errorMessage;
575
}
576
577
+ if (walletType == WalletType.tron) {
578
+ if (errorMessage.contains('balance is not sufficient')) {
579
+ return S.current.do_not_have_enough_gas_asset(currency.toString());
580
+ }
581
+
582
+ if (errorMessage.contains('Transaction expired')) {
583
+ return 'An error occurred while processing the transaction. Kindly retry the transaction';
584
+ }
585
+ }
586
+
587
if (walletType == WalletType.bitcoin ||
588
walletType == WalletType.litecoin ||
589
walletType == WalletType.bitcoinCash) {