From 5ce381b1748aa505e67306411334f157d37e7adf Mon Sep 17 00:00:00 2001
From: poka <poka@p2p.legal>
Date: Wed, 17 Aug 2022 23:28:19 +0200
Subject: [PATCH] fix: can't cert if identity is not confirmed

---
 assets/translations/en.json      |  1 +
 assets/translations/es.json      |  1 +
 assets/translations/fr.json      |  1 +
 lib/providers/substrate_sdk.dart |  9 ++-
 lib/screens/wallet_view.dart     | 96 ++++++++++++--------------------
 5 files changed, 46 insertions(+), 62 deletions(-)

diff --git a/assets/translations/en.json b/assets/translations/en.json
index bca3f5c0..cfcd2e39 100644
--- a/assets/translations/en.json
+++ b/assets/translations/en.json
@@ -147,6 +147,7 @@
     "execTimeoutOver": "Execution timeout is over",
     "seeAWallet": "See a wallet",
     "mustWaitXBeforeCertify": "You have to wait\n{} before\ncertifying again",
+    "mustConfirmHisIdentity": "This person must confirm\nhis identity before can be\ncertified",
     "canRenewCertInX": "You can renew\nthis certification\nin {}",
     "executeATransfer": "Execute a transfer",
     "executeTheTransfer": "Execute the transfer",
diff --git a/assets/translations/es.json b/assets/translations/es.json
index 7d985e91..99f6f1b2 100644
--- a/assets/translations/es.json
+++ b/assets/translations/es.json
@@ -147,6 +147,7 @@
     "execTimeoutOver": "Execution timeout is over",
     "seeAWallet": "See a wallet",
     "mustWaitXBeforeCertify": "You have to wait\n{} before\ncertifying again",
+    "mustConfirmHisIdentity": "This person must confirm\nhis identity before can be\ncertified",
     "canRenewCertInX": "You can renew\nthis certification\nin {}",
     "executeATransfer": "Execute a transfer",
     "executeTheTransfer": "Execute the transfer",
diff --git a/assets/translations/fr.json b/assets/translations/fr.json
index 9f039531..120c1285 100644
--- a/assets/translations/fr.json
+++ b/assets/translations/fr.json
@@ -148,6 +148,7 @@
     "execTimeoutOver": "Le délais d'éxecution est dépassé",
     "seeAWallet": "Voir un portefeuille",
     "mustWaitXBeforeCertify": "Vous devez attendre\n{} avant\nde pouvoir certifier",
+    "mustConfirmHisIdentity": "Cette personne doit confirmer\nson identité avant de pouvoir\nêtre certifié",
     "canRenewCertInX": "Vous pourrez renouveller\ncette certification\ndans {}",
     "executeATransfer": "Effectuer un virement",
     "executeTheTransfer": "Effectuer le virement",
diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart
index d814bb79..c06d1025 100644
--- a/lib/providers/substrate_sdk.dart
+++ b/lib/providers/substrate_sdk.dart
@@ -227,9 +227,13 @@ class SubstrateSdk with ChangeNotifier {
       } else {
         result.putIfAbsent('canCert', () => 0);
       }
-      // log.d('tatatatata: ${nextIssuableOn - blocNumber}');
     }
 
+    final toStatus = await idtyStatus(to);
+    // log.d('certMeta: $toStatus');
+
+    if (toStatus == 'Created') result.putIfAbsent('toStatus', () => 1);
+
     return result;
   }
 
