node related fixes

This commit is contained in:
fosse 2023-08-16 13:01:01 -04:00
parent 3041fcc8b8
commit 6a63e08e74
6 changed files with 34 additions and 27 deletions

View file

@ -13,14 +13,15 @@ Uri createUriFromElectrumAddress(String address) => Uri.tryParse('tcp://$address
@HiveType(typeId: Node.typeId)
class Node extends HiveObject with Keyable {
Node(
{this.login,
this.password,
this.useSSL,
this.trusted = false,
this.socksProxyAddress,
String? uri,
WalletType? type,}) {
Node({
this.login,
this.password,
this.useSSL,
this.trusted = false,
this.socksProxyAddress,
String? uri,
WalletType? type,
}) {
if (uri != null) {
uriRaw = uri;
}
@ -61,6 +62,8 @@ class Node extends HiveObject with Keyable {
@HiveField(6)
String? socksProxyAddress;
bool isPowNode = false;
bool get isSSL => useSSL ?? false;
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;
@ -92,13 +95,13 @@ class Node extends HiveObject with Keyable {
@override
bool operator ==(other) =>
other is Node &&
(other.uriRaw == uriRaw &&
other.login == login &&
other.password == password &&
other.typeRaw == typeRaw &&
other.useSSL == useSSL &&
other.trusted == trusted &&
other.socksProxyAddress == socksProxyAddress);
(other.uriRaw == uriRaw &&
other.login == login &&
other.password == password &&
other.typeRaw == typeRaw &&
other.useSSL == useSSL &&
other.trusted == trusted &&
other.socksProxyAddress == socksProxyAddress);
@override
int get hashCode =>
@ -126,7 +129,9 @@ class Node extends HiveObject with Keyable {
try {
switch (type) {
case WalletType.monero:
return useSocksProxy ? requestNodeWithProxy(socksProxyAddress ?? '') : requestMoneroNode();
return useSocksProxy
? requestNodeWithProxy(socksProxyAddress ?? '')
: requestMoneroNode();
case WalletType.bitcoin:
return requestElectrumServer();
case WalletType.litecoin:
@ -176,7 +181,6 @@ class Node extends HiveObject with Keyable {
}
Future<bool> requestNodeWithProxy(String proxy) async {
if (proxy.isEmpty || !proxy.contains(':')) {
return false;
}

View file

@ -665,5 +665,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.19.0 <4.0.0"
dart: ">=2.19.0 <3.0.0"
flutter: ">=3.0.0"

View file

@ -109,6 +109,7 @@ Future<List<Node>> loadDefaultNanoPowNodes() async {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.nano;
node.isPowNode = true;
nodes.add(node);
}
}
@ -123,12 +124,14 @@ Future resetToDefault(Box<Node> nodeSource) async {
final havenNodes = await loadDefaultHavenNodes();
final ethereumNodes = await loadDefaultEthereumNodes();
final nanoNodes = await loadDefaultNanoNodes();
final nanoPowNodes = await loadDefaultNanoPowNodes();
final nodes = moneroNodes +
bitcoinElectrumServerList +
litecoinElectrumServerList +
havenNodes +
ethereumNodes +
nanoNodes;
nanoNodes + nanoPowNodes;
await nodeSource.clear();
await nodeSource.addAll(nodes);

View file

@ -86,7 +86,7 @@ abstract class NodeListViewModelBase with Store {
nodes.clear();
_nodeSource.bindToList(
nodes,
filter: (val) => val.type == _appStore.wallet!.type,
filter: (val) => (val.type == _appStore.wallet!.type && val.isPowNode == false),
initialFire: true,
);
}

View file

@ -13,8 +13,7 @@ class PowNodeCreateOrEditViewModel = PowNodeCreateOrEditViewModelBase
with _$PowNodeCreateOrEditViewModel;
abstract class PowNodeCreateOrEditViewModelBase with Store {
PowNodeCreateOrEditViewModelBase(
this._nodeSource, this._walletType, this._settingsStore)
PowNodeCreateOrEditViewModelBase(this._nodeSource, this._walletType, this._settingsStore)
: state = InitialExecutionState(),
connectionState = InitialExecutionState(),
useSSL = false,
@ -122,6 +121,7 @@ abstract class PowNodeCreateOrEditViewModelBase with Store {
useSSL: useSSL,
trusted: trusted,
socksProxyAddress: socksProxyAddress);
node.isPowNode = true;
try {
state = IsExecutingState();
if (editingNode != null) {
@ -172,7 +172,7 @@ abstract class PowNodeCreateOrEditViewModelBase with Store {
}
@action
void setAsCurrent(Node node) => _settingsStore.nodes[_walletType] = node;
void setAsCurrent(Node node) => _settingsStore.powNodes[_walletType] = node;
@action
Future<void> scanQRCodeForNewNode() async {
@ -190,7 +190,7 @@ abstract class PowNodeCreateOrEditViewModelBase with Store {
}
final userInfo = uri.userInfo.split(':');
if (userInfo.length < 2) {
throw Exception('Unexpected scan QR code value: Value is invalid');
}

View file

@ -27,7 +27,7 @@ abstract class PowNodeListViewModelBase with Store {
@computed
Node get currentNode {
final node = settingsStore.nodes[_appStore.wallet!.type];
final node = settingsStore.powNodes[_appStore.wallet!.type];
if (node == null) {
throw Exception('No node for wallet type: ${_appStore.wallet!.type}');
@ -79,14 +79,14 @@ abstract class PowNodeListViewModelBase with Store {
@action
Future<void> delete(Node node) async => node.delete();
Future<void> setAsCurrent(Node node) async => settingsStore.nodes[_appStore.wallet!.type] = node;
Future<void> setAsCurrent(Node node) async => settingsStore.powNodes[_appStore.wallet!.type] = node;
@action
void _bindNodes() {
nodes.clear();
_nodeSource.bindToList(
nodes,
filter: (val) => val.type == _appStore.wallet!.type,
filter: (val) => (val.type == _appStore.wallet!.type && val.isPowNode == true),
initialFire: true,
);
}