2021-04-12 18:22:22 +00:00
|
|
|
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';
|
2024-12-09 18:23:59 +00:00
|
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
2021-04-12 18:22:22 +00:00
|
|
|
|
|
|
|
class BuyItem {
|
2022-10-12 17:09:57 +00:00
|
|
|
BuyItem({required this.provider, required this.buyAmountViewModel});
|
2021-04-12 18:22:22 +00:00
|
|
|
|
|
|
|
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
|
2022-10-12 17:09:57 +00:00
|
|
|
.calculateAmount(amount?.toString() ?? '', fiatCurrency.title);
|
2021-04-12 18:22:22 +00:00
|
|
|
} catch (e) {
|
|
|
|
_buyAmount = BuyAmount(sourceAmount: 0.0, destAmount: 0.0);
|
2024-12-09 18:23:59 +00:00
|
|
|
printV(e.toString());
|
2021-04-12 18:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _buyAmount;
|
|
|
|
}
|
|
|
|
}
|