From 39881ba13687c5f8609dfcdcc7069f01b66ff6da Mon Sep 17 00:00:00 2001
From: poka <poka@p2p.legal>
Date: Mon, 29 Nov 2021 05:53:21 +0100
Subject: [PATCH] Add blockchain username in wallet view; Can open avatar
 fullscreen; Fix HD assets size in mywallets view

---
 lib/models/cesium_plus.dart                   |  2 +-
 lib/models/queries.dart                       |  9 +++
 lib/screens/avatar_fullscreen.dart            | 48 ++++++++++++++++
 .../myWallets/cesium_wallet_options.dart      | 34 +++++++-----
 lib/screens/myWallets/chest_options.dart      |  6 +-
 lib/screens/myWallets/wallet_options.dart     | 32 +++++++----
 lib/screens/template_screen.dart              | 45 ---------------
 lib/screens/wallet_view.dart                  | 55 +++++++++++++++++--
 8 files changed, 152 insertions(+), 79 deletions(-)
 create mode 100644 lib/screens/avatar_fullscreen.dart

diff --git a/lib/models/cesium_plus.dart b/lib/models/cesium_plus.dart
index 8f872ed4..b66306ea 100644
--- a/lib/models/cesium_plus.dart
+++ b/lib/models/cesium_plus.dart
@@ -105,7 +105,7 @@ class CesiumPlusProvider with ChangeNotifier {
     return Image.file(
       avatarFile,
       height: size,
-      fit: BoxFit.cover,
+      fit: BoxFit.fitWidth,
     );
   }
 }
