2020-11-10 16:58:40 +02:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
2023-08-17 12:28:31 -03:00
|
|
|
import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
|
2022-09-01 16:12:38 +02:00
|
|
|
import 'package:cake_wallet/src/widgets/check_box_picker.dart';
|
2020-09-25 18:32:44 +03:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-05-18 20:23:33 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-07-31 18:29:21 +03:00
|
|
|
import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart';
|
2020-05-18 20:23:33 +03:00
|
|
|
|
|
|
|
class PresentProviderPicker extends StatelessWidget {
|
2022-10-12 13:09:57 -04:00
|
|
|
PresentProviderPicker({required this.exchangeViewModel});
|
2020-05-18 20:23:33 +03:00
|
|
|
|
2020-07-31 18:29:21 +03:00
|
|
|
final ExchangeViewModel exchangeViewModel;
|
2020-05-18 20:23:33 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-11-10 16:58:40 +02:00
|
|
|
final arrowBottom = Image.asset(
|
|
|
|
'assets/images/arrow_bottom_purple_icon.png',
|
2020-07-31 18:29:21 +03:00
|
|
|
color: Colors.white,
|
2020-05-29 18:10:11 +03:00
|
|
|
height: 6);
|
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
return TextButton(
|
2025-02-17 23:43:45 +02:00
|
|
|
onPressed: () => presentProviderPicker(context),
|
2022-10-24 21:23:06 +02:00
|
|
|
style: ButtonStyle(
|
|
|
|
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
|
|
|
splashFactory: NoSplash.splashFactory,
|
|
|
|
foregroundColor: MaterialStateProperty.all(Colors.transparent),
|
|
|
|
overlayColor: MaterialStateProperty.all(Colors.transparent),
|
|
|
|
),
|
2020-05-18 20:23:33 +03:00
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(S.of(context).exchange,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16.0,
|
2020-07-31 18:29:21 +03:00
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: Colors.white)),
|
2020-05-18 20:23:33 +03:00
|
|
|
Observer(
|
2022-09-01 16:12:38 +02:00
|
|
|
builder: (_) => Text(
|
|
|
|
exchangeViewModel.selectedProviders.isEmpty
|
|
|
|
? S.of(context).choose_one
|
|
|
|
: exchangeViewModel.selectedProviders.length > 1
|
|
|
|
? S.of(context).automatic
|
|
|
|
: exchangeViewModel.selectedProviders.first.title,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10.0,
|
|
|
|
fontWeight: FontWeight.w500,
|
2023-08-17 12:28:31 -03:00
|
|
|
color: Theme.of(context).extension<QRCodeTheme>()!.qrCodeColor)))
|
2020-05-18 20:23:33 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(width: 5),
|
|
|
|
Padding(
|
2020-07-31 18:29:21 +03:00
|
|
|
padding: EdgeInsets.only(top: 12),
|
2020-05-18 20:23:33 +03:00
|
|
|
child: arrowBottom,
|
|
|
|
)
|
|
|
|
],
|
2020-11-10 16:58:40 +02:00
|
|
|
));
|
2020-05-18 20:23:33 +03:00
|
|
|
}
|
|
|
|
|
2025-02-17 23:43:45 +02:00
|
|
|
void presentProviderPicker(BuildContext context) async {
|
2022-09-01 16:12:38 +02:00
|
|
|
await showPopUp<void>(
|
|
|
|
builder: (BuildContext popUpContext) => CheckBoxPicker(
|
|
|
|
items: exchangeViewModel.providerList
|
|
|
|
.map((e) => CheckBoxItem(
|
|
|
|
e.title,
|
|
|
|
exchangeViewModel.selectedProviders.contains(e),
|
|
|
|
isDisabled: !exchangeViewModel.providersForCurrentPair().contains(e),
|
|
|
|
))
|
|
|
|
.toList(),
|
2020-05-18 20:23:33 +03:00
|
|
|
title: S.of(context).change_exchange_provider,
|
2022-09-01 16:12:38 +02:00
|
|
|
onChanged: (int index, bool value) {
|
|
|
|
if (!exchangeViewModel.providerList[index].isAvailable) {
|
2020-11-10 16:58:40 +02:00
|
|
|
showPopUp<void>(
|
|
|
|
builder: (BuildContext popUpContext) => AlertWithOneAction(
|
|
|
|
alertTitle: 'Error',
|
|
|
|
alertContent: 'The exchange is blocked in your region.',
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop()),
|
|
|
|
context: context);
|
|
|
|
return;
|
|
|
|
}
|
2022-09-01 16:12:38 +02:00
|
|
|
if (value) {
|
|
|
|
exchangeViewModel.addExchangeProvider(exchangeViewModel.providerList[index]);
|
|
|
|
} else {
|
|
|
|
exchangeViewModel.removeExchangeProvider(exchangeViewModel.providerList[index]);
|
|
|
|
}
|
2020-11-10 16:58:40 +02:00
|
|
|
}),
|
2020-05-18 20:23:33 +03:00
|
|
|
context: context);
|
2022-09-01 16:12:38 +02:00
|
|
|
|
|
|
|
exchangeViewModel.saveSelectedProviders();
|
2020-05-18 20:23:33 +03:00
|
|
|
}
|
2020-11-10 16:58:40 +02:00
|
|
|
}
|