From cd69ce482b3efec8ffab8ff3c046fb8a99fd37f8 Mon Sep 17 00:00:00 2001 From: Serhii Date: Wed, 14 Feb 2024 11:02:06 +0200 Subject: [PATCH] remove buy_item --- lib/di.dart | 4 -- lib/view_model/buy/buy_amount_view_model.dart | 40 ------------------- lib/view_model/buy/buy_item.dart | 29 -------------- lib/view_model/buy/buy_view_model.dart | 13 ++---- 4 files changed, 3 insertions(+), 83 deletions(-) delete mode 100644 lib/view_model/buy/buy_amount_view_model.dart delete mode 100644 lib/view_model/buy/buy_item.dart diff --git a/lib/di.dart b/lib/di.dart index 7edcffa73..c41889906 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -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/yat/yat_store.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/contact_list/contact_list_view_model.dart'; import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart'; @@ -954,8 +953,6 @@ Future setup({ getIt.registerFactoryParam( (Trade trade, _) => TradeDetailsPage(getIt.get(param1: trade))); - getIt.registerFactory(() => BuyAmountViewModel()); - getIt.registerFactoryParam( (isBuyOption, _) => BuySellOptionsPage(getIt.get(), isBuyOption)); @@ -963,7 +960,6 @@ Future setup({ _ordersSource, getIt.get(), getIt.get(), - getIt.get(), wallet: getIt.get().wallet!)); diff --git a/lib/view_model/buy/buy_amount_view_model.dart b/lib/view_model/buy/buy_amount_view_model.dart deleted file mode 100644 index 8f23d9ef4..000000000 --- a/lib/view_model/buy/buy_amount_view_model.dart +++ /dev/null @@ -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().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; - } -} diff --git a/lib/view_model/buy/buy_item.dart b/lib/view_model/buy/buy_item.dart deleted file mode 100644 index 97bd661f2..000000000 --- a/lib/view_model/buy/buy_item.dart +++ /dev/null @@ -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 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; - } -} \ No newline at end of file diff --git a/lib/view_model/buy/buy_view_model.dart b/lib/view_model/buy/buy_view_model.dart index 88971f510..cb95d6914 100644 --- a/lib/view_model/buy/buy_view_model.dart +++ b/lib/view_model/buy/buy_view_model.dart @@ -7,28 +7,23 @@ import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/entities/provider_types.dart'; import 'package:cake_wallet/store/dashboard/orders_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/wallet_base.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; -import 'buy_amount_view_model.dart'; - part 'buy_view_model.g.dart'; class BuyViewModel = BuyViewModelBase with _$BuyViewModel; abstract class BuyViewModelBase with Store { - BuyViewModelBase(this.ordersSource, this.ordersStore, this.settingsStore, this.buyAmountViewModel, - {required this.wallet}) + BuyViewModelBase(this.ordersSource, this.ordersStore, this.settingsStore, {required this.wallet}) : orderId = ''; final Box ordersSource; final OrdersStore ordersStore; final SettingsStore settingsStore; - final BuyAmountViewModel buyAmountViewModel; final WalletBase wallet; String orderId; @@ -37,10 +32,8 @@ abstract class BuyViewModelBase with Store { WalletType get type => wallet.type; - double get doubleAmount => buyAmountViewModel.doubleAmount; - @computed - FiatCurrency get fiatCurrency => buyAmountViewModel.fiatCurrency; + FiatCurrency get fiatCurrency => settingsStore.fiatCurrency; CryptoCurrency get cryptoCurrency => walletTypeToCryptoCurrency(type); @@ -50,7 +43,7 @@ abstract class BuyViewModelBase with Store { 'id': orderId, 'transferId': orderId, 'createdAt': DateTime.now().toIso8601String(), - 'amount': doubleAmount.toString(), + 'amount': '0.0', 'receiveAddress': 'address123', 'walletId': wallet.id, 'providerRaw': ProvidersHelper.serialize(selectedProviderType ?? ProviderType.askEachTime),