Skip to content
Snippets Groups Projects
Commit 36267865 authored by poka's avatar poka
Browse files

fix Valid value range is empty for certs cache

parent 74a81de6
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ import 'package:provider/provider.dart';
import 'package:pointycastle/pointycastle.dart' as pc;
import "package:hex/hex.dart";
import 'package:uuid/uuid.dart' show Uuid;
import 'package:gecko/widgets/certifications.dart';
class SubstrateSdk with ChangeNotifier {
final WalletSDK sdk = WalletSDK();
......@@ -51,7 +52,7 @@ class SubstrateSdk with ChangeNotifier {
bool isCesiumIDVisible = false;
bool isCesiumAddresLoading = false;
late int udValue;
Map<String, List<int>> certsCounterCache = {};
final Map<String, CertificationData> certsCounterCache = {};
Map<String, List> oldOwnerKeys = {};
// Cache pour idtyStatus
......@@ -210,13 +211,13 @@ class SubstrateSdk with ChangeNotifier {
return List<int?>.from(await _getStorage('identity.identityIndexOf.multi($jsonString)'));
}
Future<List<int>> getCertsCounter(String address) async {
Future<CertificationData> getCertsCounter(String address) async {
// On fait toujours la requête en background
final idtyIndex = await _getIdentityIndexOf(address);
if (idtyIndex == null) {
final emptyList = <int>[];
final emptyList = CertificationData(receivedCount: 0, sentCount: 0);
// Si le compteur a changé (était non vide avant), on notifie
if (certsCounterCache[address]?.isNotEmpty == true) {
if (certsCounterCache[address]?.receivedCount != 0 || certsCounterCache[address]?.sentCount != 0) {
certsCounterCache[address] = emptyList;
notifyListeners();
}
......@@ -227,12 +228,12 @@ class SubstrateSdk with ChangeNotifier {
final List<int> newCerts = [certsReceiver['receivedCount'] as int, certsReceiver['issuedCount'] as int];
// Si le compteur a changé, on met à jour le cache et on notifie
if (certsCounterCache[address]?.length != 2 || certsCounterCache[address]![0] != newCerts[0] || certsCounterCache[address]![1] != newCerts[1]) {
certsCounterCache[address] = newCerts;
if (certsCounterCache[address]?.receivedCount != newCerts[0] || certsCounterCache[address]?.sentCount != newCerts[1]) {
certsCounterCache[address] = CertificationData(receivedCount: newCerts[0], sentCount: newCerts[1]);
notifyListeners();
}
return certsCounterCache[address] ?? newCerts;
return certsCounterCache[address]!;
}
Future<DateTime?> membershipExpireIn(String address) async {
......@@ -1069,10 +1070,10 @@ class SubstrateSdk with ChangeNotifier {
String? rawParams;
var toCerts = await getCertsCounter(destAddress);
if (toCerts.isEmpty) {
toCerts = [0, 0];
if (toCerts.receivedCount == 0 && toCerts.sentCount == 0) {
toCerts = CertificationData(receivedCount: 0, sentCount: 0);
}
log.d("debug toCert: ${toCerts[0]} --- ${currencyParameters['minCertForMembership']!} --- $toIdtyStatus");
log.d("debug toCert: ${toCerts.receivedCount} --- ${currencyParameters['minCertForMembership']!} --- $toIdtyStatus");
if (toIdtyStatus == IdtyStatus.none) {
txInfo = TxInfoData(
......@@ -1082,7 +1083,7 @@ class SubstrateSdk with ChangeNotifier {
);
txOptions = [destAddress];
} else if (toIdtyStatus == IdtyStatus.member || toIdtyStatus == IdtyStatus.unvalidated) {
if (toCerts[0] >= currencyParameters['minCertForMembership']! - 1 && toIdtyStatus != IdtyStatus.member) {
if (toCerts.receivedCount >= currencyParameters['minCertForMembership']! - 1 && toIdtyStatus != IdtyStatus.member) {
log.d('Batch cert and membership validation');
txInfo = TxInfoData(
'utility',
......
......@@ -3,6 +3,19 @@ import 'package:gecko/models/scale_functions.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:provider/provider.dart';
// Add a class to store certification data
class CertificationData {
final int receivedCount;
final int sentCount;
CertificationData({required this.receivedCount, required this.sentCount});
bool equals(CertificationData? other) {
if (other == null) return false;
return receivedCount == other.receivedCount && sentCount == other.sentCount;
}
}
class Certifications extends StatefulWidget {
const Certifications({super.key, required this.address, required this.size, this.color = Colors.black});
final String address;
......@@ -25,7 +38,7 @@ class _CertificationsState extends State<Certifications> {
if (!mounted) return;
final cachedData = sdk.certsCounterCache[widget.address];
if (cachedData == null || cachedData.isEmpty || networkData[0] != cachedData[0] || networkData[1] != cachedData[1]) {
if (cachedData == null || !cachedData.equals(networkData)) {
sdk.certsCounterCache[widget.address] = networkData;
setState(() {});
}
......@@ -38,21 +51,21 @@ class _CertificationsState extends State<Certifications> {
Widget build(BuildContext context) {
return Consumer<SubstrateSdk>(
builder: (context, sdk, _) {
// Afficher les données du cache immédiatement si disponibles
// Display cached data immediately if available
final cachedCerts = sdk.certsCounterCache[widget.address];
// Vérifier les données réseau en arrière-plan
// Check network data in the background
if (!_isLoading) {
Future.microtask(() => _checkNetworkData(sdk));
}
// Si pas de données en cache, on affiche rien en attendant
if (cachedCerts == null || cachedCerts.isEmpty) {
// If no cached data, show nothing while waiting
if (cachedCerts == null) {
return const SizedBox.shrink();
}
// Afficher les données du cache
return _buildContent(cachedCerts[0], cachedCerts[1]);
// Display cached data
return _buildContent(cachedCerts.receivedCount, cachedCerts.sentCount);
},
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment