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