Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • upgrade_polkadot_v0.9.42
  • archive_upgrade_polkadot_v0.9.42
  • pallet-benchmark
  • jrx/workspace_tomls
  • hugo-gtest
  • hugo-rework-genesis
  • hugo-remove-duniter-account
  • hugo-tmp
  • release/poka-chainspec-gdev5-pini-docker
  • release/poka-chainspec-gdev5
  • ud-time-64
  • distance
  • david-wot-scenarios-cucumber
  • release/runtime-400
  • elois-revoc-with-old-key
  • elois-smish-members-cant-change-or-rem-idty
  • release/runtime-300
  • elois-fix-idty-post-genesis
  • elois-fix-sufficients-change-owner-key
  • v0.4.0
  • runtime-400
  • runtime-303
  • runtime-302
  • v0.3.0
  • runtime-301
  • v0.2.0
  • runtime-300
  • runtime-201
  • runtime-200
  • runtime-105
  • runtime-104
  • runtime-103
  • runtime-102
  • runtime-101
  • v0.1.0
  • runtime-100
37 results

runtime-calls.md

Blame
  • Forked from nodes / rust / Duniter v2S
    Source project has a limited visibility.
    certifications.dart 2.55 KiB
    import 'package:flutter/material.dart';
    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;
      final double size;
      final Color color;
    
      @override
      State<Certifications> createState() => _CertificationsState();
    }
    
    class _CertificationsState extends State<Certifications> {
      bool _isLoading = false;
    
      Future<void> _checkNetworkData(SubstrateSdk sdk) async {
        if (_isLoading) return;
        _isLoading = true;
    
        try {
          final networkData = await sdk.getCertsCounter(widget.address);
          if (!mounted) return;
    
          final cachedData = sdk.certsCounterCache[widget.address];
          if (cachedData == null || !cachedData.equals(networkData)) {
            sdk.certsCounterCache[widget.address] = networkData;
            setState(() {});
          }
        } finally {
          _isLoading = false;
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Consumer<SubstrateSdk>(
          builder: (context, sdk, _) {
            // Display cached data immediately if available
            final cachedCerts = sdk.certsCounterCache[widget.address];
    
            // Check network data in the background
            if (!_isLoading) {
              Future.microtask(() => _checkNetworkData(sdk));
            }
    
            // If no cached data, show nothing while waiting
            if (cachedCerts == null) {
              return const SizedBox.shrink();
            }
    
            // Display cached data
            return _buildContent(cachedCerts.receivedCount, cachedCerts.sentCount);
          },
        );