diff --git a/lib/models/queries.dart b/lib/models/queries.dart
index 4644a770..85b4c42e 100644
--- a/lib/models/queries.dart
+++ b/lib/models/queries.dart
@@ -86,3 +86,12 @@ query ($number: Int!, $cursor: String) {
   }
 }
 ''';
+
+const String getId = r'''
+query ($pubkey: PubKeyGva!) {
+  idty(pubkey: $pubkey) {
+    isMember
+    username
+  }
+}
+''';
diff --git a/lib/screens/avatar_fullscreen.dart b/lib/screens/avatar_fullscreen.dart
new file mode 100644
index 00000000..d7f5cede
--- /dev/null
+++ b/lib/screens/avatar_fullscreen.dart
@@ -0,0 +1,48 @@
+import 'package:flutter/services.dart';
+import 'package:gecko/globals.dart';
+import 'package:flutter/material.dart';
+// import 'package:gecko/models/home.dart';
+// import 'package:provider/provider.dart';
+
+// ignore: must_be_immutable
+class AvatarFullscreen extends StatelessWidget {
+  TextEditingController tplController = TextEditingController();
+
+  AvatarFullscreen(this.avatar, {Key key}) : super(key: key);
+  final Image avatar;
+
+  @override
+  Widget build(BuildContext context) {
+    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
+    // HomeProvider _homeProvider = Provider.of<HomeProvider>(context);
+    return Scaffold(
+      appBar: AppBar(
+          elevation: 0,
+          backgroundColor: Colors.black,
+          toolbarHeight: 60 * ratio,
+          leading: IconButton(
+              icon: Icon(Icons.arrow_back, color: orangeC),
+              onPressed: () {
+                Navigator.pop(context);
+              }),
+          title: SizedBox(
+            height: 22,
+            child: Text(
+              'Photo de profil',
+              style: TextStyle(color: orangeC),
+            ),
+          )),
+      body: SafeArea(
+        child: SizedBox.expand(
+          child: Container(
+            color: Colors.black,
+            // alignment: Alignment.center,
+            // height: MediaQuery.of(context).size.height,
+            // width: MediaQuery.of(context).size.width,
+            child: avatar,
+          ),
+        ),
+      ),
+    );
+  }
+}
diff --git a/lib/screens/myWallets/cesium_wallet_options.dart b/lib/screens/myWallets/cesium_wallet_options.dart
index 1d8854d8..115c318f 100644
--- a/lib/screens/myWallets/cesium_wallet_options.dart
+++ b/lib/screens/myWallets/cesium_wallet_options.dart
@@ -89,8 +89,9 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
                     child: Column(children: <Widget>[
                       Image.asset(
                         'assets/walletOptions/camera.png',
+                        height: 40,
                       ),
-                      const SizedBox(height: 100)
+                      const SizedBox(height: 80)
                     ])),
                 Column(children: <Widget>[
                   Row(children: <Widget>[
@@ -175,15 +176,17 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
                       ),
                       const SizedBox(height: 5),
                       InkWell(
-                          key: const Key('displayBalance'),
-                          onTap: () {
-                            _walletOptions.bluringBalance();
-                          },
-                          child: Image.asset(
-                            _walletOptions.isBalanceBlur
-                                ? 'assets/walletOptions/icon_oeuil.png'
-                                : 'assets/walletOptions/icon_oeuil_close.png',
-                          )),
+                        key: const Key('displayBalance'),
+                        onTap: () {
+                          _walletOptions.bluringBalance();
+                        },
+                        child: Image.asset(
+                          _walletOptions.isBalanceBlur
+                              ? 'assets/walletOptions/icon_oeuil.png'
+                              : 'assets/walletOptions/icon_oeuil_close.png',
+                          height: 35,
+                        ),
+                      ),
                     ]),
                     const SizedBox(width: 0),
                     Column(children: <Widget>[
@@ -234,6 +237,7 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
                     const SizedBox(width: 30),
                     Image.asset(
                       'assets/walletOptions/key.png',
+                      height: 45,
                     ),
                     const SizedBox(width: 20),
                     Text("${shortPubkey.split(':')[0]}:",
@@ -267,6 +271,7 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
                             child: Row(children: <Widget>[
                               Image.asset(
                                 'assets/walletOptions/copy-white.png',
+                                height: 25,
                               ),
                               const SizedBox(width: 7),
                               Text('Copier',
@@ -287,6 +292,7 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
                     const SizedBox(width: 30),
                     Image.asset(
                       'assets/walletOptions/clock.png',
+                      height: 45,
                     ),
                     const SizedBox(width: 22),
                     const Text('Historique des transactions',
@@ -312,11 +318,12 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
             child: SizedBox(
                 height: 50,
                 child: Row(children: <Widget>[
-                  const SizedBox(width: 28),
+                  const SizedBox(width: 31),
                   Image.asset(
                     'assets/chests/secret_code.png',
+                    height: 24,
                   ),
-                  const SizedBox(width: 18),
+                  const SizedBox(width: 20),
                   const Text('Changer mon code secret',
                       style: TextStyle(fontSize: 20, color: Colors.black)),
                 ])),
@@ -333,8 +340,9 @@ Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet,
                 const SizedBox(width: 33),
                 Image.asset(
                   'assets/walletOptions/trash.png',
+                  height: 45,
                 ),
-                const SizedBox(width: 25),
+                const SizedBox(width: 21),
                 const Text(
                   'Supprimer ce coffre',
                   style: TextStyle(
diff --git a/lib/screens/myWallets/chest_options.dart b/lib/screens/myWallets/chest_options.dart
index e0c1d1c3..cc7eb68e 100644
--- a/lib/screens/myWallets/chest_options.dart
+++ b/lib/screens/myWallets/chest_options.dart
@@ -68,6 +68,7 @@ class ChestOptions extends StatelessWidget {
                     const SizedBox(width: 28),
                     Image.asset(
                       'assets/chests/secret_code.png',
+                      height: 25,
                     ),
                     const SizedBox(width: 18),
                     const Text('Changer mon code secret',
@@ -83,11 +84,12 @@ class ChestOptions extends StatelessWidget {
               child: SizedBox(
                 height: 50,
                 child: Row(children: <Widget>[
-                  const SizedBox(width: 33),
+                  const SizedBox(width: 30),
                   Image.asset(
                     'assets/walletOptions/trash.png',
+                    height: 45,
                   ),
-                  const SizedBox(width: 24),
+                  const SizedBox(width: 20),
                   const Text(
                     'Supprimer ce coffre',
                     style: TextStyle(
diff --git a/lib/screens/myWallets/wallet_options.dart b/lib/screens/myWallets/wallet_options.dart
index b3e450e0..8f049f2a 100644
--- a/lib/screens/myWallets/wallet_options.dart
+++ b/lib/screens/myWallets/wallet_options.dart
@@ -131,8 +131,9 @@ class WalletOptions extends StatelessWidget {
                         child: Column(children: <Widget>[
                           Image.asset(
                             'assets/walletOptions/camera.png',
+                            height: 40,
                           ),
-                          const SizedBox(height: 100)
+                          const SizedBox(height: 80)
                         ])),
                     Column(children: <Widget>[
                       Row(children: <Widget>[
@@ -221,15 +222,17 @@ class WalletOptions extends StatelessWidget {
                           ),
                           const SizedBox(height: 5),
                           InkWell(
-                              key: const Key('displayBalance'),
-                              onTap: () {
-                                _walletOptions.bluringBalance();
-                              },
-                              child: Image.asset(
-                                _walletOptions.isBalanceBlur
-                                    ? 'assets/walletOptions/icon_oeuil.png'
-                                    : 'assets/walletOptions/icon_oeuil_close.png',
-                              )),
+                            key: const Key('displayBalance'),
+                            onTap: () {
+                              _walletOptions.bluringBalance();
+                            },
+                            child: Image.asset(
+                              _walletOptions.isBalanceBlur
+                                  ? 'assets/walletOptions/icon_oeuil.png'
+                                  : 'assets/walletOptions/icon_oeuil_close.png',
+                              height: 35,
+                            ),
+                          ),
                         ]),
                         const SizedBox(width: 0),
                         Column(children: <Widget>[
@@ -282,6 +285,7 @@ class WalletOptions extends StatelessWidget {
                     const SizedBox(width: 30),
                     Image.asset(
                       'assets/walletOptions/key.png',
+                      height: 45,
                     ),
                     const SizedBox(width: 20),
                     Text("${shortPubkey.split(':')[0]}:",
@@ -315,6 +319,7 @@ class WalletOptions extends StatelessWidget {
                         child: Row(children: <Widget>[
                           Image.asset(
                             'assets/walletOptions/copy-white.png',
+                            height: 25,
                           ),
                           const SizedBox(width: 7),
                           Text(
@@ -341,6 +346,7 @@ class WalletOptions extends StatelessWidget {
                     const SizedBox(width: 30),
                     Image.asset(
                       'assets/walletOptions/clock.png',
+                      height: 45,
                     ),
                     const SizedBox(width: 22),
                     const Text('Historique des transactions',
@@ -369,6 +375,7 @@ class WalletOptions extends StatelessWidget {
                           .grey[_walletOptions.isDefaultWallet ? 300 : 500],
                       child: Image.asset(
                         'assets/walletOptions/android-checkmark.png',
+                        height: 25,
                       ),
                     ),
                     const SizedBox(width: 22),
@@ -399,11 +406,12 @@ class WalletOptions extends StatelessWidget {
                         }
                       : null,
                   child: Row(children: <Widget>[
-                    const SizedBox(width: 33),
+                    const SizedBox(width: 30),
                     Image.asset(
                       'assets/walletOptions/trash.png',
+                      height: 45,
                     ),
-                    const SizedBox(width: 24),
+                    const SizedBox(width: 19),
                     const Text('Supprimer ce portefeuille',
                         style:
                             TextStyle(fontSize: 20, color: Color(0xffD80000))),
diff --git a/lib/screens/template_screen.dart b/lib/screens/template_screen.dart
index 4759e7ba..e8858c78 100644
--- a/lib/screens/template_screen.dart
+++ b/lib/screens/template_screen.dart
@@ -1,6 +1,5 @@
 import 'package:flutter/services.dart';
 import 'package:gecko/globals.dart';
-import 'package:gecko/screens/home.dart';
 import 'package:flutter/material.dart';
 // import 'package:gecko/models/home.dart';
 // import 'package:provider/provider.dart';
@@ -22,26 +21,6 @@ class TemplateScreen extends StatelessWidget {
               height: 22,
               child: Text('Template screen'),
             )),
-        floatingActionButton: SizedBox(
-            height: 80.0,
-            width: 80.0,
-            child: FittedBox(
-                child: FloatingActionButton(
-              heroTag: "tplButton",
-              onPressed: () => Navigator.push(
-                context,
-                MaterialPageRoute(builder: (context) {
-                  return const HomeScreen();
-                }),
-              ),
-              child: SizedBox(
-                height: 40.0,
-                width: 40.0,
-                child: Icon(Icons.home, color: Colors.grey[850]),
-              ),
-              backgroundColor:
-                  floattingYellow, //smoothYellow, //Color.fromARGB(500, 204, 255, 255),
-            ))),
         body: SafeArea(
           child: Column(children: <Widget>[
             const SizedBox(height: 20),
@@ -58,30 +37,6 @@ class TemplateScreen extends StatelessWidget {
                     color: Colors.black,
                     fontWeight: FontWeight.w400)),
             const SizedBox(height: 20),
-            ElevatedButton(
-                style: ElevatedButton.styleFrom(
-                  primary: yellowC, // background
-                  onPrimary: Colors.black, // foreground
-                ),
-                onPressed: () {
-                  Navigator.push(
-                    context,
-                    MaterialPageRoute(builder: (context) {
-                      return const HomeScreen();
-                    }),
-                  );
-                },
-                child: const Text('Retour Accueil',
-                    style: TextStyle(fontSize: 20))),
-            const SizedBox(height: 20),
-            GestureDetector(
-                onTap: () {
-                  Navigator.popUntil(
-                    context,
-                    ModalRoute.withName('/'),
-                  );
-                },
-                child: const Icon(Icons.home))
           ]),
         ));
   }
diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart
index 8d3961e4..3aeefe57 100644
--- a/lib/screens/wallet_view.dart
+++ b/lib/screens/wallet_view.dart
@@ -5,6 +5,9 @@ import 'package:gecko/globals.dart';
 import 'package:flutter/material.dart';
 import 'package:gecko/models/cesium_plus.dart';
 import 'package:gecko/models/history.dart';
+import 'package:gecko/models/queries.dart';
+import 'package:gecko/screens/avatar_fullscreen.dart';
+import 'package:graphql_flutter/graphql_flutter.dart';
 import 'package:provider/provider.dart';
 // import 'package:gecko/models/home.dart';
 // import 'package:provider/provider.dart';
@@ -34,7 +37,7 @@ class WalletViewScreen extends StatelessWidget {
         body: SafeArea(
           child: Column(children: <Widget>[
             Container(
-              height: isTall ? 30 : 10,
+              height: 10,
               color: yellowC,
             ),
             Container(
@@ -69,7 +72,36 @@ class WalletViewScreen extends StatelessWidget {
                             ),
                           ),
                         ),
-                        const SizedBox(height: 15),
+                        const SizedBox(height: 10),
+                        Query(
+                          options: QueryOptions(
+                            document: gql(getId),
+                            variables: {
+                              'pubkey': _historyProvider.pubkey,
+                            },
+                          ),
+                          builder: (QueryResult result,
+                              {VoidCallback refetch, FetchMore fetchMore}) {
+                            if (result.isLoading || result.hasException) {
+                              return const Text('...');
+                            } else if (result.data['idty'] == null ||
+                                result.data['idty']['username'] == null) {
+                              return const Text('');
+                            } else {
+                              return SizedBox(
+                                width: 230,
+                                child: Text(
+                                  result?.data['idty']['username'] ?? '',
+                                  style: const TextStyle(
+                                    fontSize: 27,
+                                    color: Color(0xff814C00),
+                                  ),
+                                ),
+                              );
+                            }
+                          },
+                        ),
+                        const SizedBox(height: 25),
                         FutureBuilder(
                             future: _cesiumPlusProvider
                                 .getName(_historyProvider.pubkey),
@@ -80,7 +112,7 @@ class WalletViewScreen extends StatelessWidget {
                                 child: Text(
                                   snapshot.data ?? '-',
                                   style: const TextStyle(
-                                      fontSize: 20, color: Color(0xff814C00)),
+                                      fontSize: 18, color: Colors.black),
                                 ),
                               );
                             }),
@@ -113,8 +145,19 @@ class WalletViewScreen extends StatelessWidget {
                             ]);
                           }
                           if (_avatar.hasData) {
-                            return ClipOval(
-                              child: _avatar.data,
+                            return GestureDetector(
+                              key: const Key('openAvatar'),
+                              onTap: () {
+                                Navigator.push(
+                                  context,
+                                  MaterialPageRoute(builder: (context) {
+                                    return AvatarFullscreen(_avatar.data);
+                                  }),
+                                );
+                              },
+                              child: ClipOval(
+                                child: _avatar.data,
+                              ),
                             );
                           }
                           return ClipOval(
@@ -122,7 +165,7 @@ class WalletViewScreen extends StatelessWidget {
                                 _cesiumPlusProvider.defaultAvatar(_avatarSize),
                           );
                         }),
-                    const SizedBox(height: 30),
+                    const SizedBox(height: 25),
                   ]),
                 ]),
               ),
-- 
GitLab