externalCalls set and db migration

This commit is contained in:
Marco 2022-10-19 16:51:50 -06:00
parent 27c2e38311
commit b8836397a9
5 changed files with 35 additions and 6 deletions

View file

@ -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<MaterialAppWithTheme>
// unawaited(_nodeService.updateCommunityNodes());
// run without awaiting
if (Constants.enableExchange && _prefs.externalCalls) {
if (Constants.enableExchange &&
_prefs.externalCalls &&
await _prefs.isExternalCallsSet()) {
unawaited(ExchangeDataLoadingService().loadAll(ref));
}

View file

@ -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<Coin, Tuple2<Decimal, double>> result = {};
try {
final uri = Uri.parse(
@ -123,7 +123,8 @@ class PriceAPI {
static Future<List<String>?> 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;

View file

@ -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<int> possibleLengthsForCoin(Coin coin) {
final List<int> values = [];

View file

@ -143,6 +143,18 @@ class DbVersionMigrator {
// try to continue migrating
return await migrate(2);
case 2:
await Hive.openBox<dynamic>(DB.boxNamePrefs);
final prefs = Prefs.instance;
await prefs.init();
if (!(await prefs.isExternalCallsSet())) {
prefs.externalCalls = true;
}
// update version
await DB.instance.put<dynamic>(
boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 3);
return await migrate(3);
default:
// finally return

View file

@ -571,4 +571,13 @@ class Prefs extends ChangeNotifier {
boxName: DB.boxNamePrefs, key: "externalCalls") as bool? ??
true;
}
Future<bool> isExternalCallsSet() async {
if (await DB.instance
.get<dynamic>(boxName: DB.boxNamePrefs, key: "externalCalls") ==
null) {
return false;
}
return true;
}
}