Validate bitcoin's saved transaction priority

This commit is contained in:
OmarHatem 2022-12-15 02:00:59 +02:00
parent 987df055a0
commit 710de57847
4 changed files with 20 additions and 20 deletions

View file

@ -13,6 +13,8 @@ class BitcoinTransactionPriority extends TransactionPriority {
static const BitcoinTransactionPriority fast =
BitcoinTransactionPriority(title: 'Fast', raw: 2);
static const BitcoinTransactionPriority defaultPriority = medium;
static BitcoinTransactionPriority deserialize({required int raw}) {
switch (raw) {
case 0:
@ -22,7 +24,7 @@ class BitcoinTransactionPriority extends TransactionPriority {
case 2:
return fast;
default:
return medium;
throw Exception('Unexpected token: $raw for BitcoinTransactionPriority deserialize');
}
}
@ -73,7 +75,7 @@ class LitecoinTransactionPriority extends BitcoinTransactionPriority {
case 2:
return fast;
default:
return medium;
throw Exception('Unexpected token: $raw for LitecoinTransactionPriority deserialize');
}
}

View file

@ -21,22 +21,6 @@ class MoneroTransactionPriority extends TransactionPriority {
static const fastest = MoneroTransactionPriority(title: 'Fastest', raw: 4);
static const standard = slow;
static List<MoneroTransactionPriority> forWalletType(WalletType type) {
switch (type) {
case WalletType.monero:
return MoneroTransactionPriority.all;
case WalletType.bitcoin:
return [
MoneroTransactionPriority.slow,
MoneroTransactionPriority.automatic,
MoneroTransactionPriority.fast
];
default:
return [];
}
}
static MoneroTransactionPriority deserialize({required int raw}) {
switch (raw) {
case 0:
@ -50,7 +34,7 @@ class MoneroTransactionPriority extends TransactionPriority {
case 4:
return fastest;
default:
return automatic;
throw Exception('Unexpected token: $raw for MoneroTransactionPriority deserialize');
}
}

View file

@ -1,10 +1,12 @@
import 'dart:io' show File, Platform;
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cw_bitcoin/bitcoin_transaction_priority.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cake_wallet/entities/secret_store_key.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:hive/hive.dart';
import 'package:share_plus/share_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cw_core/wallet_type.dart';
@ -139,6 +141,10 @@ Future defaultSettingsMigration(
await addOnionNode(nodes);
break;
case 19:
await validateBitcoinSavedTransactionPriority(sharedPreferences);
break;
default:
break;
}
@ -154,6 +160,14 @@ Future defaultSettingsMigration(
PreferencesKey.currentDefaultSettingsMigrationVersion, version);
}
Future<void> validateBitcoinSavedTransactionPriority(SharedPreferences sharedPreferences) async {
int? savedBitcoinPriority = sharedPreferences.getInt(PreferencesKey.bitcoinTransactionPriority);
if (!BitcoinTransactionPriority.all.any((element) => element.raw == savedBitcoinPriority)) {
await sharedPreferences.setInt(
PreferencesKey.bitcoinTransactionPriority, BitcoinTransactionPriority.defaultPriority.raw);
}
}
Future<void> addOnionNode(Box<Node> nodes) async {
final onionNodeUri = "cakexmrl7bonq7ovjka5kuwuyd3f7qnkz6z6s6dmsy3uckwra7bvggyd.onion:18081";

View file

@ -129,7 +129,7 @@ Future<void> main() async {
exchangeTemplates: exchangeTemplates,
transactionDescriptions: transactionDescriptions,
secureStorage: secureStorage,
initialMigrationVersion: 18);
initialMigrationVersion: 19);
runApp(App());
} catch (e, stacktrace) {
runApp(MaterialApp(