Fix MyWallets screen crash on fresh app cause wallets folder doesn't exist; Fix match accented words
This commit is contained in:
parent
22be4f1de6
commit
dbf6a9d476
|
@ -4,6 +4,7 @@ import 'package:dubp/dubp.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'dart:convert' show utf8;
|
||||||
|
|
||||||
class ConfirmStoreWallet extends StatefulWidget {
|
class ConfirmStoreWallet extends StatefulWidget {
|
||||||
final String generatedMnemonic;
|
final String generatedMnemonic;
|
||||||
|
@ -163,19 +164,16 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
|
||||||
|
|
||||||
Future storeWallet(_name) async {
|
Future storeWallet(_name) async {
|
||||||
final appPath = await _localPath;
|
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) {
|
if (await walletNameDirectory.exists()) {
|
||||||
new Directory('$appPath/wallets').createSync();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await Directory('$appPath/wallets/$_name').exists() == true) {
|
|
||||||
print('Ce wallet existe déjà, impossible de le créer.');
|
print('Ce wallet existe déjà, impossible de le créer.');
|
||||||
_showWalletExistDialog();
|
_showWalletExistDialog();
|
||||||
return 'Exist: DENY';
|
return 'Exist: DENY';
|
||||||
}
|
}
|
||||||
|
|
||||||
new Directory('$appPath/wallets/$_name').createSync();
|
walletNameDirectory.createSync();
|
||||||
walletFile.writeAsString('${widget.generatedWallet.dewif}');
|
walletFile.writeAsString('${widget.generatedWallet.dewif}');
|
||||||
_pin.clear();
|
_pin.clear();
|
||||||
|
|
||||||
|
@ -190,11 +188,21 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
|
||||||
return directory.path;
|
return directory.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkAskedWord(value) {
|
void checkAskedWord(String value) {
|
||||||
print(this._mnemonicController.text.split(' ')[nbrWord]);
|
final runesAsked = _mnemonicController.text.split(' ')[nbrWord].runes;
|
||||||
print(value);
|
List<int> runesAskedUnaccent = [];
|
||||||
if (this._mnemonicController.text.split(' ')[nbrWord] == value ||
|
for (int i in runesAsked) {
|
||||||
value == 'triche') {
|
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');
|
print('Word is OK');
|
||||||
isAskedWordValid = true;
|
isAskedWordValid = true;
|
||||||
askedWordColor = Colors.green[600];
|
askedWordColor = Colors.green[600];
|
||||||
|
@ -232,6 +240,19 @@ class ConfirmStoreWalletState extends State<ConfirmStoreWallet> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
int getRandomInt() {
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
return rng.nextInt(12);
|
return rng.nextInt(12);
|
||||||
|
|
|
@ -128,7 +128,15 @@ class WalletsHomeState extends State<WalletsHome> {
|
||||||
if (this.appPath == null) {
|
if (this.appPath == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var walletsFolder = new Directory("${this.appPath.path}/wallets/");
|
var walletsFolder = new Directory("${this.appPath.path}/wallets/");
|
||||||
|
|
||||||
|
bool isWalletFolderExist = walletsFolder.existsSync();
|
||||||
|
|
||||||
|
if (!isWalletFolderExist) {
|
||||||
|
Directory(walletsFolder.path).createSync();
|
||||||
|
}
|
||||||
|
|
||||||
List contents = walletsFolder.listSync();
|
List contents = walletsFolder.listSync();
|
||||||
if (contents.length == 0) {
|
if (contents.length == 0) {
|
||||||
print('No wallets detected');
|
print('No wallets detected');
|
||||||
|
|
|
@ -5,7 +5,7 @@ description: A new Flutter project.
|
||||||
# pub.dev using `pub publish`. This is preferred for private packages.
|
# 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
|
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:
|
environment:
|
||||||
sdk: ">=2.7.0 <3.0.0"
|
sdk: ">=2.7.0 <3.0.0"
|
||||||
|
|
Loading…
Reference in New Issue