fix: wrong type cast

This commit is contained in:
Matyáš Caras 2023-12-31 11:42:27 +01:00
parent 073806b8dd
commit 480c4e2538
Signed by untrusted user who does not match committer: hernik
GPG key ID: 2A3175F98820C5C6
2 changed files with 7 additions and 2 deletions

View file

@ -15,7 +15,7 @@ Wallet _$WalletFromJson(Map<String, dynamic> json) => Wallet(
const [], const [],
entries: (json['entries'] as List<dynamic>?) entries: (json['entries'] as List<dynamic>?)
?.map( ?.map(
(e) => WalletSingleEntry.fromJson(e as Map<String, dynamic>),) (e) => WalletSingleEntry.fromJson(e as Map<String, dynamic>))
.toList() ?? .toList() ??
const [], const [],
starterBalance: (json['starterBalance'] as num?)?.toDouble() ?? 0, starterBalance: (json['starterBalance'] as num?)?.toDouble() ?? 0,

View file

@ -3,6 +3,7 @@ import 'dart:io';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:prasule/api/wallet.dart'; import 'package:prasule/api/wallet.dart';
import 'package:prasule/main.dart';
/// Used for [Wallet]-managing operations /// Used for [Wallet]-managing operations
class WalletManager { class WalletManager {
@ -19,9 +20,11 @@ class WalletManager {
try { try {
wallets.add(await loadWallet(w)); wallets.add(await loadWallet(w));
} catch (e) { } catch (e) {
logger.e(e);
// TODO: do something with unreadable wallets // TODO: do something with unreadable wallets
} }
} }
logger.i(wallets.length);
return wallets; return wallets;
} }
@ -37,7 +40,8 @@ class WalletManager {
return Future.error("Wallet does not exist"); return Future.error("Wallet does not exist");
} }
return Wallet.fromJson( return Wallet.fromJson(
jsonDecode(wallet.readAsStringSync()) as Map<String, String>,); jsonDecode(wallet.readAsStringSync()) as Map<String, dynamic>,
);
} }
/// Converts [Wallet] to JSON and saves it to AppData /// Converts [Wallet] to JSON and saves it to AppData
@ -50,6 +54,7 @@ class WalletManager {
} }
// if (!wallet.existsSync()) return false; // if (!wallet.existsSync()) return false;
wallet.writeAsStringSync(jsonEncode(w.toJson())); wallet.writeAsStringSync(jsonEncode(w.toJson()));
logger.i(wallet.existsSync());
return true; return true;
} }