Fixes issue with loading old android wallets. Changed seed text field type to visual password.

This commit is contained in:
M 2020-11-13 16:58:28 +02:00
parent fcaf7b4abb
commit ba2b5fb1fa
6 changed files with 67 additions and 21 deletions

View file

@ -19,3 +19,10 @@ Future<String> pathForWalletDir({@required String name, @required WalletType ty
Future<String> pathForWallet({@required String name, @required WalletType type}) async =>
await pathForWalletDir(name: name, type: type)
.then((path) => path + '/$name');
Future<String> outdatedAndroidPathForWalletDir({String name}) async {
final directory = await getApplicationDocumentsDirectory();
final pathDir = directory.path + '/$name';
return pathDir;
}

View file

@ -20,7 +20,7 @@ abstract class MoneroAccountListBase with Store {
bool _isRefreshing;
bool _isUpdating;
Future update() async {
void update() async {
if (_isUpdating) {
return;
}

View file

@ -121,8 +121,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
_onAccountChangeReaction?.reaction?.dispose();
}
Future<bool> validate() async {
await accountList.update();
bool validate() {
accountList.update();
final accountListLength = accountList.accounts?.length ?? 0;
if (accountListLength <= 0) {

View file

@ -27,7 +27,7 @@ class MoneroRestoreWalletFromSeedCredentials extends WalletCredentials {
class MoneroWalletLoadingException implements Exception {
@override
String toString() => 'The wallet is damaged.';
String toString() => 'Failure to load the wallet.';
}
class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials {
@ -93,6 +93,11 @@ class MoneroWalletService extends WalletService<
Future<MoneroWallet> openWallet(String name, String password) async {
try {
final path = await pathForWallet(name: name, type: WalletType.monero);
if (!File(path).existsSync()) {
await repairOldAndroidWallet(name);
}
await monero_wallet_manager
.openWalletAsync({'path': path, 'password': password});
final walletInfo = walletInfoSource.values.firstWhere(
@ -100,7 +105,7 @@ class MoneroWalletService extends WalletService<
orElse: () => null);
final wallet = MoneroWallet(
filename: monero_wallet.getFilename(), walletInfo: walletInfo);
final isValid = await wallet.validate();
final isValid = wallet.validate();
if (!isValid) {
// if (wallet.seed?.isNotEmpty ?? false) {
@ -187,4 +192,38 @@ class MoneroWalletService extends WalletService<
rethrow;
}
}
Future<void> repairOldAndroidWallet(String name) async {
try {
if (!Platform.isAndroid) {
return;
}
final oldAndroidWalletDirPath =
await outdatedAndroidPathForWalletDir(name: name);
final dir = Directory(oldAndroidWalletDirPath);
if (!dir.existsSync()) {
throw MoneroWalletLoadingException();
}
final newWalletDirPath =
await pathForWalletDir(name: name, type: WalletType.monero);
dir.listSync().forEach((f) {
final file = File(f.path);
final name = f.path.split('/').last;
final newPath = newWalletDirPath + '/$name';
final newFile = File(newPath);
print(file.path);
if (!newFile.existsSync()) {
newFile.createSync();
}
newFile.writeAsBytesSync(file.readAsBytesSync());
});
} catch (e) {
print(e.toString());
throw MoneroWalletLoadingException();
}
}
}

View file

@ -77,7 +77,7 @@ class SeedWidgetState extends State<SeedWidget> {
fontSize: 16.0, color: Theme.of(context).hintColor))),
Padding(
padding: EdgeInsets.only(right: 40, top: 10),
child: ValidableAnnotatedEditableText(
child: ValidatableAnnotatedEditableText(
cursorColor: Colors.blue,
backgroundCursorColor: Colors.blue,
validStyle: TextStyle(

View file

@ -22,8 +22,8 @@ class TextAnnotation extends Comparable<TextAnnotation> {
int compareTo(TextAnnotation other) => text.compareTo(other.text);
}
class ValidableAnnotatedEditableText extends EditableText {
ValidableAnnotatedEditableText({
class ValidatableAnnotatedEditableText extends EditableText {
ValidatableAnnotatedEditableText({
Key key,
FocusNode focusNode,
TextEditingController controller,
@ -49,7 +49,7 @@ class ValidableAnnotatedEditableText extends EditableText {
controller: controller,
cursorColor: cursorColor,
style: validStyle,
keyboardType: TextInputType.text,
keyboardType: TextInputType.visiblePassword,
autocorrect: false,
autofocus: false,
selectionColor: selectionColor,
@ -73,14 +73,14 @@ class ValidableAnnotatedEditableText extends EditableText {
final TextStyle invalidStyle;
@override
ValidableAnnotatedEditableTextState createState() =>
ValidableAnnotatedEditableTextState();
ValidatableAnnotatedEditableTextState createState() =>
ValidatableAnnotatedEditableTextState();
}
class ValidableAnnotatedEditableTextState extends EditableTextState {
class ValidatableAnnotatedEditableTextState extends EditableTextState {
@override
ValidableAnnotatedEditableText get widget =>
super.widget as ValidableAnnotatedEditableText;
ValidatableAnnotatedEditableText get widget =>
super.widget as ValidatableAnnotatedEditableText;
List<Annotation> getRanges() {
final result = List<Annotation>();