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)') ??
[];
log.d(_certsReceiver['receivedCount']);
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 {
double balance = 0.0;
if (nodeConnected) {

View File

@ -108,6 +108,15 @@ class WalletOptionsProvider with ChangeNotifier {
Widget idtyStatus(BuildContext context, String address,
{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 FutureBuilder(
future: _sub.idtyStatus(address),
@ -116,70 +125,39 @@ class WalletOptionsProvider with ChangeNotifier {
switch (snapshot.data.toString()) {
case 'noid':
{
return Column(children: const <Widget>[
Text(
'Aucune identité',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
return _showText('Aucune identité');
}
case 'Created':
{
return Column(children: <Widget>[
isOwner
? InkWell(
child: const Text(
'Identité créé, cliquez pour la confirmer',
style:
TextStyle(fontSize: 18, color: Colors.black),
),
onTap: () async {
await validateIdentity(context);
},
)
: const Text(
'Identité créé',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
return isOwner
? InkWell(
child: _showText(
'Cliquez ici pour confirmer\nvotre nouvelle identité',
18,
true),
onTap: () async {
await validateIdentity(context);
},
)
: _showText('Identité créé');
}
case 'ConfirmedByOwner':
{
return Column(children: const <Widget>[
Text(
'Identité confirmé',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
return _showText('Identité confirmé');
}
case 'Validated':
{
return Column(children: const <Widget>[
Text(
'Membre validé !',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
return _showText('Membre validé !');
}
case 'expired':
{
return Column(children: const <Widget>[
Text(
'Identité expiré',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]);
return _showText('Identité expiré');
}
}
return SizedBox(
child: Column(children: const <Widget>[
Text(
'Statut inconnu',
style: TextStyle(fontSize: 18, color: Colors.black),
),
]),
child: _showText('Statut inconnu'),
);
});
});
@ -198,29 +176,60 @@ class WalletOptionsProvider with ChangeNotifier {
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
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(
height: 100,
child: Column(children: [
const Text('Nom:'),
const SizedBox(height: 20),
const Text(
'Nom:',
style: TextStyle(fontSize: 19),
),
TextField(
onChanged: (_) => notifyListeners(),
textAlign: TextAlign.center,
autofocus: true,
controller: idtyName,
style: const TextStyle(fontSize: 19),
)
]),
),
actions: <Widget>[
TextButton(
child: const Text("Valider"),
onPressed: () async {
final _wallet =
_myWalletProvider.getWalletDataByAddress(address.text);
await _sub.setCurrentWallet(_wallet!);
_sub.confirmIdentity(_walletOptions.address.text, idtyName.text,
_myWalletProvider.pinCode);
Navigator.pop(context);
},
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Consumer<WalletOptionsProvider>(
builder: (context, _wOptions, _) {
return TextButton(
key: const Key('infoPopup'),
child: Text(
"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,
[Color _color = Colors.black]) {
return Column(children: <Widget>[
Consumer<SubstrateSdk>(builder: (context, _sdk, _) {
return FutureBuilder(
future: _sdk.getCerts(address),
builder: (BuildContext context, AsyncSnapshot<List?>? _certs) {
if (_certs!.connectionState != ConnectionState.done ||
_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()}"
: '';
builder: (BuildContext context, AsyncSnapshot<List<int>> _certs) {
// log.d(_certs.data);
return Text(
certCache[address]!,
style: TextStyle(
fontSize: isTall ? size : size * 0.9,
color: _color,
),
);
return _certs.data?[0] != 0
? Row(
children: [
const Icon(
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,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
const Spacer(flex: 5),
const Spacer(flex: 1),
avatar(walletProvider),
// const Spacer(flex: 1),
const Spacer(flex: 1),
Column(children: <Widget>[
walletName(walletProvider, _walletOptions),
SizedBox(height: isTall ? 5 : 0),
SizedBox(
width: 350,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// SizedBox(height: isTall ? 5 : 0),
balance(
context, walletProvider.address.text, 21),
const SizedBox(width: 30),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
_walletOptions.idtyStatus(context,
_walletOptions.address.text,
isOwner: true),
getCerts(context,
walletProvider.address.text, 15),
]),
]),
),
// SizedBox(height: isTall ? 5 : 0),
balance(context, walletProvider.address.text, 21),
const SizedBox(width: 30),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_walletOptions.idtyStatus(
context, _walletOptions.address.text,
isOwner: true),
getCerts(
context, walletProvider.address.text, 15),
]),
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>[
headerProfileView(
context, _walletViewProvider, _cesiumPlusProvider),
SizedBox(height: isTall ? 50 : 20),
SizedBox(height: isTall ? 10 : 0),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
Column(children: <Widget>[
SizedBox(
@ -570,199 +570,208 @@ class WalletViewScreen extends StatelessWidget {
WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context, listen: false);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
return Column(children: <Widget>[
Container(
height: 10,
color: yellowC,
),
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
yellowC,
const Color(0xFFE7811A),
],
)),
child: Padding(
padding: const EdgeInsets.only(left: 30, right: 40),
child: Row(children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(children: [
GestureDetector(
key: const Key('copyPubkey'),
onTap: () {
Clipboard.setData(ClipboardData(text: pubkey));
snackCopyKey(context);
},
child: Text(
getShortPubkey(pubkey!),
style: const TextStyle(
fontSize: 30,
fontWeight: FontWeight.w800,
),
),
),
]),
const SizedBox(height: 25),
// AsyncSnapshot<bool> isAccountExist;
balance(context, pubkey!, 22),
const SizedBox(height: 10),
_walletOptions.idtyStatus(context, pubkey!, isOwner: false),
getCerts(context, pubkey!, 14),
// if (username == null &&
// g1WalletsBox.get(pubkey)?.username == null)
// Query(
// options: QueryOptions(
// document: gql(getId),
// variables: {
// 'pubkey': pubkey,
// },
// ),
// builder: (QueryResult result,
// {VoidCallback? refetch, FetchMore? fetchMore}) {
// if (result.isLoading || result.hasException) {
// return const Text('...');
// } else if (result.data!['idty'] == null ||
// result.data!['idty']['username'] == null) {
// g1WalletsBox.get(pubkey)?.username = '';
// return const Text('');
// } else {
// g1WalletsBox.get(pubkey)?.username =
// result.data!['idty']['username'] ?? '';
// return SizedBox(
// width: 230,
// child: Text(
// result.data!['idty']['username'] ?? '',
// style: const TextStyle(
// fontSize: 27,
// color: Color(0xff814C00),
// ),
// ),
// );
// }
// },
// ),
if (username == null &&
g1WalletsBox.get(pubkey)?.username != null)
SizedBox(
width: 230,
child: Text(
g1WalletsBox.get(pubkey)?.username ?? '',
style: const TextStyle(
fontSize: 27,
color: Color(0xff814C00),
),
),
),
if (username != null)
SizedBox(
width: 230,
child: Text(
username!,
style: const TextStyle(
fontSize: 27,
color: Color(0xff814C00),
),
),
),
const SizedBox(height: 25),
//// To get Cs+ name
// FutureBuilder(
// future: _cesiumPlusProvider.getName(pubkey),
// initialData: '...',
// builder: (context, snapshot) {
// return SizedBox(
// width: 230,
// child: Text(
// snapshot.data.toString(),
// style: const TextStyle(
// fontSize: 18, color: Colors.black),
// ),
// );
// }),
const SizedBox(height: 30),
]),
const Spacer(),
Column(children: <Widget>[
if (avatar == null)
ClipOval(
child: _cesiumPlusProvider.defaultAvatar(_avatarSize),
return Stack(children: <Widget>[
FutureBuilder(
future: _sub.isAccountExit(pubkey!),
builder: (BuildContext context, AsyncSnapshot<bool> isAccountExist) {
final bool _isExit = isAccountExist.data ?? false;
return Container(
height: 180,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
_isExit ? yellowC : Colors.grey[400]!,
_isExit ? const Color(0xFFE7811A) : Colors.grey[600]!,
],
),
));
}),
Padding(
padding: const EdgeInsets.only(left: 30, right: 40),
child: Row(children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
height: 10,
color: yellowC, // Colors.grey[400],
),
// FutureBuilder(
// future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize),
// builder:
// (BuildContext context, AsyncSnapshot<Image?> _avatar) {
// if (_avatar.connectionState != ConnectionState.done) {
// return Stack(children: [
// ClipOval(
// child:
// _cesiumPlusProvider.defaultAvatar(_avatarSize),
// ),
// Positioned(
// top: 15,
// right: 45,
// width: 51,
// height: 51,
// child: CircularProgressIndicator(
// strokeWidth: 5,
// color: orangeC,
// ),
// ),
// ]);
// }
// if (_avatar.hasData) {
// return GestureDetector(
// key: const Key('openAvatar'),
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) {
// return AvatarFullscreen(_avatar.data);
// }),
// );
// },
// child: ClipOval(
// child: Image(
// image: _avatar.data!.image,
// height: _avatarSize,
// fit: BoxFit.cover,
// ),
// ),
// );
// }
// return ClipOval(
// child: _cesiumPlusProvider.defaultAvatar(_avatarSize),
// );
// }),
if (avatar != null)
GestureDetector(
key: const Key('openAvatar'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return AvatarFullscreen(avatar);
}),
);
},
child: ClipOval(
child: Image(
image: avatar!.image,
height: _avatarSize,
fit: BoxFit.cover,
Row(children: [
GestureDetector(
key: const Key('copyPubkey'),
onTap: () {
Clipboard.setData(ClipboardData(text: pubkey));
snackCopyKey(context);
},
child: Text(
getShortPubkey(pubkey!),
style: const TextStyle(
fontSize: 30,
fontWeight: FontWeight.w800,
),
),
),
]),
const SizedBox(height: 25),
balance(context, pubkey!, 22),
const SizedBox(height: 10),
_walletOptions.idtyStatus(context, pubkey!, isOwner: false),
getCerts(context, pubkey!, 14),
// if (username == null &&
// g1WalletsBox.get(pubkey)?.username == null)
// Query(
// options: QueryOptions(
// document: gql(getId),
// variables: {
// 'pubkey': pubkey,
// },
// ),
// builder: (QueryResult result,
// {VoidCallback? refetch, FetchMore? fetchMore}) {
// if (result.isLoading || result.hasException) {
// return const Text('...');
// } else if (result.data!['idty'] == null ||
// result.data!['idty']['username'] == null) {
// g1WalletsBox.get(pubkey)?.username = '';
// return const Text('');
// } else {
// g1WalletsBox.get(pubkey)?.username =
// result.data!['idty']['username'] ?? '';
// return SizedBox(
// width: 230,
// child: Text(
// result.data!['idty']['username'] ?? '',
// style: const TextStyle(
// fontSize: 27,
// color: Color(0xff814C00),
// ),
// ),
// );
// }
// },
// ),
if (username == null &&
g1WalletsBox.get(pubkey)?.username != null)
SizedBox(
width: 230,
child: Text(
g1WalletsBox.get(pubkey)?.username ?? '',
style: const TextStyle(
fontSize: 27,
color: Color(0xff814C00),
),
),
),
if (username != null)
SizedBox(
width: 230,
child: Text(
username!,
style: const TextStyle(
fontSize: 27,
color: Color(0xff814C00),
),
),
),
const SizedBox(height: 25),
//// To get Cs+ name
// FutureBuilder(
// future: _cesiumPlusProvider.getName(pubkey),
// initialData: '...',
// builder: (context, snapshot) {
// return SizedBox(
// width: 230,
// child: Text(
// snapshot.data.toString(),
// style: const TextStyle(
// fontSize: 18, color: Colors.black),
// ),
// );
// }),
const SizedBox(height: 30),
]),
const Spacer(),
Column(children: <Widget>[
if (avatar == null)
ClipOval(
child: _cesiumPlusProvider.defaultAvatar(_avatarSize),
),
// FutureBuilder(
// future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize),
// builder:
// (BuildContext context, AsyncSnapshot<Image?> _avatar) {
// if (_avatar.connectionState != ConnectionState.done) {
// return Stack(children: [
// ClipOval(
// child:
// _cesiumPlusProvider.defaultAvatar(_avatarSize),
// ),
// Positioned(
// top: 15,
// right: 45,
// width: 51,
// height: 51,
// child: CircularProgressIndicator(
// strokeWidth: 5,
// color: orangeC,
// ),
// ),
// ]);
// }
// if (_avatar.hasData) {
// return GestureDetector(
// key: const Key('openAvatar'),
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) {
// return AvatarFullscreen(_avatar.data);
// }),
// );
// },
// child: ClipOval(
// child: Image(
// image: _avatar.data!.image,
// height: _avatarSize,
// fit: BoxFit.cover,
// ),
// ),
// );
// }
// return ClipOval(
// child: _cesiumPlusProvider.defaultAvatar(_avatarSize),
// );
// }),
if (avatar != null)
GestureDetector(
key: const Key('openAvatar'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return AvatarFullscreen(avatar);
}),
);
},
child: ClipOval(
child: Image(
image: avatar!.image,
height: _avatarSize,
fit: BoxFit.cover,
),
),
const SizedBox(height: 25),
]),
),
const SizedBox(height: 25),
]),
),
]),
),
]);
}