mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
fix: Add another node, handle errors gracefully (#1433)
This commit is contained in:
parent
55cdec810e
commit
2a88b32eee
3 changed files with 29 additions and 6 deletions
|
@ -1,4 +1,8 @@
|
||||||
-
|
-
|
||||||
uri: api.trongrid.io
|
uri: api.trongrid.io
|
||||||
is_default: true
|
is_default: true
|
||||||
|
useSSL: true
|
||||||
|
-
|
||||||
|
uri: tron-rpc.publicnode.com:443
|
||||||
|
is_default: false
|
||||||
useSSL: true
|
useSSL: true
|
|
@ -367,7 +367,7 @@ class TronClient {
|
||||||
) async {
|
) async {
|
||||||
// This is introduce to server as a limit in cases where feeLimit is 0
|
// This is introduce to server as a limit in cases where feeLimit is 0
|
||||||
// The transaction signing will fail if the feeLimit is explicitly 0.
|
// The transaction signing will fail if the feeLimit is explicitly 0.
|
||||||
int defaultFeeLimit = 100000;
|
int defaultFeeLimit = 269000;
|
||||||
|
|
||||||
final block = await _provider!.request(TronRequestGetNowBlock());
|
final block = await _provider!.request(TronRequestGetNowBlock());
|
||||||
// Create the transfer contract
|
// Create the transfer contract
|
||||||
|
@ -401,8 +401,9 @@ class TronClient {
|
||||||
final tronBalanceInt = tronBalance.toInt();
|
final tronBalanceInt = tronBalance.toInt();
|
||||||
|
|
||||||
if (feeLimit > tronBalanceInt) {
|
if (feeLimit > tronBalanceInt) {
|
||||||
|
final feeInTrx = TronHelper.fromSun(BigInt.parse(feeLimit.toString()));
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up.',
|
'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up.\nTransaction fee: $feeInTrx TRX',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,6 +443,9 @@ class TronClient {
|
||||||
|
|
||||||
if (!request.isSuccess) {
|
if (!request.isSuccess) {
|
||||||
log("Tron TRC20 error: ${request.error} \n ${request.respose}");
|
log("Tron TRC20 error: ${request.error} \n ${request.respose}");
|
||||||
|
throw Exception(
|
||||||
|
'An error occured while creating the transfer request. Please try again.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final feeLimit = await getFeeLimit(
|
final feeLimit = await getFeeLimit(
|
||||||
|
@ -454,8 +458,9 @@ class TronClient {
|
||||||
final tronBalanceInt = tronBalance.toInt();
|
final tronBalanceInt = tronBalance.toInt();
|
||||||
|
|
||||||
if (feeLimit > tronBalanceInt) {
|
if (feeLimit > tronBalanceInt) {
|
||||||
|
final feeInTrx = TronHelper.fromSun(BigInt.parse(feeLimit.toString()));
|
||||||
throw Exception(
|
throw Exception(
|
||||||
'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up.',
|
'You don\'t have enough TRX to cover the transaction fee for this transaction. Kindly top up. Transaction fee: $feeInTrx TRX',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||||
wallet.type != WalletType.banano &&
|
wallet.type != WalletType.banano &&
|
||||||
wallet.type != WalletType.solana &&
|
wallet.type != WalletType.solana &&
|
||||||
wallet.type != WalletType.tron;
|
wallet.type != WalletType.tron;
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
CryptoCurrency selectedCryptoCurrency;
|
CryptoCurrency selectedCryptoCurrency;
|
||||||
|
|
||||||
|
@ -363,7 +363,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e is LedgerException) {
|
if (e is LedgerException) {
|
||||||
final errorCode = e.errorCode.toRadixString(16);
|
final errorCode = e.errorCode.toRadixString(16);
|
||||||
final fallbackMsg = e.message.isNotEmpty ? e.message : "Unexpected Ledger Error Code: $errorCode";
|
final fallbackMsg =
|
||||||
|
e.message.isNotEmpty ? e.message : "Unexpected Ledger Error Code: $errorCode";
|
||||||
final errorMsg = ledgerViewModel.interpretErrorCode(errorCode) ?? fallbackMsg;
|
final errorMsg = ledgerViewModel.interpretErrorCode(errorCode) ?? fallbackMsg;
|
||||||
|
|
||||||
state = FailureState(errorMsg);
|
state = FailureState(errorMsg);
|
||||||
|
@ -444,7 +445,10 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||||
Object _credentials() {
|
Object _credentials() {
|
||||||
final priority = _settingsStore.priority[wallet.type];
|
final priority = _settingsStore.priority[wallet.type];
|
||||||
|
|
||||||
if (priority == null && wallet.type != WalletType.nano && wallet.type != WalletType.banano && wallet.type != WalletType.solana &&
|
if (priority == null &&
|
||||||
|
wallet.type != WalletType.nano &&
|
||||||
|
wallet.type != WalletType.banano &&
|
||||||
|
wallet.type != WalletType.solana &&
|
||||||
wallet.type != WalletType.tron) {
|
wallet.type != WalletType.tron) {
|
||||||
throw Exception('Priority is null for wallet type: ${wallet.type}');
|
throw Exception('Priority is null for wallet type: ${wallet.type}');
|
||||||
}
|
}
|
||||||
|
@ -570,6 +574,16 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (walletType == WalletType.tron) {
|
||||||
|
if (errorMessage.contains('balance is not sufficient')) {
|
||||||
|
return S.current.do_not_have_enough_gas_asset(currency.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMessage.contains('Transaction expired')) {
|
||||||
|
return 'An error occurred while processing the transaction. Kindly retry the transaction';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (walletType == WalletType.bitcoin ||
|
if (walletType == WalletType.bitcoin ||
|
||||||
walletType == WalletType.litecoin ||
|
walletType == WalletType.litecoin ||
|
||||||
walletType == WalletType.bitcoinCash) {
|
walletType == WalletType.bitcoinCash) {
|
||||||
|
|
Loading…
Reference in a new issue