From 6a63e08e74cad22b9e61fc810a8788415c0345d0 Mon Sep 17 00:00:00 2001
From: fosse <matt.cfosse@gmail.com>
Date: Wed, 16 Aug 2023 13:01:01 -0400
Subject: [PATCH] node related fixes

---
 cw_core/lib/node.dart                         | 38 ++++++++++---------
 cw_core/pubspec.lock                          |  2 +-
 lib/entities/node_list.dart                   |  5 ++-
 .../node_list/node_list_view_model.dart       |  2 +-
 .../pow_node_create_or_edit_view_model.dart   |  8 ++--
 .../node_list/pow_node_list_view_model.dart   |  6 +--
 6 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart
index 218ca16f4..b3ab5277c 100644
--- a/cw_core/lib/node.dart
+++ b/cw_core/lib/node.dart
@@ -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;
     }
diff --git a/cw_core/pubspec.lock b/cw_core/pubspec.lock
index 70652ec35..01e19dda4 100644
--- a/cw_core/pubspec.lock
+++ b/cw_core/pubspec.lock
@@ -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"
diff --git a/lib/entities/node_list.dart b/lib/entities/node_list.dart
index 595dcb684..3e551ab71 100644
--- a/lib/entities/node_list.dart
+++ b/lib/entities/node_list.dart
@@ -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);
diff --git a/lib/view_model/node_list/node_list_view_model.dart b/lib/view_model/node_list/node_list_view_model.dart
index 59d150ae9..946641d5f 100644
--- a/lib/view_model/node_list/node_list_view_model.dart
+++ b/lib/view_model/node_list/node_list_view_model.dart
@@ -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,
     );
   }
diff --git a/lib/view_model/node_list/pow_node_create_or_edit_view_model.dart b/lib/view_model/node_list/pow_node_create_or_edit_view_model.dart
index 8c69aa364..d24db1741 100644
--- a/lib/view_model/node_list/pow_node_create_or_edit_view_model.dart
+++ b/lib/view_model/node_list/pow_node_create_or_edit_view_model.dart
@@ -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');
       }
diff --git a/lib/view_model/node_list/pow_node_list_view_model.dart b/lib/view_model/node_list/pow_node_list_view_model.dart
index 3cfb8a113..8b52457b3 100644
--- a/lib/view_model/node_list/pow_node_list_view_model.dart
+++ b/lib/view_model/node_list/pow_node_list_view_model.dart
@@ -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,
     );
   }