feat: add certifications up and down; Check if wallet exist in wallet_view

This commit is contained in:
poka 2022-06-03 18:15:45 +02:00
parent 1eb966046c
commit 1cd3f74c6c
4 changed files with 307 additions and 301 deletions

View File

@ -219,11 +219,16 @@ class SubstrateSdk with ChangeNotifier {
.evalJavascript('api.query.cert.storageIdtyCertMeta($idtyIndex)') ?? .evalJavascript('api.query.cert.storageIdtyCertMeta($idtyIndex)') ??
[]; [];
log.d(_certsReceiver['receivedCount']);
return [_certsReceiver['receivedCount'], _certsReceiver['issuedCount']]; return [_certsReceiver['receivedCount'], _certsReceiver['issuedCount']];
} }
Future<bool> 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<double> getBalance(String address, {bool isUd = false}) async { Future<double> getBalance(String address, {bool isUd = false}) async {
double balance = 0.0; double balance = 0.0;
if (nodeConnected) { if (nodeConnected) {

View File

@ -108,6 +108,15 @@ class WalletOptionsProvider with ChangeNotifier {
Widget idtyStatus(BuildContext context, String address, Widget idtyStatus(BuildContext context, String address,
{bool isOwner = false}) { {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<SubstrateSdk>(builder: (context, _sub, _) { return Consumer<SubstrateSdk>(builder: (context, _sub, _) {
return FutureBuilder( return FutureBuilder(
future: _sub.idtyStatus(address), future: _sub.idtyStatus(address),
@ -116,70 +125,39 @@ class WalletOptionsProvider with ChangeNotifier {
switch (snapshot.data.toString()) { switch (snapshot.data.toString()) {
case 'noid': case 'noid':
{ {
return Column(children: const <Widget>[ return _showText('Aucune identité');
Text(
'Aucune identité',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
} }
case 'Created': case 'Created':
{ {
return Column(children: <Widget>[ return isOwner
isOwner
? InkWell( ? InkWell(
child: const Text( child: _showText(
'Identité créé, cliquez pour la confirmer', 'Cliquez ici pour confirmer\nvotre nouvelle identité',
style: 18,
TextStyle(fontSize: 18, color: Colors.black), true),
),
onTap: () async { onTap: () async {
await validateIdentity(context); await validateIdentity(context);
}, },
) )
: const Text( : _showText('Identité créé');
'Identité créé',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
} }
case 'ConfirmedByOwner': case 'ConfirmedByOwner':
{ {
return Column(children: const <Widget>[ return _showText('Identité confirmé');
Text(
'Identité confirmé',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
} }
case 'Validated': case 'Validated':
{ {
return Column(children: const <Widget>[ return _showText('Membre validé !');
Text(
'Membre validé !',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
} }
case 'expired': case 'expired':
{ {
return Column(children: const <Widget>[ return _showText('Identité expiré');
Text(
'Identité expiré',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
} }
} }
return SizedBox( return SizedBox(
child: Column(children: const <Widget>[ child: _showText('Statut inconnu'),
Text(
'Statut inconnu',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]),
); );
}); });
}); });
@ -198,29 +176,60 @@ class WalletOptionsProvider with ChangeNotifier {
barrierDismissible: true, // user must tap button! barrierDismissible: true, // user must tap button!
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( 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( content: SizedBox(
height: 100, height: 100,
child: Column(children: [ child: Column(children: [
const Text('Nom:'), const SizedBox(height: 20),
const Text(
'Nom:',
style: TextStyle(fontSize: 19),
),
TextField( TextField(
onChanged: (_) => notifyListeners(),
textAlign: TextAlign.center,
autofocus: true, autofocus: true,
controller: idtyName, controller: idtyName,
style: const TextStyle(fontSize: 19),
) )
]), ]),
), ),
actions: <Widget>[ actions: <Widget>[
TextButton( Row(
child: const Text("Valider"), mainAxisAlignment: MainAxisAlignment.center,
onPressed: () async { children: [
final _wallet = Consumer<WalletOptionsProvider>(
_myWalletProvider.getWalletDataByAddress(address.text); builder: (context, _wOptions, _) {
await _sub.setCurrentWallet(_wallet!); return TextButton(
_sub.confirmIdentity(_walletOptions.address.text, idtyName.text, key: const Key('infoPopup'),
_myWalletProvider.pinCode); child: Text(
Navigator.pop(context); "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<String, String> certCache = {};
Widget getCerts(BuildContext context, String address, double size, Widget getCerts(BuildContext context, String address, double size,
[Color _color = Colors.black]) { [Color _color = Colors.black]) {
return Column(children: <Widget>[ return Column(children: <Widget>[
Consumer<SubstrateSdk>(builder: (context, _sdk, _) { Consumer<SubstrateSdk>(builder: (context, _sdk, _) {
return FutureBuilder( return FutureBuilder(
future: _sdk.getCerts(address), future: _sdk.getCerts(address),
builder: (BuildContext context, AsyncSnapshot<List?>? _certs) { builder: (BuildContext context, AsyncSnapshot<List<int>> _certs) {
if (_certs!.connectionState != ConnectionState.done || // log.d(_certs.data);
_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()}"
: '';
return Text( return _certs.data?[0] != 0
certCache[address]!, ? Row(
style: TextStyle( children: [
fontSize: isTall ? size : size * 0.9, const Icon(
color: _color, 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('');
}); });
}), }),
]); ]);

View File

@ -91,36 +91,27 @@ class WalletOptions extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[ children: <Widget>[
const Spacer(flex: 5), const Spacer(flex: 1),
avatar(walletProvider), avatar(walletProvider),
// const Spacer(flex: 1), const Spacer(flex: 1),
Column(children: <Widget>[ Column(children: <Widget>[
walletName(walletProvider, _walletOptions), walletName(walletProvider, _walletOptions),
SizedBox(height: isTall ? 5 : 0), SizedBox(height: isTall ? 5 : 0),
SizedBox(
width: 350,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// SizedBox(height: isTall ? 5 : 0), // SizedBox(height: isTall ? 5 : 0),
balance( balance(context, walletProvider.address.text, 21),
context, walletProvider.address.text, 21),
const SizedBox(width: 30), const SizedBox(width: 30),
Column( Column(
crossAxisAlignment: crossAxisAlignment: CrossAxisAlignment.center,
CrossAxisAlignment.start,
children: [ children: [
_walletOptions.idtyStatus(context, _walletOptions.idtyStatus(
_walletOptions.address.text, context, _walletOptions.address.text,
isOwner: true), isOwner: true),
getCerts(context, getCerts(
walletProvider.address.text, 15), context, walletProvider.address.text, 15),
]), ]),
]),
),
SizedBox(height: 10 * ratio), SizedBox(height: 10 * ratio),
]), ]),
const Spacer(flex: 1), const Spacer(flex: 2),
]), ]),
); );
}), }),

View File

@ -59,7 +59,7 @@ class WalletViewScreen extends StatelessWidget {
child: Column(children: <Widget>[ child: Column(children: <Widget>[
headerProfileView( headerProfileView(
context, _walletViewProvider, _cesiumPlusProvider), context, _walletViewProvider, _cesiumPlusProvider),
SizedBox(height: isTall ? 50 : 20), SizedBox(height: isTall ? 10 : 0),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
Column(children: <Widget>[ Column(children: <Widget>[
SizedBox( SizedBox(
@ -570,28 +570,38 @@ class WalletViewScreen extends StatelessWidget {
WalletOptionsProvider _walletOptions = WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context, listen: false); Provider.of<WalletOptionsProvider>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
return Column(children: <Widget>[ // AsyncSnapshot<bool> isAccountExist;
Container(
height: 10, return Stack(children: <Widget>[
color: yellowC, FutureBuilder(
), future: _sub.isAccountExit(pubkey!),
Container( builder: (BuildContext context, AsyncSnapshot<bool> isAccountExist) {
final bool _isExit = isAccountExist.data ?? false;
return Container(
height: 180,
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: Alignment.topCenter, begin: Alignment.topCenter,
end: Alignment.bottomCenter, end: Alignment.bottomCenter,
colors: [ colors: [
yellowC, _isExit ? yellowC : Colors.grey[400]!,
const Color(0xFFE7811A), _isExit ? const Color(0xFFE7811A) : Colors.grey[600]!,
], ],
)), ),
child: Padding( ));
}),
Padding(
padding: const EdgeInsets.only(left: 30, right: 40), padding: const EdgeInsets.only(left: 30, right: 40),
child: Row(children: <Widget>[ child: Row(children: <Widget>[
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Container(
height: 10,
color: yellowC, // Colors.grey[400],
),
Row(children: [ Row(children: [
GestureDetector( GestureDetector(
key: const Key('copyPubkey'), key: const Key('copyPubkey'),
@ -763,7 +773,6 @@ class WalletViewScreen extends StatelessWidget {
]), ]),
]), ]),
), ),
),
]); ]);
} }
} }