Skip to content
Snippets Groups Projects
wallets_profiles.dart 4.25 KiB
// ignore_for_file: use_build_context_synchronously

import 'dart:io';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/models/g1_wallets_list.dart';
import 'package:gecko/models/scale_functions.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/screens/wallet_view.dart';
import 'package:jdenticon_dart/jdenticon_dart.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:barcode_scan2/barcode_scan2.dart';
import 'package:provider/provider.dart';

class WalletsProfilesProvider with ChangeNotifier {
  WalletsProfilesProvider(this.address);

  String address = '';
  String pubkeyShort = '';

  bool isHistoryScreen = false;
  String historySwitchButtun = "Voir l'historique";
  String? rawSvg;
  final payAmount = TextEditingController();
  final payComment = TextEditingController();
  num? _balance;

  Future<String> scan(context) async {
    if (Platform.isAndroid || Platform.isIOS) {
      await Permission.camera.request();
    }
    ScanResult? barcode;
    try {
      barcode = await BarcodeScanner.scan();
    } catch (e) {
      log.e("BarcodeScanner ERR: $e");
      return 'false';
    }
    if (await isAddress(barcode.rawContent)) {
      address = barcode.rawContent;
      Navigator.popUntil(
        context,
        ModalRoute.withName('/'),
      );
      Navigator.push(
        context,
        MaterialPageRoute(builder: (context) {
          return WalletViewScreen(
            address: barcode!.rawContent,
            username: null,
          );
        }),
      );
    } else {
      return 'false';
    }
    return barcode.rawContent;
  }

  void resetdHistory() {
    notifyListeners();
  }

  String generateIdenticon(String pubkey) {
    return Jdenticon.toSvg(pubkey);
  }

  Future<num?> getBalance(String? pubkey) async {
    while (_balance == null) {