mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
epic node changes and fixes
This commit is contained in:
parent
84108a3b27
commit
236e04f849
6 changed files with 122 additions and 55 deletions
|
@ -70,20 +70,13 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
|
|||
switch (coin) {
|
||||
case Coin.epicCash:
|
||||
try {
|
||||
final uri = Uri.parse(formData.host!);
|
||||
if (uri.scheme.startsWith("http")) {
|
||||
final String path = uri.path.isEmpty ? "/v1/version" : uri.path;
|
||||
final data = await testEpicNodeConnection(formData);
|
||||
|
||||
String uriString =
|
||||
"${uri.scheme}://${uri.host}:${formData.port ?? 0}$path";
|
||||
|
||||
if (uri.host == "https") {
|
||||
ref.read(nodeFormDataProvider).useSSL = true;
|
||||
} else {
|
||||
ref.read(nodeFormDataProvider).useSSL = false;
|
||||
}
|
||||
|
||||
testPassed = await testEpicBoxNodeConnection(Uri.parse(uriString));
|
||||
if (data != null) {
|
||||
testPassed = true;
|
||||
ref.read(nodeFormDataProvider).host = data.host;
|
||||
ref.read(nodeFormDataProvider).port = data.port;
|
||||
ref.read(nodeFormDataProvider).useSSL = data.useSSL;
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
|
||||
|
@ -315,7 +308,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
|
|||
|
||||
// strip unused path
|
||||
String address = formData.host!;
|
||||
if (coin == Coin.monero || coin == Coin.wownero || coin == Coin.epicCash) {
|
||||
if (coin == Coin.monero || coin == Coin.wownero) {
|
||||
if (address.startsWith("http")) {
|
||||
final uri = Uri.parse(address);
|
||||
address = "${uri.scheme}://${uri.host}";
|
||||
|
@ -673,6 +666,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
|
|||
bool _useSSL = false;
|
||||
bool _isFailover = false;
|
||||
int? port;
|
||||
late bool enableSSLCheckbox;
|
||||
|
||||
late final bool enableAuthFields;
|
||||
|
||||
|
@ -692,9 +686,9 @@ class _NodeFormState extends ConsumerState<NodeForm> {
|
|||
case Coin.bitcoincashTestnet:
|
||||
case Coin.firoTestNet:
|
||||
case Coin.dogecoinTestNet:
|
||||
case Coin.epicCash:
|
||||
return false;
|
||||
|
||||
case Coin.epicCash:
|
||||
case Coin.monero:
|
||||
case Coin.wownero:
|
||||
return true;
|
||||
|
@ -768,11 +762,19 @@ class _NodeFormState extends ConsumerState<NodeForm> {
|
|||
_usernameController.text = node.loginName ?? "";
|
||||
_useSSL = node.useSSL;
|
||||
_isFailover = node.isFailover;
|
||||
if (widget.coin == Coin.epicCash) {
|
||||
enableSSLCheckbox = !node.host.startsWith("http");
|
||||
}
|
||||
print("enableSSLCheckbox: $enableSSLCheckbox");
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// update provider state object so test connection works without having to modify a field in the ui first
|
||||
_updateState();
|
||||
});
|
||||
} else {
|
||||
enableSSLCheckbox = true;
|
||||
// default to port 3413
|
||||
// _portController.text = "3413";
|
||||
}
|
||||
|
||||
super.initState();
|
||||
|
@ -858,9 +860,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
|
|||
focusNode: _hostFocusNode,
|
||||
style: STextStyles.field(context),
|
||||
decoration: standardInputDecoration(
|
||||
(widget.coin != Coin.monero &&
|
||||
widget.coin != Coin.wownero &&
|
||||
widget.coin != Coin.epicCash)
|
||||
(widget.coin != Coin.monero && widget.coin != Coin.wownero)
|
||||
? "IP address"
|
||||
: "Url",
|
||||
_hostFocusNode,
|
||||
|
@ -886,6 +886,17 @@ class _NodeFormState extends ConsumerState<NodeForm> {
|
|||
: null,
|
||||
),
|
||||
onChanged: (newValue) {
|
||||
if (widget.coin == Coin.epicCash) {
|
||||
if (newValue.startsWith("https://")) {
|
||||
_useSSL = true;
|
||||
enableSSLCheckbox = false;
|
||||
} else if (newValue.startsWith("http://")) {
|
||||
_useSSL = false;
|
||||
enableSSLCheckbox = false;
|
||||
} else {
|
||||
enableSSLCheckbox = true;
|
||||
}
|
||||
}
|
||||
_updateState();
|
||||
setState(() {});
|
||||
},
|
||||
|
@ -1040,20 +1051,18 @@ class _NodeFormState extends ConsumerState<NodeForm> {
|
|||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (widget.coin != Coin.monero &&
|
||||
widget.coin != Coin.wownero &&
|
||||
widget.coin != Coin.epicCash)
|
||||
if (widget.coin != Coin.monero && widget.coin != Coin.wownero)
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: widget.readOnly
|
||||
? null
|
||||
: () {
|
||||
onTap: !widget.readOnly && enableSSLCheckbox
|
||||
? () {
|
||||
setState(() {
|
||||
_useSSL = !_useSSL;
|
||||
});
|
||||
_updateState();
|
||||
},
|
||||
}
|
||||
: null,
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: Row(
|
||||
|
@ -1062,22 +1071,22 @@ class _NodeFormState extends ConsumerState<NodeForm> {
|
|||
width: 20,
|
||||
height: 20,
|
||||
child: Checkbox(
|
||||
fillColor: widget.readOnly
|
||||
? MaterialStateProperty.all(Theme.of(context)
|
||||
fillColor: !widget.readOnly && enableSSLCheckbox
|
||||
? null
|
||||
: MaterialStateProperty.all(Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.checkboxBGDisabled)
|
||||
: null,
|
||||
.checkboxBGDisabled),
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
value: _useSSL,
|
||||
onChanged: widget.readOnly
|
||||
? null
|
||||
: (newValue) {
|
||||
onChanged: !widget.readOnly && enableSSLCheckbox
|
||||
? (newValue) {
|
||||
setState(() {
|
||||
_useSSL = newValue!;
|
||||
});
|
||||
_updateState();
|
||||
},
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
|
|
|
@ -70,14 +70,15 @@ class _NodeDetailsViewState extends ConsumerState<NodeDetailsView> {
|
|||
switch (coin) {
|
||||
case Coin.epicCash:
|
||||
try {
|
||||
final uri = Uri.parse(node!.host);
|
||||
if (uri.scheme.startsWith("http")) {
|
||||
final String path = uri.path.isEmpty ? "/v1/version" : uri.path;
|
||||
|
||||
String uriString = "${uri.scheme}://${uri.host}:${node.port}$path";
|
||||
testPassed = await testEpicNodeConnection(
|
||||
NodeFormData()
|
||||
..host = node!.host
|
||||
..useSSL = node.useSSL
|
||||
..port = node.port,
|
||||
) !=
|
||||
null;
|
||||
|
||||
testPassed = await testEpicBoxNodeConnection(Uri.parse(uriString));
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
|
||||
testPassed = false;
|
||||
|
|
|
@ -15,6 +15,7 @@ import 'package:stackwallet/models/node_model.dart';
|
|||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||
import 'package:stackwallet/models/paymint/utxo_model.dart';
|
||||
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
|
||||
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/blocks_remaining_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
|
||||
|
@ -552,6 +553,9 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
DefaultNodes.getNodeFor(coin);
|
||||
// TODO notify ui/ fire event for node changed?
|
||||
|
||||
String stringConfig = await getConfig();
|
||||
await _secureStore.write(key: '${_walletId}_config', value: stringConfig);
|
||||
|
||||
if (shouldRefresh) {
|
||||
unawaited(refresh());
|
||||
}
|
||||
|
@ -1262,8 +1266,12 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
}
|
||||
final NodeModel node = _epicNode!;
|
||||
final String nodeAddress = node.host;
|
||||
int port = node.port;
|
||||
final String nodeApiAddress = "$nodeAddress:$port";
|
||||
final int port = node.port;
|
||||
|
||||
final uri = Uri.parse(nodeAddress).replace(port: port);
|
||||
|
||||
final String nodeApiAddress = uri.toString();
|
||||
|
||||
final walletDir = await currentWalletDirPath();
|
||||
|
||||
final Map<String, dynamic> config = {};
|
||||
|
@ -1272,7 +1280,8 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
config["chain"] = "mainnet";
|
||||
config["account"] = "default";
|
||||
config["api_listen_port"] = port;
|
||||
config["api_listen_interface"] = nodeAddress;
|
||||
config["api_listen_interface"] =
|
||||
nodeApiAddress.replaceFirst(uri.scheme, "");
|
||||
String stringConfig = json.encode(config);
|
||||
return stringConfig;
|
||||
}
|
||||
|
@ -2022,11 +2031,13 @@ class EpicCashWallet extends CoinServiceAPI {
|
|||
try {
|
||||
// force unwrap optional as we want connection test to fail if wallet
|
||||
// wasn't initialized or epicbox node was set to null
|
||||
final String uriString =
|
||||
"${_epicNode!.host}:${_epicNode!.port}/v1/version";
|
||||
|
||||
final Uri uri = Uri.parse(uriString);
|
||||
return await testEpicBoxNodeConnection(uri);
|
||||
return await testEpicNodeConnection(
|
||||
NodeFormData()
|
||||
..host = _epicNode!.host
|
||||
..useSSL = _epicNode!.useSSL
|
||||
..port = _epicNode!.port,
|
||||
) !=
|
||||
null;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
|
||||
return false;
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
|
||||
Future<bool> testEpicBoxNodeConnection(Uri uri) async {
|
||||
Future<bool> _testEpicBoxNodeConnection(Uri uri) async {
|
||||
try {
|
||||
final client = http.Client();
|
||||
final response = await client.get(
|
||||
uri,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
).timeout(const Duration(milliseconds: 1200),
|
||||
).timeout(const Duration(milliseconds: 2000),
|
||||
onTimeout: () async => http.Response('Error', 408));
|
||||
|
||||
final json = jsonDecode(response.body);
|
||||
|
@ -24,3 +25,38 @@ Future<bool> testEpicBoxNodeConnection(Uri uri) async {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// returns node data with properly formatted host/url if successful, otherwise null
|
||||
Future<NodeFormData?> testEpicNodeConnection(NodeFormData data) async {
|
||||
if (data.host == null || data.port == null || data.useSSL == null) {
|
||||
return null;
|
||||
}
|
||||
const String path_postfix = "/v1/version";
|
||||
|
||||
if (data.host!.startsWith("https://")) {
|
||||
data.useSSL = true;
|
||||
} else if (data.host!.startsWith("http://")) {
|
||||
data.useSSL = false;
|
||||
} else {
|
||||
if (data.useSSL!) {
|
||||
data.host = "https://${data.host!}";
|
||||
} else {
|
||||
data.host = "http://${data.host!}";
|
||||
}
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse(data.host! + path_postfix);
|
||||
|
||||
uri = uri.replace(port: data.port);
|
||||
|
||||
try {
|
||||
if (await _testEpicBoxNodeConnection(uri)) {
|
||||
return data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/models/node_model.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
|
||||
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/node_details_view.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
|
@ -93,9 +94,13 @@ class _NodeCardState extends ConsumerState<NodeCard> {
|
|||
switch (widget.coin) {
|
||||
case Coin.epicCash:
|
||||
try {
|
||||
final String uriString = "${node.host}:${node.port}/v1/version";
|
||||
|
||||
testPassed = await testEpicBoxNodeConnection(Uri.parse(uriString));
|
||||
testPassed = await testEpicNodeConnection(
|
||||
NodeFormData()
|
||||
..host = node.host
|
||||
..useSSL = node.useSSL
|
||||
..port = node.port,
|
||||
) !=
|
||||
null;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/models/node_model.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
|
||||
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/node_details_view.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
|
@ -76,9 +77,13 @@ class NodeOptionsSheet extends ConsumerWidget {
|
|||
switch (coin) {
|
||||
case Coin.epicCash:
|
||||
try {
|
||||
final String uriString = "${node.host}:${node.port}/v1/version";
|
||||
|
||||
testPassed = await testEpicBoxNodeConnection(Uri.parse(uriString));
|
||||
testPassed = await testEpicNodeConnection(
|
||||
NodeFormData()
|
||||
..host = node.host
|
||||
..useSSL = node.useSSL
|
||||
..port = node.port,
|
||||
) !=
|
||||
null;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue