Test node connection when updating and node and show error codes on send fail instead of generic error

This commit is contained in:
likho 2023-08-23 15:13:17 +02:00
parent 2732b2fe71
commit 961b687e27
3 changed files with 35 additions and 20 deletions

View file

@ -58,10 +58,8 @@ class StellarWallet extends CoinServiceAPI with WalletCache, WalletDB {
if (coin.isTestNet) {
stellarSdk = StellarSDK.TESTNET;
stellarNetwork = Network.TESTNET;
} else {
stellarSdk = StellarSDK.PUBLIC;
stellarNetwork = Network.PUBLIC;
}
@ -217,10 +215,12 @@ class StellarWallet extends CoinServiceAPI with WalletCache, WalletDB {
transaction.sign(senderKeyPair, stellarNetwork);
try {
SubmitTransactionResponse response =
await stellarSdk.submitTransaction(transaction);
await stellarSdk.submitTransaction(transaction).onError((error, stackTrace) => throw (error.toString()));
if (!response.success) {
throw ("Unable to send transaction");
throw (
"${response.extras?.resultCodes?.transactionResultCode}"
" ::: ${response.extras?.resultCodes?.operationsResultCodes}"
);
}
return response.hash!;
} catch (e, s) {
@ -278,13 +278,15 @@ class StellarWallet extends CoinServiceAPI with WalletCache, WalletDB {
@override
Future<FeeObject> get fees async {
int fee = await getBaseFee();
return FeeObject(
numberOfBlocksFast: 10,
numberOfBlocksAverage: 10,
numberOfBlocksSlow: 10,
fast: 1,
medium: 1,
slow: 1);
fast: fee,
medium: fee,
slow: fee);
}
@override
@ -482,13 +484,6 @@ class StellarWallet extends CoinServiceAPI with WalletCache, WalletDB {
if (response is PaymentOperationResponse) {
PaymentOperationResponse por = response;
Logging.instance.log(
"ALL TRANSACTIONS IS ${por.transactionSuccessful}",
level: LogLevel.Info);
Logging.instance.log("THIS TX HASH IS ${por.transactionHash}",
level: LogLevel.Info);
SWTransaction.TransactionType type;
if (por.sourceAccount == await getAddressSW()) {
type = SWTransaction.TransactionType.outgoing;

View file

@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
Future<bool> testStellarNodeConnection(String host) async {
@ -12,11 +13,22 @@ Future<bool> testStellarNodeConnection(String host) async {
).timeout(const Duration(milliseconds: 2000),
onTimeout: () async => http.Response('Error', 408));
final json = jsonDecode(response.body);
if (response.statusCode == 200) {
//Get chain height for sdk
StellarSDK stellarSdk = StellarSDK(host);
final height = await stellarSdk.ledgers
.order(RequestBuilderOrder.DESC)
.limit(1)
.execute()
.then((value) => value.records!.first.sequence)
.onError((error, stackTrace) => throw ("Error getting chain height"));
if (response.statusCode == 200 && json["horizon_version"] != null) {
if (height > 0) {
return true;
} else {
return false;
}
} else {
return false;
}
}

View file

@ -29,6 +29,7 @@ import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/test_epic_box_connection.dart';
import 'package:stackwallet/utilities/test_eth_node_connection.dart';
import 'package:stackwallet/utilities/test_monero_node_connection.dart';
import 'package:stackwallet/utilities/test_stellar_node_connection.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
@ -192,10 +193,17 @@ class _NodeCardState extends ConsumerState<NodeCard> {
}
break;
case Coin.nano:
case Coin.banano:
case Coin.stellar:
case Coin.stellarTestnet:
try {
testPassed = await testStellarNodeConnection(node.host);
} catch(_) {
testPassed = false;
}
break;
case Coin.nano:
case Coin.banano:
throw UnimplementedError();
//TODO: check network/node
}