diff --git a/lib/main.dart b/lib/main.dart index ad1ef9b7f..eb7cd8e64 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -143,7 +143,12 @@ void main() async { boxName: DB.boxNameDBInfo, key: "hive_data_version") as int? ?? 0; if (dbVersion < Constants.currentHiveDbVersion) { - await DbVersionMigrator().migrate(dbVersion); + try { + await DbVersionMigrator().migrate(dbVersion); + } catch (e, s) { + Logging.instance.log("Cannot migrate database\n$e $s", + level: LogLevel.Error, printFullLength: true); + } } monero.onStartup(); @@ -231,7 +236,9 @@ class _MaterialAppWithThemeState extends ConsumerState // unawaited(_nodeService.updateCommunityNodes()); // run without awaiting - if (Constants.enableExchange && _prefs.externalCalls) { + if (Constants.enableExchange && + _prefs.externalCalls && + await _prefs.isExternalCallsSet()) { unawaited(ExchangeDataLoadingService().loadAll(ref)); } diff --git a/lib/services/price.dart b/lib/services/price.dart index 4f6650b06..b44e055d5 100644 --- a/lib/services/price.dart +++ b/lib/services/price.dart @@ -78,12 +78,12 @@ class PriceAPI { } final externalCalls = Prefs.instance.externalCalls; - if (!Logger.isTestEnv && !externalCalls) { + if ((!Logger.isTestEnv && !externalCalls) || + !(await Prefs.instance.isExternalCallsSet())) { Logging.instance.log("User does not want to use external calls", level: LogLevel.Info); return _cachedPrices; } - Map> result = {}; try { final uri = Uri.parse( @@ -123,7 +123,8 @@ class PriceAPI { static Future?> availableBaseCurrencies() async { final externalCalls = Prefs.instance.externalCalls; - if (!Logger.isTestEnv && !externalCalls) { + if ((!Logger.isTestEnv && !externalCalls) || + !(await Prefs.instance.isExternalCallsSet())) { Logging.instance.log("User does not want to use external calls", level: LogLevel.Info); return null; diff --git a/lib/utilities/constants.dart b/lib/utilities/constants.dart index 4eb69d7e1..2495a6be4 100644 --- a/lib/utilities/constants.dart +++ b/lib/utilities/constants.dart @@ -36,7 +36,7 @@ abstract class Constants { // Enable Logger.print statements static const bool disableLogger = false; - static const int currentHiveDbVersion = 2; + static const int currentHiveDbVersion = 3; static List possibleLengthsForCoin(Coin coin) { final List values = []; diff --git a/lib/utilities/db_version_migration.dart b/lib/utilities/db_version_migration.dart index 26af1c48a..d1763e266 100644 --- a/lib/utilities/db_version_migration.dart +++ b/lib/utilities/db_version_migration.dart @@ -143,6 +143,18 @@ class DbVersionMigrator { // try to continue migrating return await migrate(2); + case 2: + await Hive.openBox(DB.boxNamePrefs); + final prefs = Prefs.instance; + await prefs.init(); + if (!(await prefs.isExternalCallsSet())) { + prefs.externalCalls = true; + } + + // update version + await DB.instance.put( + boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 3); + return await migrate(3); default: // finally return diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index 2fc21a78d..246291053 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -571,4 +571,13 @@ class Prefs extends ChangeNotifier { boxName: DB.boxNamePrefs, key: "externalCalls") as bool? ?? true; } + + Future isExternalCallsSet() async { + if (await DB.instance + .get(boxName: DB.boxNamePrefs, key: "externalCalls") == + null) { + return false; + } + return true; + } }