Skip to content
Snippets Groups Projects
myWallets.dart 3.44 KiB
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:gecko/globals.dart';
import 'package:provider/provider.dart';

class MyWalletsProvider with ChangeNotifier {
  String listWallets;

  bool checkIfWalletExist() {
    if (appPath == null) {
      return false;
    }

    List contents = walletsDirectory.listSync();
    if (contents.length == 0) {
      print('No wallets detected');
      return false;
    } else {
      print('Some wallets have been detected.');
      return true;
    }
  }

  Future importWallet() async {}

  String getAllWalletsNames() {
    if (listWallets != null && listWallets.isNotEmpty) {
      listWallets = '';
    }
    if (listWallets == null) {
      listWallets = '';
    }

    // int i = 0;
    walletsDirectory
        .listSync(recursive: false, followLinks: false)
        .forEach((_wallet) {
      File _walletConfig = File('${_wallet.path}/config.txt');
      _walletConfig.readAsLinesSync().forEach((element) {
        if (listWallets != '') {
          listWallets += '\n';
        }
        listWallets +=
            "${element.split(':')[0]}:${element.split(':')[1]}:${element.split(':')[2]}";
      });
    });

    return listWallets;
  }

  Future<int> deleteAllWallet(context) async {
    try {
      print('DELETE THAT ?: $walletsDirectory');

      final bool _answer = await _confirmDeletingAllWallets(context);

      if (_answer) {
        await walletsDirectory.delete(recursive: true);
        await walletsDirectory.create();
        Navigator.pop(context);
      }
      return 0;
    } catch (e) {
      return 1;
    }
  }

  Future<bool> _confirmDeletingAllWallets(context) async {