Skip to content
Snippets Groups Projects
myWallets.dart 1.68 KiB
Newer Older
poka's avatar
poka committed
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
poka's avatar
poka committed
import 'package:gecko/globals.dart';
poka's avatar
poka committed

class MyWalletsProvider with ChangeNotifier {
poka's avatar
poka committed
  // Directory appPath;
  List listWallets = [];
poka's avatar
poka committed

  bool checkIfWalletExist() {
poka's avatar
poka committed
    if (appPath == null) {
poka's avatar
poka committed
      return false;
    }

poka's avatar
poka committed
    var walletsFolder = new Directory("${appPath.path}/wallets/");
poka's avatar
poka committed

    bool isWalletFolderExist = walletsFolder.existsSync();

    if (!isWalletFolderExist) {
      Directory(walletsFolder.path).createSync();
    }

    List contents = walletsFolder.listSync();
    if (contents.length == 0) {
      print('No wallets detected');
poka's avatar
poka committed
      notifyListeners();
poka's avatar
poka committed
      return false;
    } else {
      print('Some wallets have been detected:');
      for (var _wallets in contents) {
        print(_wallets);
      }
poka's avatar
poka committed
      notifyListeners();
poka's avatar
poka committed
      return true;
    }

    // final bool isExist =
    //     File('${walletsFolder.path}/$name/wallet.dewif').existsSync();
    // print(this.appPath.path);
    // print('Wallet existe ? : ' + isExist.toString());
    // print('Is wallet generated ? : ' + walletIsGenerated.toString());
    // if (isExist) {
    //   print('Un wallet existe !');
    //   return true;
    // } else {
    //   return false;
    // }
  }

poka's avatar
poka committed
  Future importWallet() async {}

  List getAllWalletsNames() {
    listWallets.clear();
    print('1');
    print(walletsDirectory.path);
    print('2');

    walletsDirectory
        .listSync(recursive: false, followLinks: false)
        .forEach((wallet) {
      String _name = wallet.path.split('/').last;
      print(_name);
      listWallets.add(_name);
    });
poka's avatar
poka committed
    notifyListeners();

poka's avatar
poka committed
    return listWallets;
  }