| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart'; |
| 3 | import 'package:cw_core/crypto_amount_format.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 6 | |
| 7 | class SwapLimitPopup extends StatelessWidget { |
| 8 | const SwapLimitPopup({super.key, required this.exchangeViewModel}); |
| 9 | |
| 10 | final ExchangeViewModel exchangeViewModel; |
| 11 | |
| 12 | static const outlineColor = Color(0xFFFFB84E); |
| 13 | static const backgroundColor = Color(0xFF8E5800); |
| 14 | |
| 15 | @override |
| 16 | Widget build(BuildContext context) { |
| 17 | return AnimatedSize( |
| 18 | duration: Duration(milliseconds: 200), |
| 19 | curve: Curves.easeInOutCubic, |
| 20 | child: Container( |
| 21 | width: double.infinity, |
| 22 | child: Observer(builder: (_) { |
| 23 | final amount = exchangeViewModel.hasDepositAmount |
| 24 | ? double.tryParse(exchangeViewModel.depositAmountCanonical) |
| 25 | : null; |
| 26 | final max = exchangeViewModel.limits.max ?? double.infinity; |
| 27 | final min = exchangeViewModel.limits.min ?? 0; |
| 28 | final tooLarge = amount != null && max != 0 && amount > max; |
| 29 | final tooSmall = amount != null && min != 0 && amount < min; |
| 30 | final show = amount != null && (tooLarge || tooSmall); |
| 31 | |
| 32 | final askText = |
| 33 | tooLarge ? S.of(context).enter_less_than : S.of(context).enter_greater_than; |
| 34 | final neededAmount = (tooLarge ? max : min).toString().withMaxDecimals(8); |
| 35 | final currency = exchangeViewModel.depositCurrency.title; |
| 36 | |
| 37 | return Padding( |
| 38 | padding: const EdgeInsets.only(top: 12.0), |
| 39 | child: AnimatedOpacity( |
| 40 | duration: Duration(milliseconds: 200), |
| 41 | curve: Curves.easeInOut, |
| 42 | opacity: show ? 1 : 0, |
| 43 | child: Container( |
| 44 | height: show ? null : 0, |
| 45 | decoration: BoxDecoration( |
| 46 | color: backgroundColor, borderRadius: BorderRadius.circular(99999)), |
| 47 | width: double.infinity, |
| 48 | child: Padding( |
| 49 | padding: const EdgeInsets.symmetric(vertical: 12.0), |
| 50 | child: Text( |
| 51 | "$askText $neededAmount $currency", |
| 52 | textAlign: TextAlign.center, |
| 53 | style: |
| 54 | TextStyle(color: outlineColor, fontWeight: FontWeight.w500, fontSize: 12), |
| 55 | ), |
| 56 | ), |
| 57 | ), |
| 58 | ), |
| 59 | ); |
| 60 | }), |
| 61 | ), |
| 62 | ); |
| 63 | } |
| 64 | } |