From dbf6a9d476723cfe27752916e158f0ec988b256f Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 15 Jan 2021 09:55:03 +0100 Subject: [PATCH] Fix MyWallets screen crash on fresh app cause wallets folder doesn't exist; Fix match accented words --- lib/ui/myWallets/confirmWalletStorage.dart | 45 ++++++++++++++++------ lib/ui/myWallets/walletsHome.dart | 8 ++++ pubspec.yaml | 4 +- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/lib/ui/myWallets/confirmWalletStorage.dart b/lib/ui/myWallets/confirmWalletStorage.dart index 666d0d9..1e2543e 100644 --- a/lib/ui/myWallets/confirmWalletStorage.dart +++ b/lib/ui/myWallets/confirmWalletStorage.dart @@ -4,6 +4,7 @@ import 'package:dubp/dubp.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; +import 'dart:convert' show utf8; class ConfirmStoreWallet extends StatefulWidget { final String generatedMnemonic; @@ -163,19 +164,16 @@ class ConfirmStoreWalletState extends State { Future storeWallet(_name) async { final appPath = await _localPath; - final walletFile = File('$appPath/wallets/$_name/wallet.dewif'); + final Directory walletNameDirectory = Directory('$appPath/wallets/$_name'); + final walletFile = File('${walletNameDirectory.path}/wallet.dewif'); - if (await Directory('$appPath/wallets').exists() == false) { - new Directory('$appPath/wallets').createSync(); - } - - if (await Directory('$appPath/wallets/$_name').exists() == true) { + if (await walletNameDirectory.exists()) { print('Ce wallet existe déjà, impossible de le créer.'); _showWalletExistDialog(); return 'Exist: DENY'; } - new Directory('$appPath/wallets/$_name').createSync(); + walletNameDirectory.createSync(); walletFile.writeAsString('${widget.generatedWallet.dewif}'); _pin.clear(); @@ -190,11 +188,21 @@ class ConfirmStoreWalletState extends State { return directory.path; } - void checkAskedWord(value) { - print(this._mnemonicController.text.split(' ')[nbrWord]); - print(value); - if (this._mnemonicController.text.split(' ')[nbrWord] == value || - value == 'triche') { + void checkAskedWord(String value) { + final runesAsked = _mnemonicController.text.split(' ')[nbrWord].runes; + List runesAskedUnaccent = []; + for (int i in runesAsked) { + if (i == 769) { + continue; + } else { + runesAskedUnaccent.add(i); + } + } + final String unaccentedAskedWord = utf8.decode(runesAskedUnaccent); + final String unaccentedInputWord = removeDiacritics(value); + + print("Is $unaccentedAskedWord equal to input $unaccentedInputWord ?"); + if (unaccentedAskedWord == unaccentedInputWord || value == 'triche') { print('Word is OK'); isAskedWordValid = true; askedWordColor = Colors.green[600]; @@ -232,6 +240,19 @@ class ConfirmStoreWalletState extends State { ); } + String removeDiacritics(String str) { + var withDia = + 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž'; + var withoutDia = + 'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz'; + + for (int i = 0; i < withDia.length; i++) { + str = str.replaceAll(withDia[i], withoutDia[i]); + } + + return str; + } + int getRandomInt() { var rng = new Random(); return rng.nextInt(12); diff --git a/lib/ui/myWallets/walletsHome.dart b/lib/ui/myWallets/walletsHome.dart index 2f1b8a3..62c2b3d 100644 --- a/lib/ui/myWallets/walletsHome.dart +++ b/lib/ui/myWallets/walletsHome.dart @@ -128,7 +128,15 @@ class WalletsHomeState extends State { if (this.appPath == null) { return false; } + var walletsFolder = new Directory("${this.appPath.path}/wallets/"); + + bool isWalletFolderExist = walletsFolder.existsSync(); + + if (!isWalletFolderExist) { + Directory(walletsFolder.path).createSync(); + } + List contents = walletsFolder.listSync(); if (contents.length == 0) { print('No wallets detected'); diff --git a/pubspec.yaml b/pubspec.yaml index c8b5426..bccd226 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: A new Flutter project. # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.0.0+10 +version: 0.0.0+11 environment: sdk: ">=2.7.0 <3.0.0" @@ -46,4 +46,4 @@ flutter: assets: - images/ - - config/ \ No newline at end of file + - config/