refacto: new IdentityStatus Widget
This commit is contained in:
parent
30b8b68bef
commit
c50aa53f38
|
@ -27,6 +27,7 @@ class DuniterIndexer with ChangeNotifier {
|
|||
List? transBC;
|
||||
List listIndexerEndpoints = [];
|
||||
bool isLoadingIndexer = false;
|
||||
Map<String, String> idtyStatusCache = {};
|
||||
|
||||
void reload() {
|
||||
notifyListeners();
|
||||
|
|
|
@ -4,7 +4,6 @@ import 'dart:io';
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/widgets_keys.dart';
|
||||
|
@ -12,7 +11,6 @@ import 'package:gecko/providers/duniter_indexer.dart';
|
|||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/screens/animated_text.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||
import 'package:gecko/screens/transaction_in_progress.dart';
|
||||
|
@ -33,7 +31,6 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
TextEditingController nameController = TextEditingController();
|
||||
late bool isDefaultWallet;
|
||||
bool canValidateNameBool = false;
|
||||
Map<String, String> idtyStatusCache = {};
|
||||
Future<NewWallet>? get badWallet => null;
|
||||
|
||||
int getPinLenght(walletNbr) {
|
||||
|
@ -133,84 +130,6 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Widget idtyStatus(BuildContext context, String address,
|
||||
{bool isOwner = false, Color color = Colors.black}) {
|
||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||
|
||||
showText(String text,
|
||||
[double size = 18, bool bold = false, bool smooth = true]) {
|
||||
// log.d('$address $text');
|
||||
return AnimatedFadeOutIn<String>(
|
||||
data: text,
|
||||
duration: Duration(milliseconds: smooth ? 200 : 0),
|
||||
builder: (value) => Text(
|
||||
value,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: size,
|
||||
color: bold ? color : Colors.black,
|
||||
fontWeight: bold ? FontWeight.w500 : FontWeight.w400),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
||||
return FutureBuilder(
|
||||
future: sub.idtyStatus(address),
|
||||
initialData: '',
|
||||
builder: (context, snapshot) {
|
||||
idtyStatusCache[address] = snapshot.data.toString();
|
||||
switch (snapshot.data.toString()) {
|
||||
case 'noid':
|
||||
{
|
||||
return showText('noIdentity'.tr());
|
||||
}
|
||||
case 'Created':
|
||||
{
|
||||
return showText('identityCreated'.tr());
|
||||
}
|
||||
case 'ConfirmedByOwner':
|
||||
{
|
||||
return isOwner
|
||||
? showText('identityConfirmed'.tr())
|
||||
: duniterIndexer.getNameByAddress(
|
||||
context,
|
||||
address,
|
||||
null,
|
||||
20,
|
||||
true,
|
||||
Colors.grey[700]!,
|
||||
FontWeight.w500,
|
||||
FontStyle.italic);
|
||||
}
|
||||
|
||||
case 'Validated':
|
||||
{
|
||||
return isOwner
|
||||
? showText('memberValidated'.tr(), 18, true)
|
||||
: duniterIndexer.getNameByAddress(
|
||||
context,
|
||||
address,
|
||||
null,
|
||||
20,
|
||||
true,
|
||||
Colors.black,
|
||||
FontWeight.w600,
|
||||
FontStyle.normal);
|
||||
}
|
||||
|
||||
case 'expired':
|
||||
{
|
||||
return showText('identityExpired'.tr());
|
||||
}
|
||||
}
|
||||
return SizedBox(
|
||||
child: showText('', 18, false, false),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<bool> isMember(BuildContext context, String address) async {
|
||||
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
return await sub.idtyStatus(address) == 'Validated';
|
||||
|
|
|
@ -15,6 +15,7 @@ import 'package:gecko/providers/wallet_options.dart';
|
|||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||
import 'package:gecko/screens/transaction_in_progress.dart';
|
||||
import 'package:gecko/widgets/idty_status.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ImportG1v1 extends StatelessWidget {
|
||||
|
@ -22,8 +23,6 @@ class ImportG1v1 extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final walletOptions =
|
||||
Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
final myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||
|
||||
|
@ -210,8 +209,10 @@ class ImportG1v1 extends StatelessWidget {
|
|||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
walletOptions.idtyStatus(context, sub.g1V1NewAddress,
|
||||
isOwner: false, color: Colors.black),
|
||||
IdentityStatus(
|
||||
address: sub.g1V1NewAddress,
|
||||
isOwner: false,
|
||||
color: Colors.black),
|
||||
const SizedBox(width: 10),
|
||||
getCerts(context, sub.g1V1NewAddress, 14)
|
||||
],
|
||||
|
|
|
@ -17,6 +17,7 @@ import 'package:gecko/screens/common_elements.dart';
|
|||
import 'package:gecko/screens/activity.dart';
|
||||
import 'package:gecko/screens/myWallets/manage_membership.dart';
|
||||
import 'package:gecko/screens/qrcode_fullscreen.dart';
|
||||
import 'package:gecko/widgets/idty_status.dart';
|
||||
import 'package:gecko/widgets/page_route_no_transition.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
@ -169,9 +170,10 @@ class WalletOptions extends StatelessWidget {
|
|||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
children: [
|
||||
walletOptions.idtyStatus(
|
||||
context, walletOptions.address.text,
|
||||
isOwner: true, color: orangeC),
|
||||
IdentityStatus(
|
||||
address: walletOptions.address.text,
|
||||
isOwner: true,
|
||||
color: orangeC),
|
||||
getCerts(context,
|
||||
walletProvider.address.text, 15),
|
||||
]),
|
||||
|
|
|
@ -9,6 +9,7 @@ import 'package:gecko/providers/wallet_options.dart';
|
|||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/screens/certifications.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/widgets/idty_status.dart';
|
||||
import 'package:gecko/widgets/page_route_no_transition.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
@ -25,9 +26,6 @@ class HeaderProfile extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const double avatarSize = 140;
|
||||
|
||||
final walletOptions =
|
||||
Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||
|
||||
return Stack(children: <Widget>[
|
||||
|
@ -94,8 +92,10 @@ class HeaderProfile extends StatelessWidget {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
walletOptions.idtyStatus(context, address,
|
||||
isOwner: false, color: Colors.black),
|
||||
IdentityStatus(
|
||||
address: address,
|
||||
isOwner: false,
|
||||
color: Colors.black),
|
||||
getCerts(context, address, 14)
|
||||
],
|
||||
),
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/providers/duniter_indexer.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/screens/animated_text.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class IdentityStatus extends StatelessWidget {
|
||||
const IdentityStatus(
|
||||
{Key? key,
|
||||
required this.address,
|
||||
this.isOwner = false,
|
||||
this.color = Colors.black})
|
||||
: super(key: key);
|
||||
final String address;
|
||||
final bool isOwner;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
||||
|
||||
showText(String text,
|
||||
[double size = 18, bool bold = false, bool smooth = true]) {
|
||||
// log.d('$address $text');
|
||||
return AnimatedFadeOutIn<String>(
|
||||
data: text,
|
||||
duration: Duration(milliseconds: smooth ? 200 : 0),
|
||||
builder: (value) => Text(
|
||||
value,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: size,
|
||||
color: bold ? color : Colors.black,
|
||||
fontWeight: bold ? FontWeight.w500 : FontWeight.w400),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
||||
return FutureBuilder(
|
||||
future: sub.idtyStatus(address),
|
||||
initialData: '',
|
||||
builder: (context, snapshot) {
|
||||
duniterIndexer.idtyStatusCache[address] = snapshot.data.toString();
|
||||
switch (snapshot.data.toString()) {
|
||||
case 'noid':
|
||||
{
|
||||
return showText('noIdentity'.tr());
|
||||
}
|
||||
case 'Created':
|
||||
{
|
||||
return showText('identityCreated'.tr());
|
||||
}
|
||||
case 'ConfirmedByOwner':
|
||||
{
|
||||
return isOwner
|
||||
? showText('identityConfirmed'.tr())
|
||||
: duniterIndexer.getNameByAddress(
|
||||
context,
|
||||
address,
|
||||
null,
|
||||
20,
|
||||
true,
|
||||
Colors.grey[700]!,
|
||||
FontWeight.w500,
|
||||
FontStyle.italic);
|
||||
}
|
||||
|
||||
case 'Validated':
|
||||
{
|
||||
return isOwner
|
||||
? showText('memberValidated'.tr(), 18, true)
|
||||
: duniterIndexer.getNameByAddress(
|
||||
context,
|
||||
address,
|
||||
null,
|
||||
20,
|
||||
true,
|
||||
Colors.black,
|
||||
FontWeight.w600,
|
||||
FontStyle.normal);
|
||||
}
|
||||
|
||||
case 'expired':
|
||||
{
|
||||
return showText('identityExpired'.tr());
|
||||
}
|
||||
}
|
||||
return SizedBox(
|
||||
child: showText('', 18, false, false),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue