86 lines
3.0 KiB
Dart
86 lines
3.0 KiB
Dart
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:gecko/globals.dart';
|
|
import 'package:gecko/models/wallet_data.dart';
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
|
import 'package:gecko/widgets/commons/animated_text.dart';
|
|
import 'package:gecko/widgets/name_by_address.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 walletData = walletBox.get(address) ?? WalletData(address: address);
|
|
|
|
return Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
|
return FutureBuilder(
|
|
future: sub.idtyStatus([address]),
|
|
initialData: [walletData.identityStatus],
|
|
builder: (context, AsyncSnapshot<List<IdtyStatus>> snapshot) {
|
|
final resStatus = snapshot.data!.first;
|
|
walletData.identityStatus = resStatus;
|
|
walletBox.put(address, walletData);
|
|
|
|
if (!isOwner) {
|
|
if (resStatus == IdtyStatus.confirmed) {
|
|
return NameByAddress(
|
|
wallet: WalletData(address: address),
|
|
size: 20,
|
|
color: Colors.grey[700]!,
|
|
fontWeight: FontWeight.w500,
|
|
fontStyle: FontStyle.italic);
|
|
} else if (resStatus == IdtyStatus.validated) {
|
|
return NameByAddress(
|
|
wallet: WalletData(address: address),
|
|
size: 24,
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.w600,
|
|
fontStyle: FontStyle.normal);
|
|
}
|
|
}
|
|
|
|
final Map<IdtyStatus, String> statusText = {
|
|
IdtyStatus.none: 'noIdentity'.tr(),
|
|
IdtyStatus.created: 'identityCreated'.tr(),
|
|
IdtyStatus.confirmed: 'identityConfirmed'.tr(),
|
|
IdtyStatus.validated: 'memberValidated'.tr(),
|
|
IdtyStatus.expired: 'identityExpired'.tr(),
|
|
IdtyStatus.unknown: ''
|
|
};
|
|
|
|
return SizedBox(
|
|
child: showText(statusText[resStatus]!,
|
|
bold: resStatus == IdtyStatus.validated ? true : false),
|
|
);
|
|
});
|
|
});
|
|
}
|
|
|
|
AnimatedFadeOutIn showText(String text,
|
|
{double size = 18, bool bold = false}) {
|
|
// log.d('$address $text');
|
|
return AnimatedFadeOutIn<String>(
|
|
data: text,
|
|
duration: const Duration(milliseconds: 150),
|
|
builder: (value) => Text(
|
|
value,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: size,
|
|
color: bold ? color : Colors.black,
|
|
fontWeight: bold ? FontWeight.w500 : FontWeight.w400),
|
|
),
|
|
);
|
|
}
|
|
}
|