forked from axiom-team/gecko
show cert state on profile view
This commit is contained in:
parent
bd87aee7ec
commit
c82700a45f
|
@ -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")');
|
||||||
|
|
|
@ -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 != '') {
|
// if (_pin != null || _myWalletProvider.pinCode != '') {
|
||||||
_sub.revokeIdentity(address, _myWalletProvider.pinCode);
|
// _sub.revokeIdentity(address, _myWalletProvider.pinCode);
|
||||||
}
|
// }
|
||||||
Navigator.pop(context);
|
// Navigator.pop(context);
|
||||||
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) {
|
|
||||||
return const TransactionInProgress(transType: 'revokeIdty');
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Navigator.push(
|
// Navigator.push(
|
||||||
// context,
|
// context,
|
||||||
// MaterialPageRoute(builder: (context) {
|
// MaterialPageRoute(builder: (context) {
|
||||||
// return ManageMembership(
|
// return const TransactionInProgress(transType: 'revokeIdty');
|
||||||
// address: _walletOptions.address.text,
|
|
||||||
// );
|
|
||||||
// }),
|
// }),
|
||||||
// );
|
// );
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 40,
|
height: 40,
|
||||||
|
|
|
@ -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';
|
||||||
|
|
|
@ -130,16 +130,51 @@ 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>[
|
||||||
|
if (snapshot.data!['canCert'] != null)
|
||||||
|
Column(children: <Widget>[
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: buttonSize,
|
height: buttonSize,
|
||||||
child: ClipOval(
|
child: ClipOval(
|
||||||
child: Material(
|
child: Material(
|
||||||
color: const Color(0xffFFD58D), // button color
|
color:
|
||||||
|
const Color(0xffFFD58D), // button color
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
key: const Key('copyKey'),
|
key: const Key('copyKey'),
|
||||||
splashColor: orangeC, // inkwell color
|
splashColor: orangeC, // inkwell color
|
||||||
|
@ -170,19 +205,21 @@ class WalletViewScreen extends StatelessWidget {
|
||||||
if (_pin != null ||
|
if (_pin != null ||
|
||||||
_myWalletProvider.pinCode != '') {
|
_myWalletProvider.pinCode != '') {
|
||||||
WalletsProfilesProvider
|
WalletsProfilesProvider
|
||||||
_walletViewProvider = Provider.of<
|
_walletViewProvider = Provider
|
||||||
WalletsProfilesProvider>(
|
.of<WalletsProfilesProvider>(
|
||||||
context,
|
context,
|
||||||
listen: false);
|
listen: false);
|
||||||
final acc = _sub.getCurrentWallet();
|
final acc = _sub.getCurrentWallet();
|
||||||
_sub.certify(
|
_sub.certify(
|
||||||
acc.address!,
|
acc.address!,
|
||||||
_pin ?? _myWalletProvider.pinCode,
|
_pin ??
|
||||||
|
_myWalletProvider.pinCode,
|
||||||
_walletViewProvider.address!);
|
_walletViewProvider.address!);
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) {
|
MaterialPageRoute(
|
||||||
|
builder: (context) {
|
||||||
return const TransactionInProgress(
|
return const TransactionInProgress(
|
||||||
transType: 'cert');
|
transType: 'cert');
|
||||||
}),
|
}),
|
||||||
|
@ -202,6 +239,65 @@ class WalletViewScreen extends StatelessWidget {
|
||||||
fontWeight: FontWeight.w500),
|
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')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue