diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index 21e8c90..feeac4d 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -564,8 +564,9 @@ class SubstrateSdk with ChangeNotifier { return await idtyStatus(address) == 'Validated'; } - Future canCertify(String from, String to) async { + Future> certState(String from, String to) async { if (from != to && await isMember(from)) { + Map _result = {}; final _certData = await getCertData(from, to); final _certMeta = await getCertMeta(from); final int _removableOn = _certData['removableOn'] ?? 0; @@ -576,13 +577,26 @@ class SubstrateSdk with ChangeNotifier { _removableOn.toString() + '\n' + _nextIssuableOn.toString()); - if (_renewableOn == 0 && _nextIssuableOn < blocNumber) { - return true; + if (_nextIssuableOn > blocNumber) { + final certDelayDuration = (_nextIssuableOn - blocNumber) * 6; + _result.putIfAbsent('certDelay', () => certDelayDuration); + return _result; + } else if (_renewableOn != 0) { + final certRenewDuration = (_renewableOn - blocNumber) * 6; + _result.putIfAbsent('certRenewable', () => certRenewDuration); + return _result; + } else { + _result.putIfAbsent('canCert', () => 0); + return _result; } } - return false; + return {}; } + // Future certState(String from, String to) async { + // return ''; + // } + Future getCertMeta(String address) async { var idtyIndex = await sdk.webView! .evalJavascript('api.query.identity.identityIndexOf("$address")'); diff --git a/lib/screens/myWallets/manage_membership.dart b/lib/screens/myWallets/manage_membership.dart index 1677f85..4ef851b 100644 --- a/lib/screens/myWallets/manage_membership.dart +++ b/lib/screens/myWallets/manage_membership.dart @@ -1,13 +1,13 @@ import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; import 'package:flutter/material.dart'; -import 'package:gecko/models/wallet_data.dart'; -import 'package:gecko/providers/my_wallets.dart'; -import 'package:gecko/providers/substrate_sdk.dart'; -import 'package:gecko/screens/common_elements.dart'; -import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; -import 'package:gecko/screens/transaction_in_progress.dart'; -import 'package:provider/provider.dart'; +// import 'package:gecko/models/wallet_data.dart'; +// import 'package:gecko/providers/my_wallets.dart'; +// import 'package:gecko/providers/substrate_sdk.dart'; +// import 'package:gecko/screens/common_elements.dart'; +// import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; +// import 'package:gecko/screens/transaction_in_progress.dart'; +// import 'package:provider/provider.dart'; class ManageMembership extends StatelessWidget { const ManageMembership({Key? key, required this.address}) : super(key: key); @@ -39,51 +39,44 @@ class ManageMembership extends StatelessWidget { return InkWell( key: const Key('revokeIdty'), onTap: () async { - final _answer = await confirmPopup(context, - 'Êtes-vous certains de vouloir révoquer définitivement cette identité ?') ?? - false; + // TODO: Generate revoke document, and understand extrinsic identity.revokeIdentity options + // final _answer = await confirmPopup(context, + // 'Êtes-vous certains de vouloir révoquer définitivement cette identité ?') ?? + // false; - if (_answer) { - MyWalletsProvider _myWalletProvider = - Provider.of(context, listen: false); - SubstrateSdk _sub = Provider.of(context, listen: false); + // if (_answer) { + // MyWalletsProvider _myWalletProvider = + // Provider.of(context, listen: false); + // SubstrateSdk _sub = Provider.of(context, listen: false); - MyWalletsProvider _mw = MyWalletsProvider(); - final _wallet = _mw.getWalletDataByAddress(address); - await _sub.setCurrentWallet(_wallet!); + // MyWalletsProvider _mw = MyWalletsProvider(); + // final _wallet = _mw.getWalletDataByAddress(address); + // await _sub.setCurrentWallet(_wallet!); - WalletData? defaultWallet = _myWalletProvider.getDefaultWallet(); - String? _pin; - if (_myWalletProvider.pinCode == '') { - _pin = await Navigator.push( - context, - MaterialPageRoute( - builder: (homeContext) { - return UnlockingWallet(wallet: defaultWallet); - }, - ), - ); - } - if (_pin != null || _myWalletProvider.pinCode != '') { - _sub.revokeIdentity(address, _myWalletProvider.pinCode); - } - Navigator.pop(context); - - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return const TransactionInProgress(transType: 'revokeIdty'); - }), - ); - } - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) { - // return ManageMembership( - // address: _walletOptions.address.text, + // WalletData? defaultWallet = _myWalletProvider.getDefaultWallet(); + // String? _pin; + // if (_myWalletProvider.pinCode == '') { + // _pin = await Navigator.push( + // context, + // MaterialPageRoute( + // builder: (homeContext) { + // return UnlockingWallet(wallet: defaultWallet); + // }, + // ), // ); - // }), - // ); + // } + // if (_pin != null || _myWalletProvider.pinCode != '') { + // _sub.revokeIdentity(address, _myWalletProvider.pinCode); + // } + // Navigator.pop(context); + + // Navigator.push( + // context, + // MaterialPageRoute(builder: (context) { + // return const TransactionInProgress(transType: 'revokeIdty'); + // }), + // ); + // } }, child: SizedBox( height: 40, diff --git a/lib/screens/transaction_in_progress.dart b/lib/screens/transaction_in_progress.dart index a75f402..7da1e3b 100644 --- a/lib/screens/transaction_in_progress.dart +++ b/lib/screens/transaction_in_progress.dart @@ -51,6 +51,11 @@ class TransactionInProgress extends StatelessWidget { _actionName = "Confirmation d'identité"; } break; + case 'revokeIdty': + { + _actionName = "Révocation d'adhésion"; + } + break; default: { _actionName = 'Transaction étrange'; diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index e790fb3..c5b9c69 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -130,77 +130,173 @@ class WalletViewScreen extends StatelessWidget { WalletData? _defaultWallet = _myWalletProvider.getDefaultWallet(); return FutureBuilder( - future: _sub.canCertify(_defaultWallet.address!, pubkey!), - builder: (context, AsyncSnapshot snapshot) { + future: _sub.certState(_defaultWallet.address!, + pubkey!), // .canCertify(_defaultWallet.address!, pubkey!), + builder: (context, AsyncSnapshot> snapshot) { + log.d(snapshot.data); + if (snapshot.data == null) return const SizedBox(); + String _duration = ''; + if (snapshot.data!['certDelay'] != null || + snapshot.data!['certRenewable'] != null) { + final Duration _durationSeconds = Duration( + seconds: snapshot.data!['certDelay'] ?? + snapshot.data!['certRenewable']!); + final int _seconds = _durationSeconds.inSeconds; + final int _minutes = _durationSeconds.inMinutes; + + if (_seconds <= 60) { + _duration = '$_seconds secondes'; + } else if (_seconds <= 3600) { + _duration = '$_minutes minutes'; + } else if (_seconds <= 86400) { + final int _hours = _durationSeconds.inHours; + final int _minutesLeft = _minutes - _hours * 60; + String _showMinutes = ''; + if (_minutesLeft < 60) {} + _showMinutes = ' $_minutesLeft minutes'; + _duration = '$_hours heures$_showMinutes'; + } else if (_seconds <= 2592000) { + final int _days = _durationSeconds.inDays; + _duration = '$_days jours'; + } else { + final int _months = + (_durationSeconds.inDays / 30).round(); + _duration = '$_months mois'; + } + } return Visibility( - visible: (snapshot.data ?? false), + visible: (snapshot.data != {}), child: Column(children: [ - SizedBox( - height: buttonSize, - child: ClipOval( - child: Material( - color: const Color(0xffFFD58D), // button color - child: InkWell( - key: const Key('copyKey'), - splashColor: orangeC, // inkwell color - child: const Padding( - padding: EdgeInsets.only(bottom: 0), + if (snapshot.data!['canCert'] != null) + Column(children: [ + SizedBox( + height: buttonSize, + child: ClipOval( + child: Material( + color: + const Color(0xffFFD58D), // button color + child: InkWell( + key: const Key('copyKey'), + splashColor: orangeC, // inkwell color + child: const Padding( + padding: EdgeInsets.only(bottom: 0), + child: Image( + image: AssetImage( + 'assets/gecko_certify.png')), + ), + onTap: () async { + final bool? _result = await confirmPopup( + context, + "Êtes-vous certain de vouloir certifier l'adresse:\n\n${getShortPubkey(pubkey!)}"); + + if (_result ?? false) { + String? _pin; + if (_myWalletProvider.pinCode == '') { + _pin = await Navigator.push( + context, + MaterialPageRoute( + builder: (homeContext) { + return UnlockingWallet( + wallet: defaultWallet); + }, + ), + ); + } + if (_pin != null || + _myWalletProvider.pinCode != '') { + WalletsProfilesProvider + _walletViewProvider = Provider + .of( + context, + listen: false); + final acc = _sub.getCurrentWallet(); + _sub.certify( + acc.address!, + _pin ?? + _myWalletProvider.pinCode, + _walletViewProvider.address!); + + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return const TransactionInProgress( + transType: 'cert'); + }), + ); + } + } + }), + ), + ), + ), + const SizedBox(height: 9), + Text( + "Certifier", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: buttonFontSize, + fontWeight: FontWeight.w500), + ), + ]), + if (snapshot.data!['certDelay'] != null) + Column(children: [ + 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')), ), - onTap: () async { - final bool? _result = await confirmPopup( - context, - "Êtes-vous certain de vouloir certifier l'adresse:\n\n${getShortPubkey(pubkey!)}"); - - if (_result ?? false) { - String? _pin; - if (_myWalletProvider.pinCode == '') { - _pin = await Navigator.push( - context, - MaterialPageRoute( - builder: (homeContext) { - return UnlockingWallet( - wallet: defaultWallet); - }, - ), - ); - } - if (_pin != null || - _myWalletProvider.pinCode != '') { - WalletsProfilesProvider - _walletViewProvider = Provider.of< - WalletsProfilesProvider>( - context, - listen: false); - final acc = _sub.getCurrentWallet(); - _sub.certify( - acc.address!, - _pin ?? _myWalletProvider.pinCode, - _walletViewProvider.address!); - - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return const TransactionInProgress( - transType: 'cert'); - }), - ); - } - } - }), + ), + ), ), - ), - ), - const SizedBox(height: 9), - Text( - "Certifier", - textAlign: TextAlign.center, - style: TextStyle( - fontSize: buttonFontSize, - fontWeight: FontWeight.w500), - ), + Text( + "Vous devez attendre\n$_duration avant\nde pouvoir certifier", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: buttonFontSize - 4, + fontWeight: FontWeight.w400, + color: Colors.grey[600]), + ), + ]), + if (snapshot.data!['certRenewable'] != null) + Column(children: [ + 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( + "Vous pourrez renouveller cette certification\ndans \n$_duration", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: buttonFontSize - 4, + fontWeight: FontWeight.w400, + color: Colors.grey[600]), + ), + ]), ]), ); },