mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-22 06:28:39 +02:00
Fix issues from code review
This commit is contained in:
@@ -6,8 +6,8 @@ import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
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:cake_wallet/exchange/simpleswap/simpleswap_request.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/sync_status.dart';
|
||||
@@ -42,7 +42,7 @@ class ExchangeViewModel = ExchangeViewModelBase with _$ExchangeViewModel;
|
||||
|
||||
abstract class ExchangeViewModelBase with Store {
|
||||
ExchangeViewModelBase(this.wallet, this.trades, this._exchangeTemplateStore,
|
||||
this.tradesStore, this._settingsStore, this.sharedPreferences, this._settingsViewModel)
|
||||
this.tradesStore, this._settingsStore, this.sharedPreferences)
|
||||
: _cryptoNumberFormat = NumberFormat(),
|
||||
isReverse = false,
|
||||
isFixedRateMode = false,
|
||||
@@ -189,6 +189,19 @@ abstract class ExchangeViewModelBase with Store {
|
||||
ObservableList<ExchangeTemplate> get templates =>
|
||||
_exchangeTemplateStore.templates;
|
||||
|
||||
|
||||
@computed
|
||||
TransactionPriority get transactionPriority {
|
||||
final priority = _settingsStore.priority[wallet.type];
|
||||
|
||||
if (priority == null) {
|
||||
throw Exception('Unexpected type ${wallet.type.toString()}');
|
||||
}
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
|
||||
bool get hasAllAmount =>
|
||||
wallet.type == WalletType.bitcoin && depositCurrency == wallet.currency;
|
||||
|
||||
@@ -198,11 +211,11 @@ abstract class ExchangeViewModelBase with Store {
|
||||
switch (wallet.type) {
|
||||
case WalletType.monero:
|
||||
case WalletType.haven:
|
||||
return _settingsViewModel.transactionPriority == monero!.getMoneroTransactionPrioritySlow();
|
||||
return transactionPriority == monero!.getMoneroTransactionPrioritySlow();
|
||||
case WalletType.bitcoin:
|
||||
return _settingsViewModel.transactionPriority == bitcoin!.getBitcoinTransactionPrioritySlow();
|
||||
return transactionPriority == bitcoin!.getBitcoinTransactionPrioritySlow();
|
||||
case WalletType.litecoin:
|
||||
return _settingsViewModel.transactionPriority == bitcoin!.getLitecoinTransactionPrioritySlow();
|
||||
return transactionPriority == bitcoin!.getLitecoinTransactionPrioritySlow();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -220,8 +233,6 @@ abstract class ExchangeViewModelBase with Store {
|
||||
|
||||
final SettingsStore _settingsStore;
|
||||
|
||||
final SettingsViewModel _settingsViewModel;
|
||||
|
||||
double _bestRate = 0.0;
|
||||
|
||||
late Timer bestRateSync;
|
||||
|
||||
@@ -42,7 +42,8 @@ abstract class SendViewModelBase with Store {
|
||||
: state = InitialExecutionState(),
|
||||
currencies = _wallet.balance.keys.toList(),
|
||||
selectedCryptoCurrency = _wallet.currency,
|
||||
outputs = ObservableList<Output>() {
|
||||
outputs = ObservableList<Output>(),
|
||||
fiatFromSettings = _settingsStore.fiatCurrency {
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
final priorities = priorityForWalletType(_wallet.type);
|
||||
|
||||
@@ -52,7 +53,7 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
|
||||
}
|
||||
|
||||
|
||||
@observable
|
||||
ExecutionState state;
|
||||
|
||||
@@ -133,11 +134,13 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
Validator get textValidator => TextValidator();
|
||||
|
||||
final FiatCurrency fiatFromSettings;
|
||||
|
||||
@observable
|
||||
PendingTransaction? pendingTransaction;
|
||||
|
||||
@computed
|
||||
String get balance => balanceViewModel.availableBalance ?? '0.0';
|
||||
String get balance => balanceViewModel.availableBalance;
|
||||
|
||||
@computed
|
||||
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
|
||||
@@ -166,6 +169,9 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
bool get hasCurrecyChanger => walletType == WalletType.haven;
|
||||
|
||||
@computed
|
||||
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
|
||||
|
||||
final WalletBase _wallet;
|
||||
final SettingsStore _settingsStore;
|
||||
final SendTemplateViewModel sendTemplateViewModel;
|
||||
@@ -208,7 +214,7 @@ abstract class SendViewModelBase with Store {
|
||||
state = TransactionCommitting();
|
||||
await pendingTransaction!.commit();
|
||||
|
||||
if (pendingTransaction!.id?.isNotEmpty ?? false) {
|
||||
if (pendingTransaction!.id.isNotEmpty) {
|
||||
_settingsStore.shouldSaveRecipientAddress
|
||||
? await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: pendingTransaction!.id,
|
||||
@@ -283,4 +289,12 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
bool _isEqualCurrency(String currency) =>
|
||||
currency.toLowerCase() == _wallet.currency.title.toLowerCase();
|
||||
|
||||
@action
|
||||
void onClose() =>
|
||||
_settingsStore.fiatCurrency = fiatFromSettings;
|
||||
|
||||
@action
|
||||
void setFiatCurrency(FiatCurrency fiat) =>
|
||||
_settingsStore.fiatCurrency = fiat;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ abstract class PrivacySettingsViewModelBase with Store {
|
||||
|
||||
final SettingsStore _settingsStore;
|
||||
|
||||
@computed
|
||||
bool get disableExchange => _settingsStore.disableExchange;
|
||||
|
||||
@computed
|
||||
bool get shouldSaveRecipientAddress =>
|
||||
_settingsStore.shouldSaveRecipientAddress;
|
||||
@@ -18,4 +21,8 @@ abstract class PrivacySettingsViewModelBase with Store {
|
||||
@action
|
||||
void setShouldSaveRecipientAddress(bool value) =>
|
||||
_settingsStore.shouldSaveRecipientAddress = value;
|
||||
|
||||
@action
|
||||
void setEnableExchange(bool value) =>
|
||||
_settingsStore.disableExchange = value;
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
import 'package:cake_wallet/entities/priority_for_wallet_type.dart';
|
||||
import 'package:cake_wallet/store/yat/yat_store.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/action_list_display_mode.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
import 'package:cw_core/balance.dart';
|
||||
import 'package:cw_core/transaction_info.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cake_wallet/themes/theme_base.dart';
|
||||
|
||||
part 'settings_view_model.g.dart';
|
||||
|
||||
class SettingsViewModel = SettingsViewModelBase with _$SettingsViewModel;
|
||||
|
||||
abstract class SettingsViewModelBase with Store {
|
||||
SettingsViewModelBase(
|
||||
this._settingsStore,
|
||||
this._yatStore,
|
||||
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
||||
TransactionInfo>
|
||||
wallet)
|
||||
: itemHeaders = {},
|
||||
walletType = wallet.type,
|
||||
_wallet = wallet{
|
||||
|
||||
final priority = _settingsStore.priority[wallet.type];
|
||||
final priorities = priorityForWalletType(wallet.type);
|
||||
|
||||
if (!priorities.contains(priority)) {
|
||||
_settingsStore.priority[wallet.type] = priorities.first;
|
||||
}
|
||||
|
||||
//var connectYatUrl = YatLink.baseUrl + YatLink.signInSuffix;
|
||||
//final connectYatUrlParameters =
|
||||
// _yatStore.defineQueryParameters();
|
||||
|
||||
//if (connectYatUrlParameters.isNotEmpty) {
|
||||
// connectYatUrl += YatLink.queryParameter + connectYatUrlParameters;
|
||||
//}
|
||||
|
||||
//var manageYatUrl = YatLink.baseUrl + YatLink.managePath;
|
||||
//final manageYatUrlParameters =
|
||||
// _yatStore.defineQueryParameters();
|
||||
|
||||
//if (manageYatUrlParameters.isNotEmpty) {
|
||||
// manageYatUrl += YatLink.queryParameter + manageYatUrlParameters;
|
||||
//}
|
||||
|
||||
//var createNewYatUrl = YatLink.startFlowUrl;
|
||||
//final createNewYatUrlParameters =
|
||||
// _yatStore.defineQueryParameters();
|
||||
|
||||
//if (createNewYatUrlParameters.isNotEmpty) {
|
||||
// createNewYatUrl += '?sub1=' + createNewYatUrlParameters;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@computed
|
||||
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
|
||||
|
||||
@computed
|
||||
ObservableList<ActionListDisplayMode> get actionlistDisplayMode =>
|
||||
_settingsStore.actionlistDisplayMode;
|
||||
|
||||
@computed
|
||||
TransactionPriority get transactionPriority {
|
||||
final priority = _settingsStore.priority[walletType];
|
||||
|
||||
if (priority == null) {
|
||||
throw Exception('Unexpected type ${walletType.toString()}');
|
||||
}
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
@computed
|
||||
ThemeBase get theme => _settingsStore.currentTheme;
|
||||
|
||||
bool get isBitcoinBuyEnabled => _settingsStore.isBitcoinBuyEnabled;
|
||||
|
||||
final Map<String, String> itemHeaders;
|
||||
final SettingsStore _settingsStore;
|
||||
final YatStore _yatStore;
|
||||
final WalletType walletType;
|
||||
final WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
||||
TransactionInfo> _wallet;
|
||||
|
||||
@action
|
||||
void setFiatCurrency(FiatCurrency value) =>
|
||||
_settingsStore.fiatCurrency = value;
|
||||
|
||||
@action
|
||||
void toggleTransactionsDisplay() =>
|
||||
actionlistDisplayMode.contains(ActionListDisplayMode.transactions)
|
||||
? _hideTransaction()
|
||||
: _showTransaction();
|
||||
|
||||
@action
|
||||
void toggleTradesDisplay() =>
|
||||
actionlistDisplayMode.contains(ActionListDisplayMode.trades)
|
||||
? _hideTrades()
|
||||
: _showTrades();
|
||||
|
||||
@action
|
||||
void _hideTransaction() =>
|
||||
actionlistDisplayMode.remove(ActionListDisplayMode.transactions);
|
||||
|
||||
@action
|
||||
void _hideTrades() =>
|
||||
actionlistDisplayMode.remove(ActionListDisplayMode.trades);
|
||||
|
||||
@action
|
||||
void _showTransaction() =>
|
||||
actionlistDisplayMode.add(ActionListDisplayMode.transactions);
|
||||
|
||||
@action
|
||||
void _showTrades() => actionlistDisplayMode.add(ActionListDisplayMode.trades);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user