From 1eb966046c07a240b8b33b1c63b88dd0b62ef29f Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 2 Jun 2022 19:58:23 +0200 Subject: [PATCH] WIP: get received/sent certs --- lib/providers/substrate_sdk.dart | 14 ++++++++ lib/providers/wallet_options.dart | 42 ++++++++++++++++++++++- lib/screens/myWallets/wallet_options.dart | 34 +++++++++++++----- lib/screens/wallet_view.dart | 7 ++-- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index 4b28bad..230cd12 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -210,6 +210,20 @@ class SubstrateSdk with ChangeNotifier { return result; } + Future> getCerts(String address) async { + final idtyIndex = await sdk.webView! + .evalJavascript('api.query.identity.identityIndexOf("$address")'); + log.d(idtyIndex); + + final _certsReceiver = await sdk.webView! + .evalJavascript('api.query.cert.storageIdtyCertMeta($idtyIndex)') ?? + []; + + log.d(_certsReceiver['receivedCount']); + + return [_certsReceiver['receivedCount'], _certsReceiver['issuedCount']]; + } + Future getBalance(String address, {bool isUd = false}) async { double balance = 0.0; if (nodeConnected) { diff --git a/lib/providers/wallet_options.dart b/lib/providers/wallet_options.dart index df905a2..f064b3b 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -174,7 +174,6 @@ class WalletOptionsProvider with ChangeNotifier { } } return SizedBox( - width: 230, child: Column(children: const [ Text( 'Statut inconnu', @@ -291,3 +290,44 @@ Widget balance(BuildContext context, String address, double size, }), ]); } + +Map certCache = {}; +Widget getCerts(BuildContext context, String address, double size, + [Color _color = Colors.black]) { + return Column(children: [ + Consumer(builder: (context, _sdk, _) { + return FutureBuilder( + future: _sdk.getCerts(address), + builder: (BuildContext context, AsyncSnapshot? _certs) { + if (_certs!.connectionState != ConnectionState.done || + _certs.hasError) { + if (certCache[address] != null) { + return Text(certCache[address]!, + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: _color)); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: orangeC, + strokeWidth: 2, + ), + ); + } + } + certCache[address] = _certs.data![0] != 0 + ? "Certifications reçus: ${_certs.data![0].toString()}\nCertifications envoyés: ${_certs.data![1].toString()}" + : ''; + + return Text( + certCache[address]!, + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: _color, + ), + ); + }); + }), + ]); +} diff --git a/lib/screens/myWallets/wallet_options.dart b/lib/screens/myWallets/wallet_options.dart index 8a71592..7bf0ef4 100644 --- a/lib/screens/myWallets/wallet_options.dart +++ b/lib/screens/myWallets/wallet_options.dart @@ -91,23 +91,39 @@ class WalletOptions extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - const Spacer(flex: 1), + const Spacer(flex: 5), avatar(walletProvider), - const Spacer(flex: 1), + // const Spacer(flex: 1), Column(children: [ walletName(walletProvider, _walletOptions), SizedBox(height: isTall ? 5 : 0), - balance(context, walletProvider.address.text, 20), - SizedBox(height: isTall ? 5 : 0), - _walletOptions.idtyStatus( - context, _walletOptions.address.text, - isOwner: true), + SizedBox( + width: 350, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // SizedBox(height: isTall ? 5 : 0), + balance( + context, walletProvider.address.text, 21), + const SizedBox(width: 30), + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + _walletOptions.idtyStatus(context, + _walletOptions.address.text, + isOwner: true), + getCerts(context, + walletProvider.address.text, 15), + ]), + ]), + ), + SizedBox(height: 10 * ratio), ]), - const Spacer(flex: 3), + const Spacer(flex: 1), ]), ); }), - SizedBox(height: 10 * ratio), Expanded( child: SingleChildScrollView( child: Column(children: [ diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index e665aef..ec6d886 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -609,12 +609,11 @@ class WalletViewScreen extends StatelessWidget { ), ]), const SizedBox(height: 25), - Consumer( - builder: (context, walletProvider, _) { - return balance(context, pubkey!, 22); - }), + + balance(context, pubkey!, 22), const SizedBox(height: 10), _walletOptions.idtyStatus(context, pubkey!, isOwner: false), + getCerts(context, pubkey!, 14), // if (username == null && // g1WalletsBox.get(pubkey)?.username == null)