mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
- Fix haven and litecoin fee transaction priority issue
- Revert removing fiat rate update and use it to update fiat rate periodically if Fiat API is not disabled
This commit is contained in:
parent
6395d6b2f7
commit
ce19be56a0
6 changed files with 104 additions and 24 deletions
|
@ -51,6 +51,10 @@ class CWBitcoin extends Bitcoin {
|
||||||
TransactionPriority deserializeBitcoinTransactionPriority(int raw)
|
TransactionPriority deserializeBitcoinTransactionPriority(int raw)
|
||||||
=> BitcoinTransactionPriority.deserialize(raw: raw);
|
=> BitcoinTransactionPriority.deserialize(raw: raw);
|
||||||
|
|
||||||
|
@override
|
||||||
|
TransactionPriority deserializeLitecoinTransactionPriority(int raw)
|
||||||
|
=> LitecoinTransactionPriority.deserialize(raw: raw);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int getFeeRate(Object wallet, TransactionPriority priority) {
|
int getFeeRate(Object wallet, TransactionPriority priority) {
|
||||||
final bitcoinWallet = wallet as ElectrumWallet;
|
final bitcoinWallet = wallet as ElectrumWallet;
|
||||||
|
|
|
@ -22,6 +22,8 @@ class PreferencesKey {
|
||||||
'current_default_settings_migration_version';
|
'current_default_settings_migration_version';
|
||||||
static const moneroTransactionPriority = 'current_fee_priority_monero';
|
static const moneroTransactionPriority = 'current_fee_priority_monero';
|
||||||
static const bitcoinTransactionPriority = 'current_fee_priority_bitcoin';
|
static const bitcoinTransactionPriority = 'current_fee_priority_bitcoin';
|
||||||
|
static const havenTransactionPriority = 'current_fee_priority_haven';
|
||||||
|
static const litecoinTransactionPriority = 'current_fee_priority_litecoin';
|
||||||
static const shouldShowReceiveWarning = 'should_show_receive_warning';
|
static const shouldShowReceiveWarning = 'should_show_receive_warning';
|
||||||
static const shouldShowYatPopup = 'should_show_yat_popup';
|
static const shouldShowYatPopup = 'should_show_yat_popup';
|
||||||
static const moneroWalletPasswordUpdateV1Base = 'monero_wallet_update_v1';
|
static const moneroWalletPasswordUpdateV1Base = 'monero_wallet_update_v1';
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:cake_wallet/reactions/fiat_rate_update.dart';
|
||||||
import 'package:cake_wallet/reactions/on_current_node_change.dart';
|
import 'package:cake_wallet/reactions/on_current_node_change.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
@ -31,4 +32,5 @@ Future<void> bootstrap(GlobalKey<NavigatorState> navigatorKey) async {
|
||||||
appStore, settingsStore, fiatConversionStore);
|
appStore, settingsStore, fiatConversionStore);
|
||||||
startCurrentFiatChangeReaction(appStore, settingsStore, fiatConversionStore);
|
startCurrentFiatChangeReaction(appStore, settingsStore, fiatConversionStore);
|
||||||
startOnCurrentNodeChangeReaction(appStore);
|
startOnCurrentNodeChangeReaction(appStore);
|
||||||
|
startFiatRateUpdate(appStore, settingsStore, fiatConversionStore);
|
||||||
}
|
}
|
||||||
|
|
40
lib/reactions/fiat_rate_update.dart
Normal file
40
lib/reactions/fiat_rate_update.dart
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
||||||
|
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||||
|
import 'package:cake_wallet/entities/update_haven_rate.dart';
|
||||||
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
Future<void> startFiatRateUpdate(
|
||||||
|
AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) async {
|
||||||
|
if (_timer != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appStore.wallet != null && settingsStore.fiatApiMode == FiatApiMode.enabled) {
|
||||||
|
fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice(
|
||||||
|
appStore.wallet!.currency, settingsStore.fiatCurrency);
|
||||||
|
}
|
||||||
|
|
||||||
|
_timer = Timer.periodic(Duration(seconds: 30), (_) async {
|
||||||
|
if (settingsStore.fiatApiMode == FiatApiMode.disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (appStore.wallet!.type == WalletType.haven) {
|
||||||
|
await updateHavenRate(fiatConversionStore);
|
||||||
|
} else {
|
||||||
|
fiatConversionStore.prices[appStore.wallet!.currency] =
|
||||||
|
await FiatConversionService.fetchPrice(
|
||||||
|
appStore.wallet!.currency, settingsStore.fiatCurrency);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -44,7 +44,9 @@ abstract class SettingsStoreBase with Store {
|
||||||
required this.isBitcoinBuyEnabled,
|
required this.isBitcoinBuyEnabled,
|
||||||
required this.actionlistDisplayMode,
|
required this.actionlistDisplayMode,
|
||||||
TransactionPriority? initialBitcoinTransactionPriority,
|
TransactionPriority? initialBitcoinTransactionPriority,
|
||||||
TransactionPriority? initialMoneroTransactionPriority})
|
TransactionPriority? initialMoneroTransactionPriority,
|
||||||
|
TransactionPriority? initialHavenTransactionPriority,
|
||||||
|
TransactionPriority? initialLitecoinTransactionPriority})
|
||||||
: nodes = ObservableMap<WalletType, Node>.of(nodes),
|
: nodes = ObservableMap<WalletType, Node>.of(nodes),
|
||||||
_sharedPreferences = sharedPreferences,
|
_sharedPreferences = sharedPreferences,
|
||||||
fiatCurrency = initialFiatCurrency,
|
fiatCurrency = initialFiatCurrency,
|
||||||
|
@ -67,6 +69,14 @@ abstract class SettingsStoreBase with Store {
|
||||||
priority[WalletType.bitcoin] = initialBitcoinTransactionPriority;
|
priority[WalletType.bitcoin] = initialBitcoinTransactionPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (initialHavenTransactionPriority != null) {
|
||||||
|
priority[WalletType.haven] = initialHavenTransactionPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (initialLitecoinTransactionPriority != null) {
|
||||||
|
priority[WalletType.litecoin] = initialLitecoinTransactionPriority;
|
||||||
|
}
|
||||||
|
|
||||||
reaction(
|
reaction(
|
||||||
(_) => fiatCurrency,
|
(_) => fiatCurrency,
|
||||||
(FiatCurrency fiatCurrency) => sharedPreferences.setString(
|
(FiatCurrency fiatCurrency) => sharedPreferences.setString(
|
||||||
|
@ -78,11 +88,25 @@ abstract class SettingsStoreBase with Store {
|
||||||
.setBool(PreferencesKey.shouldShowYatPopup, shouldShowYatPopup));
|
.setBool(PreferencesKey.shouldShowYatPopup, shouldShowYatPopup));
|
||||||
|
|
||||||
priority.observe((change) {
|
priority.observe((change) {
|
||||||
final key = change.key == WalletType.monero
|
final String? key;
|
||||||
? PreferencesKey.moneroTransactionPriority
|
switch (change.key) {
|
||||||
: PreferencesKey.bitcoinTransactionPriority;
|
case WalletType.monero:
|
||||||
|
key = PreferencesKey.moneroTransactionPriority;
|
||||||
|
break;
|
||||||
|
case WalletType.bitcoin:
|
||||||
|
key = PreferencesKey.bitcoinTransactionPriority;
|
||||||
|
break;
|
||||||
|
case WalletType.litecoin:
|
||||||
|
key = PreferencesKey.litecoinTransactionPriority;
|
||||||
|
break;
|
||||||
|
case WalletType.haven:
|
||||||
|
key = PreferencesKey.havenTransactionPriority;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
key = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (change.newValue != null) {
|
if (change.newValue != null && key != null) {
|
||||||
sharedPreferences.setInt(key, change.newValue!.serialize());
|
sharedPreferences.setInt(key, change.newValue!.serialize());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -202,33 +226,39 @@ abstract class SettingsStoreBase with Store {
|
||||||
static Future<SettingsStore> load(
|
static Future<SettingsStore> load(
|
||||||
{required Box<Node> nodeSource,
|
{required Box<Node> nodeSource,
|
||||||
required bool isBitcoinBuyEnabled,
|
required bool isBitcoinBuyEnabled,
|
||||||
TransactionPriority? initialMoneroTransactionPriority,
|
|
||||||
TransactionPriority? initialBitcoinTransactionPriority,
|
|
||||||
FiatCurrency initialFiatCurrency = FiatCurrency.usd,
|
FiatCurrency initialFiatCurrency = FiatCurrency.usd,
|
||||||
BalanceDisplayMode initialBalanceDisplayMode =
|
BalanceDisplayMode initialBalanceDisplayMode =
|
||||||
BalanceDisplayMode.availableBalance}) async {
|
BalanceDisplayMode.availableBalance}) async {
|
||||||
if (initialBitcoinTransactionPriority == null) {
|
|
||||||
initialBitcoinTransactionPriority = bitcoin?.getMediumTransactionPriority();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (initialMoneroTransactionPriority == null) {
|
|
||||||
initialMoneroTransactionPriority = monero?.getDefaultTransactionPriority();
|
|
||||||
}
|
|
||||||
|
|
||||||
final sharedPreferences = await getIt.getAsync<SharedPreferences>();
|
final sharedPreferences = await getIt.getAsync<SharedPreferences>();
|
||||||
final currentFiatCurrency = FiatCurrency.deserialize(raw:
|
final currentFiatCurrency = FiatCurrency.deserialize(raw:
|
||||||
sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!);
|
sharedPreferences.getString(PreferencesKey.currentFiatCurrencyKey)!);
|
||||||
final savedMoneroTransactionPriority =
|
|
||||||
|
TransactionPriority? moneroTransactionPriority =
|
||||||
monero?.deserializeMoneroTransactionPriority(
|
monero?.deserializeMoneroTransactionPriority(
|
||||||
raw: sharedPreferences
|
raw: sharedPreferences
|
||||||
.getInt(PreferencesKey.moneroTransactionPriority)!);
|
.getInt(PreferencesKey.moneroTransactionPriority)!);
|
||||||
final savedBitcoinTransactionPriority =
|
TransactionPriority? bitcoinTransactionPriority =
|
||||||
bitcoin?.deserializeBitcoinTransactionPriority(sharedPreferences
|
bitcoin?.deserializeBitcoinTransactionPriority(sharedPreferences
|
||||||
.getInt(PreferencesKey.bitcoinTransactionPriority)!);
|
.getInt(PreferencesKey.bitcoinTransactionPriority)!);
|
||||||
final moneroTransactionPriority =
|
|
||||||
savedMoneroTransactionPriority ?? initialMoneroTransactionPriority;
|
TransactionPriority? havenTransactionPriority;
|
||||||
final bitcoinTransactionPriority =
|
TransactionPriority? litecoinTransactionPriority;
|
||||||
savedBitcoinTransactionPriority ?? initialBitcoinTransactionPriority;
|
|
||||||
|
if (sharedPreferences.getInt(PreferencesKey.havenTransactionPriority) != null) {
|
||||||
|
havenTransactionPriority = monero?.deserializeMoneroTransactionPriority(
|
||||||
|
raw: sharedPreferences.getInt(PreferencesKey.havenTransactionPriority)!);
|
||||||
|
}
|
||||||
|
if (sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority) != null) {
|
||||||
|
litecoinTransactionPriority = bitcoin?.deserializeLitecoinTransactionPriority(
|
||||||
|
sharedPreferences.getInt(PreferencesKey.litecoinTransactionPriority)!);
|
||||||
|
}
|
||||||
|
|
||||||
|
moneroTransactionPriority ??= monero?.getDefaultTransactionPriority();
|
||||||
|
bitcoinTransactionPriority ??= bitcoin?.getMediumTransactionPriority();
|
||||||
|
havenTransactionPriority ??= monero?.getDefaultTransactionPriority();
|
||||||
|
litecoinTransactionPriority ??= bitcoin?.getLitecoinTransactionPriorityMedium();
|
||||||
|
|
||||||
final currentBalanceDisplayMode = BalanceDisplayMode.deserialize(
|
final currentBalanceDisplayMode = BalanceDisplayMode.deserialize(
|
||||||
raw: sharedPreferences
|
raw: sharedPreferences
|
||||||
.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
|
.getInt(PreferencesKey.currentBalanceDisplayModeKey)!);
|
||||||
|
@ -249,8 +279,7 @@ abstract class SettingsStoreBase with Store {
|
||||||
: ThemeType.bright.index;
|
: ThemeType.bright.index;
|
||||||
final savedTheme = ThemeList.deserialize(
|
final savedTheme = ThemeList.deserialize(
|
||||||
raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ??
|
raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ??
|
||||||
legacyTheme ??
|
legacyTheme);
|
||||||
0);
|
|
||||||
final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
|
final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
|
||||||
actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
|
actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
|
||||||
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
|
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
|
||||||
|
@ -314,6 +343,8 @@ abstract class SettingsStoreBase with Store {
|
||||||
initialLanguageCode: savedLanguageCode,
|
initialLanguageCode: savedLanguageCode,
|
||||||
initialMoneroTransactionPriority: moneroTransactionPriority,
|
initialMoneroTransactionPriority: moneroTransactionPriority,
|
||||||
initialBitcoinTransactionPriority: bitcoinTransactionPriority,
|
initialBitcoinTransactionPriority: bitcoinTransactionPriority,
|
||||||
|
initialHavenTransactionPriority: havenTransactionPriority,
|
||||||
|
initialLitecoinTransactionPriority: litecoinTransactionPriority,
|
||||||
shouldShowYatPopup: shouldShowYatPopup);
|
shouldShowYatPopup: shouldShowYatPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ abstract class Bitcoin {
|
||||||
List<TransactionPriority> getTransactionPriorities();
|
List<TransactionPriority> getTransactionPriorities();
|
||||||
List<TransactionPriority> getLitecoinTransactionPriorities();
|
List<TransactionPriority> getLitecoinTransactionPriorities();
|
||||||
TransactionPriority deserializeBitcoinTransactionPriority(int raw);
|
TransactionPriority deserializeBitcoinTransactionPriority(int raw);
|
||||||
|
TransactionPriority deserializeLitecoinTransactionPriority(int raw);
|
||||||
int getFeeRate(Object wallet, TransactionPriority priority);
|
int getFeeRate(Object wallet, TransactionPriority priority);
|
||||||
Future<void> generateNewAddress(Object wallet);
|
Future<void> generateNewAddress(Object wallet);
|
||||||
Object createBitcoinTransactionCredentials(List<Output> outputs, {required TransactionPriority priority, int? feeRate});
|
Object createBitcoinTransactionCredentials(List<Output> outputs, {required TransactionPriority priority, int? feeRate});
|
||||||
|
|
Loading…
Reference in a new issue