| 1 | import "package:auto_size_text/auto_size_text.dart"; |
| 2 | import "package:cake_wallet/generated/i18n.dart"; |
| 3 | import "package:cake_wallet/new-ui/widgets/swap_page/provider_selector_page.dart"; |
| 4 | import "package:cake_wallet/src/widgets/cake_image_widget.dart"; |
| 5 | import "package:cake_wallet/view_model/exchange/exchange_view_model.dart"; |
| 6 | import "package:flutter/cupertino.dart"; |
| 7 | import "package:flutter/material.dart"; |
| 8 | import "package:flutter_mobx/flutter_mobx.dart"; |
| 9 | |
| 10 | class AnyPaySwapFooter extends StatelessWidget { |
| 11 | const AnyPaySwapFooter({required this.exchangeViewModel, super.key}); |
| 12 | |
| 13 | final ExchangeViewModel exchangeViewModel; |
| 14 | |
| 15 | @override |
| 16 | Widget build(BuildContext context) { |
| 17 | final colors = Theme.of(context).colorScheme; |
| 18 | final textTheme = Theme.of(context).textTheme; |
| 19 | return Observer( |
| 20 | builder: (_) { |
| 21 | if (exchangeViewModel.noProviderForPair) { |
| 22 | return Container( |
| 23 | alignment: Alignment.center, |
| 24 | height: 48, |
| 25 | padding: const EdgeInsets.symmetric(horizontal: 16), |
| 26 | decoration: BoxDecoration( |
| 27 | borderRadius: BorderRadius.circular(18), |
| 28 | border: Border.all(color: colors.error), |
| 29 | ), |
| 30 | child: Text( |
| 31 | S.of(context).no_providers_available, |
| 32 | style: textTheme.bodyMedium?.copyWith(color: colors.error, letterSpacing: -0.07), |
| 33 | ), |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | if (exchangeViewModel.depositAmount.isEmpty) { |
| 38 | return const SizedBox.shrink(); |
| 39 | } |
| 40 | |
| 41 | final provider = exchangeViewModel.forcedProvider ?? exchangeViewModel.providerDisplay; |
| 42 | final depositAmount = exchangeViewModel.depositAmount; |
| 43 | final depositSymbol = |
| 44 | exchangeViewModel.amountParsingProxy.getCryptoSymbol(exchangeViewModel.depositCurrency); |
| 45 | final depositFiat = exchangeViewModel.roundedDepositAmountFiat(2); |
| 46 | final showFiat = !exchangeViewModel.isFiatDisabled && depositFiat.isNotEmpty; |
| 47 | return Row( |
| 48 | children: [ |
| 49 | Expanded( |
| 50 | child: Container( |
| 51 | alignment: Alignment.center, |
| 52 | height: 48, |
| 53 | padding: const EdgeInsets.symmetric(horizontal: 16), |
| 54 | decoration: BoxDecoration( |
| 55 | borderRadius: BorderRadius.circular(18), |
| 56 | border: Border.all(color: colors.primary), |
| 57 | ), |
| 58 | child: AutoSizeText.rich( |
| 59 | TextSpan( |
| 60 | children: [ |
| 61 | TextSpan(text: "$depositAmount $depositSymbol"), |
| 62 | if (showFiat) |
| 63 | TextSpan( |
| 64 | text: " ≈ ${exchangeViewModel.fiat.symbol}$depositFiat", |
| 65 | style: TextStyle(color: colors.onSurfaceVariant), |
| 66 | ), |
| 67 | ], |
| 68 | ), |
| 69 | maxLines: 1, |
| 70 | minFontSize: 10, |
| 71 | style: textTheme.bodySmall |
| 72 | ?.copyWith(fontWeight: FontWeight.w500, letterSpacing: -0.06), |
| 73 | ), |
| 74 | ), |
| 75 | ), |
| 76 | const SizedBox(width: 12), |
| 77 | GestureDetector( |
| 78 | onTap: provider == null |
| 79 | ? null |
| 80 | : () => Navigator.of(context).push( |
| 81 | CupertinoPageRoute<void>( |
| 82 | builder: (context) => Material( |
| 83 | child: ProviderSelectorPage(exchangeViewModel: exchangeViewModel), |
| 84 | ), |
| 85 | ), |
| 86 | ), |
| 87 | child: Container( |
| 88 | height: 48, |
| 89 | padding: const EdgeInsets.symmetric(horizontal: 12), |
| 90 | decoration: BoxDecoration( |
| 91 | color: colors.surfaceContainer, |
| 92 | borderRadius: BorderRadius.circular(24), |
| 93 | ), |
| 94 | child: Row( |
| 95 | mainAxisSize: MainAxisSize.min, |
| 96 | children: [ |
| 97 | if (provider != null) |
| 98 | CakeImageWidget(imageUrl: provider.description.image, width: 24, height: 24) |
| 99 | else |
| 100 | const CupertinoActivityIndicator(), |
| 101 | const SizedBox(width: 8), |
| 102 | Text( |
| 103 | provider?.title ?? "${S.of(context).finding_provider}...", |
| 104 | style: textTheme.bodyMedium?.copyWith(letterSpacing: -0.07), |
| 105 | ), |
| 106 | const SizedBox(width: 8), |
| 107 | CakeImageWidget( |
| 108 | imageUrl: "assets/new-ui/chooser.svg", |
| 109 | width: 12, |
| 110 | height: 12, |
| 111 | colorFilter: ColorFilter.mode(colors.onSurfaceVariant, BlendMode.srcIn), |
| 112 | ), |
| 113 | ], |
| 114 | ), |
| 115 | ), |
| 116 | ), |
| 117 | ], |
| 118 | ); |
| 119 | }, |
| 120 | ); |
| 121 | } |
| 122 | } |