From db06d08bee00ce46b54d5e227bdc0c827f96cda4 Mon Sep 17 00:00:00 2001
From: vjrj <vjrj@comunes.org>
Date: Mon, 20 Mar 2023 00:41:58 +0100
Subject: [PATCH] More work with payments

---
 lib/data/models/payment_cubit.dart | 4 ++++
 lib/g1/api.dart                    | 8 ++++++--
 lib/ui/screens/pay_form.dart       | 5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/data/models/payment_cubit.dart b/lib/data/models/payment_cubit.dart
index 71d7be53..5b3b1efd 100644
--- a/lib/data/models/payment_cubit.dart
+++ b/lib/data/models/payment_cubit.dart
@@ -53,4 +53,8 @@ class PaymentCubit extends HydratedCubit<PaymentState> {
   void selectAmount(double amount) {
     emit(state.copyWith(amount: amount));
   }
+
+  void setDescription(String description) {
+    emit(state.copyWith(description: description));
+  }
 }
diff --git a/lib/g1/api.dart b/lib/g1/api.dart
index a2e3ac90..c9322a53 100644
--- a/lib/g1/api.dart
+++ b/lib/g1/api.dart
@@ -427,10 +427,14 @@ Future<String> pay(
   final List<Node> nodes = nodesWorkingList(NodeType.gva);
   // reorder list to use others
   if (nodes.isNotEmpty) {
-    nodes.shuffle();
+    // nodes.shuffle();
+    // no hay Retry?
     try {
-      final Gva gva = Gva(node: nodes.first.url);
+      final String node = nodes.first.url;
+      final Gva gva = Gva(node: node);
       final CesiumWallet wallet = await SharedPreferencesHelper().getWallet();
+      print(
+          'Trying to send $amount to $to with comment ${comment ?? ''} and $node');
       final String response = await gva.pay(
           recipient: to,
           amount: amount,
diff --git a/lib/ui/screens/pay_form.dart b/lib/ui/screens/pay_form.dart
index 20f3d42e..5b4e13a5 100644
--- a/lib/ui/screens/pay_form.dart
+++ b/lib/ui/screens/pay_form.dart
@@ -35,6 +35,11 @@ class _PayFormState extends State<PayForm> {
             const SizedBox(height: 10.0),
             TextField(
               controller: _commentController,
+              onChanged: (String? value) {
+                if (value != null) {
+                  context.read<PaymentCubit>().setDescription(value);
+                }
+              },
               decoration: InputDecoration(
                 labelText: tr('g1_form_pay_desc'),
                 hintText: tr('g1_form_pay_hint'),
-- 
GitLab