From 244aaf2dcd57967c4f40e755e5eda76513d0970a Mon Sep 17 00:00:00 2001
From: vjrj <vjrj@comunes.org>
Date: Sun, 5 Mar 2023 21:05:33 +0100
Subject: [PATCH] Improving node manager

---
 assets/translations/en.json                | 3 ++-
 assets/translations/es.json                | 3 ++-
 assets/translations/fr.json                | 3 ++-
 lib/g1/duniter_node_manager.dart           | 4 ++--
 lib/main.dart                              | 1 +
 lib/ui/screens/fifth_screen.dart           | 3 ++-
 lib/ui/screens/first_screen.dart           | 2 --
 lib/ui/widgets/fifth_screen/info_card.dart | 3 +++
 8 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/assets/translations/en.json b/assets/translations/en.json
index 6de9669a..b882f60e 100644
--- a/assets/translations/en.json
+++ b/assets/translations/en.json
@@ -40,5 +40,6 @@
   "card-validity": "Validity",
   "card-validity-tooltip": "Please note that this wallet is only accessible while using this specific browser and device. If you delete or reset the browser, you will lose access to this wallet and the funds stored in it.",
   "demo-title": "This is a demo",
-  "demo-desc": "Please refrain from using this with real transactions for now."
+  "demo-desc": "Please refrain from using this with real transactions for now.",
+  "connected-to": "We are connected to node:"
 }
diff --git a/assets/translations/es.json b/assets/translations/es.json
index d5e2f9cc..1a40351d 100644
--- a/assets/translations/es.json
+++ b/assets/translations/es.json
@@ -40,5 +40,6 @@
   "card-validity": "Validez",
   "card-validity-tooltip": "Tenga en cuenta que este monedero solo es accesible mientras utiliza este navegador y este dispositivo específico. Si borra o restablece el navegador, perderá el acceso a este monedero y los fondos almacenados en el.",
   "demo-title": "Esto es una demostración",
-  "demo-desc": "Por favor, no utilice esto aún para transacciones reales."
+  "demo-desc": "Por favor, no utilice esto aún para transacciones reales.",
+  "connected-to": "Estamos conectados al nodo:"
 }
diff --git a/assets/translations/fr.json b/assets/translations/fr.json
index fd2cf066..2d7e4aea 100644
--- a/assets/translations/fr.json
+++ b/assets/translations/fr.json
@@ -40,5 +40,6 @@
   "card-validity": "Validité",
   "card-validity-tooltip": "Veuillez noter que ce portefeuille n'est accessible que lors de l'utilisation de ce navigateur et de cet appareil spécifiques. Si vous supprimez ou réinitialisez le navigateur, vous perdrez l'accès à ce portefeuille et aux fonds qu'il contient.",
   "demo-title": "Ceci est une démonstration",
-  "demo-desc": "Veuillez vous abstenir d'utiliser ceci avec de vraies transactions pour le moment."
+  "demo-desc": "Veuillez vous abstenir d'utiliser ceci avec de vraies transactions pour le moment.",
+  "connected-to": "Nous sommes connectés au nœud:"
 }
diff --git a/lib/g1/duniter_node_manager.dart b/lib/g1/duniter_node_manager.dart
index 146ced14..8b29cfc5 100644
--- a/lib/g1/duniter_node_manager.dart
+++ b/lib/g1/duniter_node_manager.dart
@@ -32,8 +32,8 @@ class DuniterNodeManager {
   final int _retryCount = 3;
   Map<String, int> _nodeErrors = <String, int>{};
   Timer? _resetErrorsTimer;
-  String? _fastestNode;
-  late Duration? _fastestLatency;
+  String _fastestNode = 'https://g1.duniter.org';
+  late Duration _fastestLatency = const Duration(minutes: 1);
 
   Future<dynamic> makeRequest(String endpoint) async {
     Response response;
diff --git a/lib/main.dart b/lib/main.dart
index d6037915..08c8b232 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -75,6 +75,7 @@ void main() async {
     // bandwidth
     DuniterNodeManager().loadNodes();
   });
+  DuniterNodeManager().init();
 
   runApp(
     EasyLocalization(
diff --git a/lib/ui/screens/fifth_screen.dart b/lib/ui/screens/fifth_screen.dart
index 0b64e275..bf07dcb7 100644
--- a/lib/ui/screens/fifth_screen.dart
+++ b/lib/ui/screens/fifth_screen.dart
@@ -20,7 +20,8 @@ class FifthScreen extends StatelessWidget {
           physics: const BouncingScrollPhysics(),
           children: <Widget>[
             const Header(text: 'bottom_nav_fifth'),
-            InfoCard(title: duniterNet, icon: Icons.hub, translate: false),
+            InfoCard(
+                title: 'connected-to', subtitle: duniterNet, icon: Icons.hub),
             LinkCard(
                 title: 'code_card_title',
                 icon: Icons.code_rounded,
diff --git a/lib/ui/screens/first_screen.dart b/lib/ui/screens/first_screen.dart
index 770bc8d3..10ae47f4 100644
--- a/lib/ui/screens/first_screen.dart
+++ b/lib/ui/screens/first_screen.dart
@@ -3,7 +3,6 @@ import 'package:easy_localization/easy_localization.dart';
 import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
 
-import '../../g1/duniter_node_manager.dart';
 import '../widgets/first_screen/credit_card.dart';
 import '../widgets/first_screen/pay_contact_search_bar.dart';
 import '../widgets/header.dart';
@@ -22,7 +21,6 @@ class _FirstScreenState extends State<FirstScreen> {
   @override
   Widget build(BuildContext context) {
     WidgetsBinding.instance.addPostFrameCallback((_) async {
-      DuniterNodeManager().init();
       if (_showFlushbar && kReleaseMode) {
         Flushbar<void>(
           message: tr('demo-title'),
diff --git a/lib/ui/widgets/fifth_screen/info_card.dart b/lib/ui/widgets/fifth_screen/info_card.dart
index 722fef80..50c5c50f 100644
--- a/lib/ui/widgets/fifth_screen/info_card.dart
+++ b/lib/ui/widgets/fifth_screen/info_card.dart
@@ -6,10 +6,12 @@ class InfoCard extends StatelessWidget {
   const InfoCard(
       {super.key,
       required this.title,
+      this.subtitle = '',
       required this.icon,
       this.translate = true});
 
   final String title;
+  final String subtitle;
   final IconData icon;
   final bool translate;
 
@@ -32,6 +34,7 @@ class InfoCard extends StatelessWidget {
           child: ListTile(
             shape: const RoundedRectangleBorder(
                 borderRadius: BorderRadius.all(Radius.circular(12))),
+            subtitle: subtitle.isNotEmpty ? Text(subtitle) : null,
             title: Row(
               children: <Widget>[
                 Icon(icon, color: Theme.of(context).colorScheme.primary),
-- 
GitLab