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';
}
Future<bool> canCertify(String from, String to) async {
Future<Map<String, int>> certState(String from, String to) async {
if (from != to && await isMember(from)) {
Map<String, int> _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<String> certState(String from, String to) async {
// return '';
// }
Future<Map> getCertMeta(String address) async {
var idtyIndex = await sdk.webView!
.evalJavascript('api.query.identity.identityIndexOf("$address")');

View File

@ -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<MyWalletsProvider>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
// if (_answer) {
// MyWalletsProvider _myWalletProvider =
// Provider.of<MyWalletsProvider>(context, listen: false);
// SubstrateSdk _sub = Provider.of<SubstrateSdk>(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,

View File

@ -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';

View File

@ -130,77 +130,173 @@ class WalletViewScreen extends StatelessWidget {
WalletData? _defaultWallet =
_myWalletProvider.getDefaultWallet();
return FutureBuilder(
future: _sub.canCertify(_defaultWallet.address!, pubkey!),
builder: (context, AsyncSnapshot<bool?> snapshot) {
future: _sub.certState(_defaultWallet.address!,
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(
visible: (snapshot.data ?? false),
visible: (snapshot.data != {}),
child: Column(children: <Widget>[
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: <Widget>[
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<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(
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: <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]),
),
]),
]),
);
},