remove buy_item

This commit is contained in:
Serhii 2024-02-14 11:02:06 +02:00
parent 5739bda8de
commit cd69ce482b
4 changed files with 3 additions and 83 deletions

View file

@ -163,7 +163,6 @@ import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart';
import 'package:cake_wallet/store/wallet_list_store.dart'; import 'package:cake_wallet/store/wallet_list_store.dart';
import 'package:cake_wallet/store/yat/yat_store.dart'; import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:cake_wallet/view_model/backup_view_model.dart'; import 'package:cake_wallet/view_model/backup_view_model.dart';
import 'package:cake_wallet/view_model/buy/buy_amount_view_model.dart';
import 'package:cake_wallet/view_model/buy/buy_view_model.dart'; import 'package:cake_wallet/view_model/buy/buy_view_model.dart';
import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart'; import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart';
import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart'; import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart';
@ -954,8 +953,6 @@ Future<void> setup({
getIt.registerFactoryParam<TradeDetailsPage, Trade, void>( getIt.registerFactoryParam<TradeDetailsPage, Trade, void>(
(Trade trade, _) => TradeDetailsPage(getIt.get<TradeDetailsViewModel>(param1: trade))); (Trade trade, _) => TradeDetailsPage(getIt.get<TradeDetailsViewModel>(param1: trade)));
getIt.registerFactory(() => BuyAmountViewModel());
getIt.registerFactoryParam<BuySellOptionsPage, bool, void>( getIt.registerFactoryParam<BuySellOptionsPage, bool, void>(
(isBuyOption, _) => BuySellOptionsPage(getIt.get<DashboardViewModel>(), isBuyOption)); (isBuyOption, _) => BuySellOptionsPage(getIt.get<DashboardViewModel>(), isBuyOption));
@ -963,7 +960,6 @@ Future<void> setup({
_ordersSource, _ordersSource,
getIt.get<OrdersStore>(), getIt.get<OrdersStore>(),
getIt.get<SettingsStore>(), getIt.get<SettingsStore>(),
getIt.get<BuyAmountViewModel>(),
wallet: getIt.get<AppStore>().wallet!)); wallet: getIt.get<AppStore>().wallet!));

View file

@ -1,40 +0,0 @@
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
part 'buy_amount_view_model.g.dart';
class BuyAmountViewModel = BuyAmountViewModelBase with _$BuyAmountViewModel;
abstract class BuyAmountViewModelBase with Store {
BuyAmountViewModelBase()
: amount = '',
fiatCurrency = FiatCurrency.usd {
int selectedIndex = FiatCurrency.currenciesAvailableToBuyWith
.indexOf(getIt.get<SettingsStore>().fiatCurrency);
if (selectedIndex != -1) {
fiatCurrency = FiatCurrency.currenciesAvailableToBuyWith[selectedIndex];
}
}
@observable
String amount;
@observable
FiatCurrency fiatCurrency;
@computed
double get doubleAmount {
double _amount;
try {
_amount = double.parse(amount.replaceAll(',', '.'));
} catch (_) {
_amount = 0.0;
}
return _amount;
}
}

View file

@ -1,29 +0,0 @@
import 'package:cake_wallet/buy/buy_amount.dart';
import 'package:cake_wallet/buy/buy_provider.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/view_model/buy/buy_amount_view_model.dart';
class BuyItem {
BuyItem({required this.provider, required this.buyAmountViewModel});
final BuyProvider provider;
final BuyAmountViewModel buyAmountViewModel;
double get amount => buyAmountViewModel.doubleAmount;
FiatCurrency get fiatCurrency => buyAmountViewModel.fiatCurrency;
Future<BuyAmount> get buyAmount async {
BuyAmount _buyAmount;
try {
_buyAmount = await provider
.calculateAmount(amount?.toString() ?? '', fiatCurrency.title);
} catch (e) {
_buyAmount = BuyAmount(sourceAmount: 0.0, destAmount: 0.0);
print(e.toString());
}
return _buyAmount;
}
}

View file

@ -7,28 +7,23 @@ import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/entities/provider_types.dart'; import 'package:cake_wallet/entities/provider_types.dart';
import 'package:cake_wallet/store/dashboard/orders_store.dart'; import 'package:cake_wallet/store/dashboard/orders_store.dart';
import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/buy/buy_item.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'buy_amount_view_model.dart';
part 'buy_view_model.g.dart'; part 'buy_view_model.g.dart';
class BuyViewModel = BuyViewModelBase with _$BuyViewModel; class BuyViewModel = BuyViewModelBase with _$BuyViewModel;
abstract class BuyViewModelBase with Store { abstract class BuyViewModelBase with Store {
BuyViewModelBase(this.ordersSource, this.ordersStore, this.settingsStore, this.buyAmountViewModel, BuyViewModelBase(this.ordersSource, this.ordersStore, this.settingsStore, {required this.wallet})
{required this.wallet})
: orderId = ''; : orderId = '';
final Box<Order> ordersSource; final Box<Order> ordersSource;
final OrdersStore ordersStore; final OrdersStore ordersStore;
final SettingsStore settingsStore; final SettingsStore settingsStore;
final BuyAmountViewModel buyAmountViewModel;
final WalletBase wallet; final WalletBase wallet;
String orderId; String orderId;
@ -37,10 +32,8 @@ abstract class BuyViewModelBase with Store {
WalletType get type => wallet.type; WalletType get type => wallet.type;
double get doubleAmount => buyAmountViewModel.doubleAmount;
@computed @computed
FiatCurrency get fiatCurrency => buyAmountViewModel.fiatCurrency; FiatCurrency get fiatCurrency => settingsStore.fiatCurrency;
CryptoCurrency get cryptoCurrency => walletTypeToCryptoCurrency(type); CryptoCurrency get cryptoCurrency => walletTypeToCryptoCurrency(type);
@ -50,7 +43,7 @@ abstract class BuyViewModelBase with Store {
'id': orderId, 'id': orderId,
'transferId': orderId, 'transferId': orderId,
'createdAt': DateTime.now().toIso8601String(), 'createdAt': DateTime.now().toIso8601String(),
'amount': doubleAmount.toString(), 'amount': '0.0',
'receiveAddress': 'address123', 'receiveAddress': 'address123',
'walletId': wallet.id, 'walletId': wallet.id,
'providerRaw': ProvidersHelper.serialize(selectedProviderType ?? ProviderType.askEachTime), 'providerRaw': ProvidersHelper.serialize(selectedProviderType ?? ProviderType.askEachTime),