fix: sometime on startup, app says you upgraded dataVersion (but no) and forget your safes...

This commit is contained in:
poka 2022-12-14 19:28:23 +01:00
parent 71d222307b
commit d1194d5eb5
2 changed files with 22 additions and 15 deletions

View File

@ -58,8 +58,11 @@ Future<void> main() async {
HomeProvider homeProvider = HomeProvider(); HomeProvider homeProvider = HomeProvider();
// DuniterIndexer _duniterIndexer = DuniterIndexer(); // DuniterIndexer _duniterIndexer = DuniterIndexer();
await initHiveForFlutter(); await initHiveForFlutter();
await homeProvider.initHive(); await homeProvider.initHive();
configBox = await Hive.openBox("configBox");
appVersion = await homeProvider.getAppVersion(); appVersion = await homeProvider.getAppVersion();
// Configure Hive and open boxes // Configure Hive and open boxes

View File

@ -47,24 +47,28 @@ class _HomeScreenState extends State<HomeScreen> {
final myWalletProvider = final myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false); Provider.of<MyWalletsProvider>(context, listen: false);
configBox = await Hive.openBox("configBox");
final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
if (!sub.sdkReady && !sub.sdkLoading) await sub.initApi(); // Check if versionData non compatible, drop everything
if (sub.sdkReady && !sub.nodeConnected) { if (configBox.get('dataVersion') == null) {
// Check if versionData non compatible, drop everything configBox.put('dataVersion', dataVersion);
if (isWalletsExists && }
(configBox.get('dataVersion') ?? 0) < dataVersion) { if (isWalletsExists && (configBox.get('dataVersion')) < dataVersion) {
await infoPopup(context, "chestNotCompatibleMustReinstallGecko".tr()); if (!sub.sdkReady && !sub.sdkLoading) sub.initApi();
await Hive.deleteBoxFromDisk('walletBox'); await infoPopup(context, "chestNotCompatibleMustReinstallGecko".tr());
await Hive.deleteBoxFromDisk('chestBox'); await Hive.deleteBoxFromDisk('walletBox');
chestBox = await Hive.openBox<ChestData>("chestBox"); await Hive.deleteBoxFromDisk('chestBox');
await configBox.delete('defaultWallet'); chestBox = await Hive.openBox<ChestData>("chestBox");
await sub.deleteAllAccounts(); await configBox.delete('defaultWallet');
configBox.put('dataVersion', dataVersion); if (!sub.sdkReady && !sub.sdkLoading) await sub.initApi();
myWalletProvider.reload(); await sub.deleteAllAccounts();
} configBox.put('dataVersion', dataVersion);
myWalletProvider.reload();
} else {
if (!sub.sdkReady && !sub.sdkLoading) await sub.initApi();
}
if (sub.sdkReady && !sub.nodeConnected) {
walletBox = await Hive.openBox<WalletData>("walletBox"); walletBox = await Hive.openBox<WalletData>("walletBox");
await Hive.deleteBoxFromDisk('g1WalletsBox'); await Hive.deleteBoxFromDisk('g1WalletsBox');
g1WalletsBox = await Hive.openBox<G1WalletsList>("g1WalletsBox"); g1WalletsBox = await Hive.openBox<G1WalletsList>("g1WalletsBox");