@@ -797,8 +801,7 @@ class AddressInfo {
 void snackNode(BuildContext context, bool isConnected) {
   String message;
   if (!isConnected) {
-    message =
-        "noDuniterNodeAvailableTryLater".tr();
+    message = "noDuniterNodeAvailableTryLater".tr();
   } else {
     SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: false);
 
diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart
index 15937806..994cdec0 100644
--- a/lib/screens/wallet_view.dart
+++ b/lib/screens/wallet_view.dart
@@ -191,6 +191,8 @@ class WalletViewScreen extends StatelessWidget {
                       }
                     }
 
+                    final toStatus = snapshot.data!['toStatus'] ?? 0;
+
                     return Visibility(
                       visible: (snapshot.data != {}),
                       child: Column(children: <Widget>[
@@ -269,66 +271,13 @@ class WalletViewScreen extends StatelessWidget {
                                   fontWeight: FontWeight.w500),
                             ),
                           ]),
-                        if (snapshot.data!['certDelay'] != null)
-                          Column(children: <Widget>[
-                            SizedBox(
-                              height: buttonSize,
-                              child: Padding(
-                                padding: const EdgeInsets.only(bottom: 0),
-                                child: Container(
-                                  foregroundDecoration: const BoxDecoration(
-                                    color: Colors.grey,
-                                    backgroundBlendMode: BlendMode.saturation,
-                                  ),
-                                  child: const Opacity(
-                                    opacity: 0.5,
-                                    child: Image(
-                                        image: AssetImage(
-                                            'assets/gecko_certify.png')),
-                                  ),
-                                ),
-                              ),
-                            ),
-                            Text(
-                              "mustWaitXBeforeCertify"
-                                  .tr(args: [duration.toString()]),
-                              textAlign: TextAlign.center,
-                              style: TextStyle(
-                                  fontSize: buttonFontSize - 4,
-                                  fontWeight: FontWeight.w400,
-                                  color: Colors.grey[600]),
-                            ),
-                          ]),
-                        if (snapshot.data!['certRenewable'] != null &&
+                        if (toStatus == 1)
+                          waitToCert('mustConfirmHisIdentity', duration)
+                        else if (snapshot.data!['certRenewable'] != null &&
                             duration != 'seconds'.tr(args: ['0']))
-                          Column(children: <Widget>[
-                            SizedBox(
-                              height: buttonSize,
-                              child: Padding(
-                                padding: const EdgeInsets.only(bottom: 0),
-                                child: Container(
-                                  foregroundDecoration: const BoxDecoration(
-                                    color: Colors.grey,
-                                    backgroundBlendMode: BlendMode.saturation,
-                                  ),
-                                  child: const Opacity(
-                                    opacity: 0.5,
-                                    child: Image(
-                                        image: AssetImage(
-                                            'assets/gecko_certify.png')),
-                                  ),
-                                ),
-                              ),
-                            ),
-                            Text(
-                              "canRenewCertInX".tr(args: [duration.toString()]),
-                              textAlign: TextAlign.center,
-                              style: TextStyle(
-                                  fontSize: buttonFontSize - 4,
-                                  fontWeight: FontWeight.w400,
-                                  color: Colors.grey[600]),
-                            ),
-                          ]),
+                          waitToCert('canRenewCertInX', duration)
+                        else if (snapshot.data!['certDelay'] != null)
+                          waitToCert('mustWaitXBeforeCertify', duration)
                       ]),
                     );
                   },
@@ -415,6 +364,35 @@ class WalletViewScreen extends StatelessWidget {
         ));
   }
 
+  Widget waitToCert(String status, String duration) {
+    return Column(children: <Widget>[
+      SizedBox(
+        height: buttonSize,
+        child: Padding(
+          padding: const EdgeInsets.only(bottom: 0),
+          child: Container(
+            foregroundDecoration: const BoxDecoration(
+              color: Colors.grey,
+              backgroundBlendMode: BlendMode.saturation,
+            ),
+            child: const Opacity(
+              opacity: 0.5,
+              child: Image(image: AssetImage('assets/gecko_certify.png')),
+            ),
+          ),
+        ),
+      ),
+      Text(
+        status.tr(args: [duration]),
+        textAlign: TextAlign.center,
+        style: TextStyle(
+            fontSize: buttonFontSize - 4,
+            fontWeight: FontWeight.w400,
+            color: Colors.grey[600]),
+      ),
+    ]);
+  }
+
   void paymentPopup(
       BuildContext context, WalletsProfilesProvider walletViewProvider) {
     // WalletsProfilesProvider _walletViewProvider =
-- 
GitLab