From 3ec414ae666c6a78f5219e967b5596c3d2b91335 Mon Sep 17 00:00:00 2001 From: mkyq <53115730+mkyq@users.noreply.github.com> Date: Thu, 3 Nov 2022 19:13:13 -0400 Subject: [PATCH] Add adapters for some of bitcoin, litecoin and monero transactions priorities. Replace direct calls of transaction priorities for exchange_view_model. (#593) --- lib/bitcoin/cw_bitcoin.dart | 16 ++++++++++++++++ lib/monero/cw_monero.dart | 8 ++++++++ lib/view_model/exchange/exchange_view_model.dart | 15 +++++++-------- tool/configure.dart | 6 ++++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/bitcoin/cw_bitcoin.dart b/lib/bitcoin/cw_bitcoin.dart index ff6fd7531..f224efde6 100644 --- a/lib/bitcoin/cw_bitcoin.dart +++ b/lib/bitcoin/cw_bitcoin.dart @@ -140,4 +140,20 @@ class CWBitcoin extends Bitcoin { WalletService createLitecoinWalletService(Box walletInfoSource, Box unspentCoinSource) { return LitecoinWalletService(walletInfoSource, unspentCoinSource); } + + @override + TransactionPriority getBitcoinTransactionPriorityMedium() + => BitcoinTransactionPriority.medium; + + @override + TransactionPriority getLitecoinTransactionPriorityMedium() + => LitecoinTransactionPriority.medium; + + @override + TransactionPriority getBitcoinTransactionPrioritySlow() + => BitcoinTransactionPriority.slow; + + @override + TransactionPriority getLitecoinTransactionPrioritySlow() + => LitecoinTransactionPriority.slow; } \ No newline at end of file diff --git a/lib/monero/cw_monero.dart b/lib/monero/cw_monero.dart index 9b10a12c9..48c0c51a4 100644 --- a/lib/monero/cw_monero.dart +++ b/lib/monero/cw_monero.dart @@ -170,6 +170,14 @@ class CWMonero extends Monero { return MoneroTransactionPriority.automatic; } + @override + TransactionPriority getMoneroTransactionPrioritySlow() + => MoneroTransactionPriority.slow; + + @override + TransactionPriority getMoneroTransactionPriorityAutomatic() + => MoneroTransactionPriority.automatic; + @override TransactionPriority deserializeMoneroTransactionPriority({required int raw}) { return MoneroTransactionPriority.deserialize(raw: raw); diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 9ff690b70..e7e73855b 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -7,8 +7,6 @@ import 'package:cake_wallet/exchange/sideshift/sideshift_exchange_provider.dart' import 'package:cake_wallet/exchange/sideshift/sideshift_request.dart'; import 'package:cake_wallet/exchange/simpleswap/simpleswap_exchange_provider.dart'; import 'package:cake_wallet/view_model/settings/settings_view_model.dart'; -import 'package:cw_bitcoin/bitcoin_transaction_priority.dart'; -import 'package:cw_core/monero_transaction_priority.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cake_wallet/exchange/simpleswap/simpleswap_request.dart'; import 'package:cw_core/wallet_base.dart'; @@ -16,6 +14,7 @@ import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/sync_status.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/exchange/exchange_provider.dart'; import 'package:cake_wallet/exchange/limits.dart'; import 'package:cake_wallet/exchange/trade.dart'; @@ -200,11 +199,11 @@ abstract class ExchangeViewModelBase with Store { switch (wallet.type) { case WalletType.monero: case WalletType.haven: - return _settingsViewModel.transactionPriority == MoneroTransactionPriority.slow; + return _settingsViewModel.transactionPriority == monero!.getMoneroTransactionPrioritySlow(); case WalletType.bitcoin: - return _settingsViewModel.transactionPriority == BitcoinTransactionPriority.slow; + return _settingsViewModel.transactionPriority == bitcoin!.getBitcoinTransactionPrioritySlow(); case WalletType.litecoin: - return _settingsViewModel.transactionPriority == LitecoinTransactionPriority.slow; + return _settingsViewModel.transactionPriority == bitcoin!.getLitecoinTransactionPrioritySlow(); default: return false; } @@ -637,13 +636,13 @@ abstract class ExchangeViewModelBase with Store { switch (wallet.type) { case WalletType.monero: case WalletType.haven: - _settingsStore.priority[wallet.type] = MoneroTransactionPriority.automatic; + _settingsStore.priority[wallet.type] = monero!.getMoneroTransactionPriorityAutomatic(); break; case WalletType.bitcoin: - _settingsStore.priority[wallet.type] = BitcoinTransactionPriority.medium; + _settingsStore.priority[wallet.type] = bitcoin!.getBitcoinTransactionPriorityMedium(); break; case WalletType.litecoin: - _settingsStore.priority[wallet.type] = LitecoinTransactionPriority.medium; + _settingsStore.priority[wallet.type] = bitcoin!.getLitecoinTransactionPriorityMedium(); break; default: break; diff --git a/tool/configure.dart b/tool/configure.dart index ca8d3c9fb..0d3d175c4 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -92,6 +92,10 @@ abstract class Bitcoin { void updateUnspents(Object wallet); WalletService createBitcoinWalletService(Box walletInfoSource, Box unspentCoinSource); WalletService createLitecoinWalletService(Box walletInfoSource, Box unspentCoinSource); + TransactionPriority getBitcoinTransactionPriorityMedium(); + TransactionPriority getLitecoinTransactionPriorityMedium(); + TransactionPriority getBitcoinTransactionPrioritySlow(); + TransactionPriority getLitecoinTransactionPrioritySlow(); } """; @@ -218,6 +222,8 @@ abstract class Monero { int getHeigthByDate({required DateTime date}); TransactionPriority getDefaultTransactionPriority(); + TransactionPriority getMoneroTransactionPrioritySlow(); + TransactionPriority getMoneroTransactionPriorityAutomatic(); TransactionPriority deserializeMoneroTransactionPriority({required int raw}); List getTransactionPriorities(); List getMoneroWordList(String language);