From 1cd3f74c6cce52b2407b566d385d768f82e725b9 Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 3 Jun 2022 18:15:45 +0200 Subject: [PATCH] feat: add certifications up and down; Check if wallet exist in wallet_view --- lib/providers/substrate_sdk.dart | 9 +- lib/providers/wallet_options.dart | 177 +++++----- lib/screens/myWallets/wallet_options.dart | 39 +-- lib/screens/wallet_view.dart | 383 +++++++++++----------- 4 files changed, 307 insertions(+), 301 deletions(-) diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index 230cd12..6510e87 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -219,11 +219,16 @@ class SubstrateSdk with ChangeNotifier { .evalJavascript('api.query.cert.storageIdtyCertMeta($idtyIndex)') ?? []; - log.d(_certsReceiver['receivedCount']); - return [_certsReceiver['receivedCount'], _certsReceiver['issuedCount']]; } + Future isAccountExit(String address) async { + final _accountInfo = await sdk.webView! + .evalJavascript('api.query.system.account("$address")'); + final _randomId = _accountInfo['data']['randomId']; + return _randomId == null ? false : true; + } + 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 f064b3b..a163d01 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -108,6 +108,15 @@ class WalletOptionsProvider with ChangeNotifier { Widget idtyStatus(BuildContext context, String address, {bool isOwner = false}) { + _showText(String text, [double size = 18, bool _bold = false]) => Text( + text, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: size, + color: _bold ? orangeC : Colors.black, + fontWeight: _bold ? FontWeight.w500 : FontWeight.w400), + ); + return Consumer(builder: (context, _sub, _) { return FutureBuilder( future: _sub.idtyStatus(address), @@ -116,70 +125,39 @@ class WalletOptionsProvider with ChangeNotifier { switch (snapshot.data.toString()) { case 'noid': { - return Column(children: const [ - Text( - 'Aucune identité', - style: TextStyle(fontSize: 18, color: Colors.black), - ), - ]); + return _showText('Aucune identité'); } case 'Created': { - return Column(children: [ - isOwner - ? InkWell( - child: const Text( - 'Identité créé, cliquez pour la confirmer', - style: - TextStyle(fontSize: 18, color: Colors.black), - ), - onTap: () async { - await validateIdentity(context); - }, - ) - : const Text( - 'Identité créé', - style: TextStyle(fontSize: 18, color: Colors.black), - ), - ]); + return isOwner + ? InkWell( + child: _showText( + 'Cliquez ici pour confirmer\nvotre nouvelle identité', + 18, + true), + onTap: () async { + await validateIdentity(context); + }, + ) + : _showText('Identité créé'); } case 'ConfirmedByOwner': { - return Column(children: const [ - Text( - 'Identité confirmé', - style: TextStyle(fontSize: 18, color: Colors.black), - ), - ]); + return _showText('Identité confirmé'); } case 'Validated': { - return Column(children: const [ - Text( - 'Membre validé !', - style: TextStyle(fontSize: 18, color: Colors.black), - ), - ]); + return _showText('Membre validé !'); } case 'expired': { - return Column(children: const [ - Text( - 'Identité expiré', - style: TextStyle(fontSize: 18, color: Colors.black), - ), - ]); + return _showText('Identité expiré'); } } return SizedBox( - child: Column(children: const [ - Text( - 'Statut inconnu', - style: TextStyle(fontSize: 18, color: Colors.black), - ), - ]), + child: _showText('Statut inconnu'), ); }); }); @@ -198,29 +176,60 @@ class WalletOptionsProvider with ChangeNotifier { barrierDismissible: true, // user must tap button! builder: (BuildContext context) { return AlertDialog( - title: const Text('Confirmez votre identité'), + title: const Text( + 'Confirmez votre identité', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500), + ), content: SizedBox( height: 100, child: Column(children: [ - const Text('Nom:'), + const SizedBox(height: 20), + const Text( + 'Nom:', + style: TextStyle(fontSize: 19), + ), TextField( + onChanged: (_) => notifyListeners(), + textAlign: TextAlign.center, autofocus: true, controller: idtyName, + style: const TextStyle(fontSize: 19), ) ]), ), actions: [ - TextButton( - child: const Text("Valider"), - onPressed: () async { - final _wallet = - _myWalletProvider.getWalletDataByAddress(address.text); - await _sub.setCurrentWallet(_wallet!); - _sub.confirmIdentity(_walletOptions.address.text, idtyName.text, - _myWalletProvider.pinCode); - Navigator.pop(context); - }, + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Consumer( + builder: (context, _wOptions, _) { + return TextButton( + key: const Key('infoPopup'), + child: Text( + "Valider", + style: TextStyle( + fontSize: 21, + color: idtyName.text.length >= 2 + ? const Color(0xffD80000) + : Colors.grey, + ), + ), + onPressed: () async { + if (idtyName.text.length >= 2) { + final _wallet = _myWalletProvider + .getWalletDataByAddress(address.text); + await _sub.setCurrentWallet(_wallet!); + _sub.confirmIdentity(_walletOptions.address.text, + idtyName.text, _myWalletProvider.pinCode); + Navigator.pop(context); + } + }, + ); + }) + ], ), + const SizedBox(height: 20) ], ); }, @@ -291,42 +300,34 @@ 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()}" - : ''; + builder: (BuildContext context, AsyncSnapshot> _certs) { + // log.d(_certs.data); - return Text( - certCache[address]!, - style: TextStyle( - fontSize: isTall ? size : size * 0.9, - color: _color, - ), - ); + return _certs.data?[0] != 0 + ? Row( + children: [ + const Icon( + Icons.arrow_drop_down, + color: Colors.green, + size: 30, + ), + Text(_certs.data?[0].toString() ?? '0'), + const SizedBox(width: 15), + const Icon( + Icons.arrow_drop_up, + color: Colors.blue, + size: 30, + ), + Text(_certs.data?[1].toString() ?? '0') + ], + ) + : const Text(''); }); }), ]); diff --git a/lib/screens/myWallets/wallet_options.dart b/lib/screens/myWallets/wallet_options.dart index 7bf0ef4..a589487 100644 --- a/lib/screens/myWallets/wallet_options.dart +++ b/lib/screens/myWallets/wallet_options.dart @@ -91,36 +91,27 @@ class WalletOptions extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - const Spacer(flex: 5), + const Spacer(flex: 1), avatar(walletProvider), - // const Spacer(flex: 1), + const Spacer(flex: 1), Column(children: [ walletName(walletProvider, _walletOptions), SizedBox(height: isTall ? 5 : 0), - 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: isTall ? 5 : 0), + balance(context, walletProvider.address.text, 21), + const SizedBox(width: 30), + Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + _walletOptions.idtyStatus( + context, _walletOptions.address.text, + isOwner: true), + getCerts( + context, walletProvider.address.text, 15), + ]), SizedBox(height: 10 * ratio), ]), - const Spacer(flex: 1), + const Spacer(flex: 2), ]), ); }), diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index ec6d886..e97e3e6 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -59,7 +59,7 @@ class WalletViewScreen extends StatelessWidget { child: Column(children: [ headerProfileView( context, _walletViewProvider, _cesiumPlusProvider), - SizedBox(height: isTall ? 50 : 20), + SizedBox(height: isTall ? 10 : 0), Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Column(children: [ SizedBox( @@ -570,199 +570,208 @@ class WalletViewScreen extends StatelessWidget { WalletOptionsProvider _walletOptions = Provider.of(context, listen: false); + SubstrateSdk _sub = Provider.of(context, listen: false); - return Column(children: [ - Container( - height: 10, - color: yellowC, - ), - Container( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - yellowC, - const Color(0xFFE7811A), - ], - )), - child: Padding( - padding: const EdgeInsets.only(left: 30, right: 40), - child: Row(children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row(children: [ - GestureDetector( - key: const Key('copyPubkey'), - onTap: () { - Clipboard.setData(ClipboardData(text: pubkey)); - snackCopyKey(context); - }, - child: Text( - getShortPubkey(pubkey!), - style: const TextStyle( - fontSize: 30, - fontWeight: FontWeight.w800, - ), - ), - ), - ]), - const SizedBox(height: 25), + // AsyncSnapshot isAccountExist; - 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) - // Query( - // options: QueryOptions( - // document: gql(getId), - // variables: { - // 'pubkey': 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) { - // g1WalletsBox.get(pubkey)?.username = ''; - // return const Text(''); - // } else { - // g1WalletsBox.get(pubkey)?.username = - // result.data!['idty']['username'] ?? ''; - // return SizedBox( - // width: 230, - // child: Text( - // result.data!['idty']['username'] ?? '', - // style: const TextStyle( - // fontSize: 27, - // color: Color(0xff814C00), - // ), - // ), - // ); - // } - // }, - // ), - if (username == null && - g1WalletsBox.get(pubkey)?.username != null) - SizedBox( - width: 230, - child: Text( - g1WalletsBox.get(pubkey)?.username ?? '', - style: const TextStyle( - fontSize: 27, - color: Color(0xff814C00), - ), - ), - ), - if (username != null) - SizedBox( - width: 230, - child: Text( - username!, - style: const TextStyle( - fontSize: 27, - color: Color(0xff814C00), - ), - ), - ), - const SizedBox(height: 25), - //// To get Cs+ name - // FutureBuilder( - // future: _cesiumPlusProvider.getName(pubkey), - // initialData: '...', - // builder: (context, snapshot) { - // return SizedBox( - // width: 230, - // child: Text( - // snapshot.data.toString(), - // style: const TextStyle( - // fontSize: 18, color: Colors.black), - // ), - // ); - // }), - const SizedBox(height: 30), - ]), - const Spacer(), - Column(children: [ - if (avatar == null) - ClipOval( - child: _cesiumPlusProvider.defaultAvatar(_avatarSize), + return Stack(children: [ + FutureBuilder( + future: _sub.isAccountExit(pubkey!), + builder: (BuildContext context, AsyncSnapshot isAccountExist) { + final bool _isExit = isAccountExist.data ?? false; + return Container( + height: 180, + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + _isExit ? yellowC : Colors.grey[400]!, + _isExit ? const Color(0xFFE7811A) : Colors.grey[600]!, + ], + ), + )); + }), + Padding( + padding: const EdgeInsets.only(left: 30, right: 40), + child: Row(children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + height: 10, + color: yellowC, // Colors.grey[400], ), - // FutureBuilder( - // future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize), - // builder: - // (BuildContext context, AsyncSnapshot _avatar) { - // if (_avatar.connectionState != ConnectionState.done) { - // return Stack(children: [ - // ClipOval( - // child: - // _cesiumPlusProvider.defaultAvatar(_avatarSize), - // ), - // Positioned( - // top: 15, - // right: 45, - // width: 51, - // height: 51, - // child: CircularProgressIndicator( - // strokeWidth: 5, - // color: orangeC, - // ), - // ), - // ]); - // } - // if (_avatar.hasData) { - // return GestureDetector( - // key: const Key('openAvatar'), - // onTap: () { - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) { - // return AvatarFullscreen(_avatar.data); - // }), - // ); - // }, - // child: ClipOval( - // child: Image( - // image: _avatar.data!.image, - // height: _avatarSize, - // fit: BoxFit.cover, - // ), - // ), - // ); - // } - // return ClipOval( - // child: _cesiumPlusProvider.defaultAvatar(_avatarSize), - // ); - // }), - if (avatar != null) - GestureDetector( - key: const Key('openAvatar'), - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return AvatarFullscreen(avatar); - }), - ); - }, - child: ClipOval( - child: Image( - image: avatar!.image, - height: _avatarSize, - fit: BoxFit.cover, + Row(children: [ + GestureDetector( + key: const Key('copyPubkey'), + onTap: () { + Clipboard.setData(ClipboardData(text: pubkey)); + snackCopyKey(context); + }, + child: Text( + getShortPubkey(pubkey!), + style: const TextStyle( + fontSize: 30, + fontWeight: FontWeight.w800, + ), ), ), + ]), + const SizedBox(height: 25), + + 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) + // Query( + // options: QueryOptions( + // document: gql(getId), + // variables: { + // 'pubkey': 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) { + // g1WalletsBox.get(pubkey)?.username = ''; + // return const Text(''); + // } else { + // g1WalletsBox.get(pubkey)?.username = + // result.data!['idty']['username'] ?? ''; + // return SizedBox( + // width: 230, + // child: Text( + // result.data!['idty']['username'] ?? '', + // style: const TextStyle( + // fontSize: 27, + // color: Color(0xff814C00), + // ), + // ), + // ); + // } + // }, + // ), + if (username == null && + g1WalletsBox.get(pubkey)?.username != null) + SizedBox( + width: 230, + child: Text( + g1WalletsBox.get(pubkey)?.username ?? '', + style: const TextStyle( + fontSize: 27, + color: Color(0xff814C00), + ), + ), + ), + if (username != null) + SizedBox( + width: 230, + child: Text( + username!, + style: const TextStyle( + fontSize: 27, + color: Color(0xff814C00), + ), + ), + ), + const SizedBox(height: 25), + //// To get Cs+ name + // FutureBuilder( + // future: _cesiumPlusProvider.getName(pubkey), + // initialData: '...', + // builder: (context, snapshot) { + // return SizedBox( + // width: 230, + // child: Text( + // snapshot.data.toString(), + // style: const TextStyle( + // fontSize: 18, color: Colors.black), + // ), + // ); + // }), + const SizedBox(height: 30), + ]), + const Spacer(), + Column(children: [ + if (avatar == null) + ClipOval( + child: _cesiumPlusProvider.defaultAvatar(_avatarSize), + ), + // FutureBuilder( + // future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize), + // builder: + // (BuildContext context, AsyncSnapshot _avatar) { + // if (_avatar.connectionState != ConnectionState.done) { + // return Stack(children: [ + // ClipOval( + // child: + // _cesiumPlusProvider.defaultAvatar(_avatarSize), + // ), + // Positioned( + // top: 15, + // right: 45, + // width: 51, + // height: 51, + // child: CircularProgressIndicator( + // strokeWidth: 5, + // color: orangeC, + // ), + // ), + // ]); + // } + // if (_avatar.hasData) { + // return GestureDetector( + // key: const Key('openAvatar'), + // onTap: () { + // Navigator.push( + // context, + // MaterialPageRoute(builder: (context) { + // return AvatarFullscreen(_avatar.data); + // }), + // ); + // }, + // child: ClipOval( + // child: Image( + // image: _avatar.data!.image, + // height: _avatarSize, + // fit: BoxFit.cover, + // ), + // ), + // ); + // } + // return ClipOval( + // child: _cesiumPlusProvider.defaultAvatar(_avatarSize), + // ); + // }), + if (avatar != null) + GestureDetector( + key: const Key('openAvatar'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return AvatarFullscreen(avatar); + }), + ); + }, + child: ClipOval( + child: Image( + image: avatar!.image, + height: _avatarSize, + fit: BoxFit.cover, + ), ), - const SizedBox(height: 25), - ]), + ), + const SizedBox(height: 25), ]), - ), + ]), ), ]); }