| 1 | import 'package:cake_wallet/buy/buy_amount.dart'; |
| 2 | import 'package:cake_wallet/buy/buy_provider.dart'; |
| 3 | import 'package:cake_wallet/entities/fiat_currency.dart'; |
| 4 | import 'package:cake_wallet/view_model/buy/buy_amount_view_model.dart'; |
| 5 | import 'package:cw_core/utils/print_verbose.dart'; |
| 6 | |
| 7 | class BuyItem { |
| 8 | BuyItem({required this.provider, required this.buyAmountViewModel}); |
| 9 | |
| 10 | final BuyProvider provider; |
| 11 | final BuyAmountViewModel buyAmountViewModel; |
| 12 | |
| 13 | double get amount => buyAmountViewModel.doubleAmount; |
| 14 | |
| 15 | FiatCurrency get fiatCurrency => buyAmountViewModel.fiatCurrency; |
| 16 | |
| 17 | Future<BuyAmount> get buyAmount async { |
| 18 | BuyAmount _buyAmount; |
| 19 | |
| 20 | try { |
| 21 | _buyAmount = await provider.calculateAmount(amount?.toString() ?? '', fiatCurrency.title); |
| 22 | } catch (e) { |
| 23 | _buyAmount = BuyAmount(sourceAmount: 0.0, destAmount: 0.0); |
| 24 | printV(e.toString()); |
| 25 | } |
| 26 | |
| 27 | return _buyAmount; |
| 28 | } |
| 29 | } |