show cert state on profile view

This commit is contained in:
poka 2022-06-05 19:58:04 +02:00
parent bd87aee7ec
commit c82700a45f
4 changed files with 224 additions and 116 deletions

View File

@ -564,8 +564,9 @@ class SubstrateSdk with ChangeNotifier {
return await idtyStatus(address) == 'Validated'; return await idtyStatus(address) == 'Validated';
} }
Future<bool> canCertify(String from, String to) async { Future<Map<String, int>> certState(String from, String to) async {
if (from != to && await isMember(from)) { if (from != to && await isMember(from)) {
Map<String, int> _result = {};
final _certData = await getCertData(from, to); final _certData = await getCertData(from, to);
final _certMeta = await getCertMeta(from); final _certMeta = await getCertMeta(from);
final int _removableOn = _certData['removableOn'] ?? 0; final int _removableOn = _certData['removableOn'] ?? 0;
@ -576,13 +577,26 @@ class SubstrateSdk with ChangeNotifier {
_removableOn.toString() + _removableOn.toString() +
'\n' + '\n' +
_nextIssuableOn.toString()); _nextIssuableOn.toString());
if (_renewableOn == 0 && _nextIssuableOn < blocNumber) { if (_nextIssuableOn > blocNumber) {
return true; 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<String> certState(String from, String to) async {
// return '';
// }
Future<Map> getCertMeta(String address) async { Future<Map> getCertMeta(String address) async {
var idtyIndex = await sdk.webView! var idtyIndex = await sdk.webView!
.evalJavascript('api.query.identity.identityIndexOf("$address")'); .evalJavascript('api.query.identity.identityIndexOf("$address")');

View File

@ -1,13 +1,13 @@
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:gecko/globals.dart'; import 'package:gecko/globals.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gecko/models/wallet_data.dart'; // import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/providers/my_wallets.dart'; // import 'package:gecko/providers/my_wallets.dart';
import 'package:gecko/providers/substrate_sdk.dart'; // import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/screens/common_elements.dart'; // import 'package:gecko/screens/common_elements.dart';
import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; // import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
import 'package:gecko/screens/transaction_in_progress.dart'; // import 'package:gecko/screens/transaction_in_progress.dart';
import 'package:provider/provider.dart'; // import 'package:provider/provider.dart';
class ManageMembership extends StatelessWidget { class ManageMembership extends StatelessWidget {
const ManageMembership({Key? key, required this.address}) : super(key: key); const ManageMembership({Key? key, required this.address}) : super(key: key);
@ -39,51 +39,44 @@ class ManageMembership extends StatelessWidget {
return InkWell( return InkWell(
key: const Key('revokeIdty'), key: const Key('revokeIdty'),
onTap: () async { onTap: () async {
final _answer = await confirmPopup(context, // TODO: Generate revoke document, and understand extrinsic identity.revokeIdentity options
'Êtes-vous certains de vouloir révoquer définitivement cette identité ?') ?? // final _answer = await confirmPopup(context,
false; // 'Êtes-vous certains de vouloir révoquer définitivement cette identité ?') ??
// false;
if (_answer) { // if (_answer) {
MyWalletsProvider _myWalletProvider = // MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false); // Provider.of<MyWalletsProvider>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false); // SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
MyWalletsProvider _mw = MyWalletsProvider(); // MyWalletsProvider _mw = MyWalletsProvider();
final _wallet = _mw.getWalletDataByAddress(address); // final _wallet = _mw.getWalletDataByAddress(address);
await _sub.setCurrentWallet(_wallet!); // await _sub.setCurrentWallet(_wallet!);
WalletData? defaultWallet = _myWalletProvider.getDefaultWallet(); // WalletData? defaultWallet = _myWalletProvider.getDefaultWallet();
String? _pin; // String? _pin;
if (_myWalletProvider.pinCode == '') { // if (_myWalletProvider.pinCode == '') {
_pin = await Navigator.push( // _pin = await Navigator.push(
context, // context,
MaterialPageRoute( // MaterialPageRoute(
builder: (homeContext) { // builder: (homeContext) {
return UnlockingWallet(wallet: defaultWallet); // 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,
// ); // );
// }), // }
// ); // 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( child: SizedBox(
height: 40, height: 40,

View File

@ -51,6 +51,11 @@ class TransactionInProgress extends StatelessWidget {
_actionName = "Confirmation d'identité"; _actionName = "Confirmation d'identité";
} }
break; break;
case 'revokeIdty':
{
_actionName = "Révocation d'adhésion";
}
break;
default: default:
{ {
_actionName = 'Transaction étrange'; _actionName = 'Transaction étrange';

View File

@ -130,77 +130,173 @@ class WalletViewScreen extends StatelessWidget {
WalletData? _defaultWallet = WalletData? _defaultWallet =
_myWalletProvider.getDefaultWallet(); _myWalletProvider.getDefaultWallet();
return FutureBuilder( return FutureBuilder(
future: _sub.canCertify(_defaultWallet.address!, pubkey!), future: _sub.certState(_defaultWallet.address!,
builder: (context, AsyncSnapshot<bool?> snapshot) { pubkey!), // .canCertify(_defaultWallet.address!, pubkey!),
builder: (context, AsyncSnapshot<Map<String, int>> 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( return Visibility(
visible: (snapshot.data ?? false), visible: (snapshot.data != {}),
child: Column(children: <Widget>[ child: Column(children: <Widget>[
SizedBox( if (snapshot.data!['canCert'] != null)
height: buttonSize, Column(children: <Widget>[
child: ClipOval( SizedBox(
child: Material( height: buttonSize,
color: const Color(0xffFFD58D), // button color child: ClipOval(
child: InkWell( child: Material(
key: const Key('copyKey'), color:
splashColor: orangeC, // inkwell color const Color(0xffFFD58D), // button color
child: const Padding( child: InkWell(
padding: EdgeInsets.only(bottom: 0), 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<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),
),
]),
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( child: Image(
image: AssetImage( image: AssetImage(
'assets/gecko_certify.png')), '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');
}),
);
}
}
}),
), ),
), Text(
), "Vous devez attendre\n$_duration avant\nde pouvoir certifier",
const SizedBox(height: 9), textAlign: TextAlign.center,
Text( style: TextStyle(
"Certifier", fontSize: buttonFontSize - 4,
textAlign: TextAlign.center, fontWeight: FontWeight.w400,
style: TextStyle( color: Colors.grey[600]),
fontSize: buttonFontSize, ),
fontWeight: FontWeight.w500), ]),
), if (snapshot.data!['certRenewable'] != 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(
"Vous pourrez renouveller cette certification\ndans \n$_duration",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: buttonFontSize - 4,
fontWeight: FontWeight.w400,
color: Colors.grey[600]),
),
]),
]), ]),
); );
}, },