2023-08-17 15:28:31 +00:00
|
|
|
import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart';
|
|
|
|
import 'package:cake_wallet/themes/extensions/keyboard_theme.dart';
|
2023-08-04 13:49:26 +00:00
|
|
|
import 'package:cake_wallet/core/auth_service.dart';
|
2022-03-15 09:11:53 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
2023-04-14 04:39:08 +00:00
|
|
|
import 'package:cake_wallet/src/screens/exchange/widgets/desktop_exchange_cards_section.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/exchange/widgets/mobile_exchange_cards_section.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/add_template_button.dart';
|
2023-08-22 18:49:37 +00:00
|
|
|
import 'package:cake_wallet/themes/extensions/send_page_theme.dart';
|
2023-04-26 12:59:27 +00:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
2022-01-26 15:44:15 +00:00
|
|
|
import 'package:cake_wallet/utils/debounce.dart';
|
2023-04-14 04:39:08 +00:00
|
|
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/sync_status.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2021-07-07 13:50:55 +00:00
|
|
|
import 'package:cake_wallet/entities/parse_address_from_domain.dart';
|
2021-09-29 11:38:31 +00:00
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/extract_address_from_parsed.dart';
|
2021-02-16 19:06:23 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
|
2020-10-24 12:55:24 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:keyboard_actions/keyboard_actions.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/exchange/exchange_template.dart';
|
2020-10-24 12:55:24 +00:00
|
|
|
import 'package:cake_wallet/exchange/exchange_trade_state.dart';
|
|
|
|
import 'package:cake_wallet/exchange/limits_state.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
2020-09-22 18:32:43 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
2020-09-29 17:56:11 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
2020-09-22 18:32:43 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/template_tile.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/trail_button.dart';
|
2020-09-25 15:32:44 +00:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/routes.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/src/screens/exchange/widgets/exchange_card.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
|
|
|
import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart';
|
|
|
|
import 'package:cake_wallet/core/address_validator.dart';
|
|
|
|
import 'package:cake_wallet/core/amount_validator.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/exchange/widgets/present_provider_picker.dart';
|
2022-02-21 14:30:48 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class ExchangePage extends BasePage {
|
2023-08-04 13:49:26 +00:00
|
|
|
ExchangePage(this.exchangeViewModel, this.authService) {
|
2023-04-14 04:39:08 +00:00
|
|
|
depositWalletName = exchangeViewModel.depositCurrency == CryptoCurrency.xmr
|
|
|
|
? exchangeViewModel.wallet.name
|
|
|
|
: null;
|
|
|
|
receiveWalletName = exchangeViewModel.receiveCurrency == CryptoCurrency.xmr
|
|
|
|
? exchangeViewModel.wallet.name
|
|
|
|
: null;
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-07-31 15:29:21 +00:00
|
|
|
final ExchangeViewModel exchangeViewModel;
|
2023-08-04 13:49:26 +00:00
|
|
|
final AuthService authService;
|
2020-09-22 18:32:43 +00:00
|
|
|
final depositKey = GlobalKey<ExchangeCardState>();
|
|
|
|
final receiveKey = GlobalKey<ExchangeCardState>();
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
2020-09-29 17:56:11 +00:00
|
|
|
final _depositAmountFocus = FocusNode();
|
2021-04-20 17:49:53 +00:00
|
|
|
final _depositAddressFocus = FocusNode();
|
2020-09-29 17:56:11 +00:00
|
|
|
final _receiveAmountFocus = FocusNode();
|
2021-04-20 17:49:53 +00:00
|
|
|
final _receiveAddressFocus = FocusNode();
|
2022-01-26 15:44:15 +00:00
|
|
|
final _receiveAmountDebounce = Debounce(Duration(milliseconds: 500));
|
|
|
|
final _depositAmountDebounce = Debounce(Duration(milliseconds: 500));
|
2020-09-22 18:32:43 +00:00
|
|
|
var _isReactionsSet = false;
|
2020-05-29 15:10:11 +00:00
|
|
|
|
2023-04-14 04:39:08 +00:00
|
|
|
final arrowBottomPurple = Image.asset(
|
|
|
|
'assets/images/arrow_bottom_purple_icon.png',
|
|
|
|
color: Colors.white,
|
|
|
|
height: 8,
|
|
|
|
);
|
|
|
|
final arrowBottomCakeGreen = Image.asset(
|
|
|
|
'assets/images/arrow_bottom_cake_green.png',
|
|
|
|
color: Colors.white,
|
|
|
|
height: 8,
|
|
|
|
);
|
|
|
|
|
|
|
|
late final String? depositWalletName;
|
|
|
|
late final String? receiveWalletName;
|
|
|
|
|
2020-05-29 15:10:11 +00:00
|
|
|
@override
|
2020-07-31 15:29:21 +00:00
|
|
|
String get title => S.current.exchange;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
2023-08-17 15:28:31 +00:00
|
|
|
bool get gradientBackground => true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool get gradientAll => true;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
2021-05-10 17:58:05 +00:00
|
|
|
bool get resizeToAvoidBottomInset => false;
|
2020-08-21 20:26:23 +00:00
|
|
|
|
|
|
|
@override
|
2020-09-22 18:32:43 +00:00
|
|
|
bool get extendBodyBehindAppBar => true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
2022-02-21 14:30:48 +00:00
|
|
|
Widget middle(BuildContext context) => Row(
|
2023-08-04 13:49:26 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 6.0),
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) =>
|
|
|
|
SyncIndicatorIcon(isSynced: exchangeViewModel.status is SyncedSyncStatus),
|
|
|
|
)),
|
|
|
|
PresentProviderPicker(exchangeViewModel: exchangeViewModel)
|
|
|
|
],
|
|
|
|
);
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
2020-09-29 17:56:11 +00:00
|
|
|
Widget trailing(BuildContext context) => TrailButton(
|
2021-01-05 18:31:03 +00:00
|
|
|
caption: S.of(context).reset,
|
|
|
|
onPressed: () {
|
2022-10-12 17:09:57 +00:00
|
|
|
_formKey.currentState?.reset();
|
2020-10-30 12:42:23 +00:00
|
|
|
exchangeViewModel.reset();
|
2021-01-05 18:31:03 +00:00
|
|
|
});
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
2023-04-26 12:59:27 +00:00
|
|
|
Widget? leading(BuildContext context) {
|
2023-08-04 13:49:26 +00:00
|
|
|
final _backButton = Icon(
|
|
|
|
Icons.arrow_back_ios,
|
2023-08-17 15:28:31 +00:00
|
|
|
color: titleColor(context),
|
2023-04-26 12:59:27 +00:00
|
|
|
size: 16,
|
|
|
|
);
|
2023-08-04 13:49:26 +00:00
|
|
|
final _closeButton =
|
|
|
|
currentTheme.type == ThemeType.dark ? closeButtonImageDarkTheme : closeButtonImage;
|
2023-04-26 12:59:27 +00:00
|
|
|
|
2023-06-13 23:04:52 +00:00
|
|
|
bool isMobileView = ResponsiveLayoutUtil.instance.isMobile;
|
2023-04-26 12:59:27 +00:00
|
|
|
|
|
|
|
return MergeSemantics(
|
|
|
|
child: SizedBox(
|
|
|
|
height: isMobileView ? 37 : 45,
|
|
|
|
width: isMobileView ? 37 : 45,
|
|
|
|
child: ButtonTheme(
|
|
|
|
minWidth: double.minPositive,
|
|
|
|
child: Semantics(
|
2023-08-04 13:49:26 +00:00
|
|
|
label: !isMobileView ? S.of(context).close : S.of(context).seed_alert_back,
|
2023-04-26 12:59:27 +00:00
|
|
|
child: TextButton(
|
|
|
|
style: ButtonStyle(
|
2023-08-04 13:49:26 +00:00
|
|
|
overlayColor: MaterialStateColor.resolveWith((states) => Colors.transparent),
|
2023-04-26 12:59:27 +00:00
|
|
|
),
|
|
|
|
onPressed: () => onClose(context),
|
|
|
|
child: !isMobileView ? _closeButton : _backButton,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2023-04-14 04:39:08 +00:00
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
2023-08-04 13:49:26 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _setReactions(context, exchangeViewModel));
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2020-09-29 17:56:11 +00:00
|
|
|
return KeyboardActions(
|
2022-01-26 15:44:15 +00:00
|
|
|
disableScroll: true,
|
2020-09-29 17:56:11 +00:00
|
|
|
config: KeyboardActionsConfig(
|
|
|
|
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
|
2023-08-17 15:28:31 +00:00
|
|
|
keyboardBarColor: Theme.of(context).extension<KeyboardTheme>()!.keyboardBarColor,
|
2020-09-29 17:56:11 +00:00
|
|
|
nextFocus: false,
|
|
|
|
actions: [
|
|
|
|
KeyboardActionsItem(
|
2023-08-04 13:49:26 +00:00
|
|
|
focusNode: _depositAmountFocus, toolbarButtons: [(_) => KeyboardDoneButton()]),
|
2020-09-29 17:56:11 +00:00
|
|
|
KeyboardActionsItem(
|
2023-08-04 13:49:26 +00:00
|
|
|
focusNode: _receiveAmountFocus, toolbarButtons: [(_) => KeyboardDoneButton()])
|
2020-09-29 17:56:11 +00:00
|
|
|
]),
|
|
|
|
child: Container(
|
2023-05-24 23:19:51 +00:00
|
|
|
color: Theme.of(context).colorScheme.background,
|
2020-09-29 17:56:11 +00:00
|
|
|
child: Form(
|
|
|
|
key: _formKey,
|
|
|
|
child: ScrollableWithBottomSection(
|
|
|
|
contentPadding: EdgeInsets.only(bottom: 24),
|
2023-08-04 13:49:26 +00:00
|
|
|
content: Observer(
|
|
|
|
builder: (_) => Column(
|
|
|
|
children: <Widget>[
|
|
|
|
_exchangeCardsSection(context),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 12, left: 24),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
StandardCheckbox(
|
|
|
|
value: exchangeViewModel.isFixedRateMode,
|
|
|
|
caption: S.of(context).fixed_rate,
|
|
|
|
onChanged: (value) => exchangeViewModel.isFixedRateMode = value,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
SizedBox(height: 30),
|
|
|
|
_buildTemplateSection(context)
|
2022-01-31 13:17:31 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-08-04 13:49:26 +00:00
|
|
|
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
2020-09-29 17:56:11 +00:00
|
|
|
bottomSection: Column(children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 15),
|
|
|
|
child: Observer(builder: (_) {
|
2021-02-24 08:16:03 +00:00
|
|
|
final description = exchangeViewModel.isFixedRateMode
|
2022-09-01 14:12:38 +00:00
|
|
|
? exchangeViewModel.isAvailableInSelected
|
2020-10-30 17:28:20 +00:00
|
|
|
? S.of(context).amount_is_guaranteed
|
2022-09-01 14:12:38 +00:00
|
|
|
: S.of(context).fixed_pair_not_supported
|
|
|
|
: exchangeViewModel.isAvailableInSelected
|
|
|
|
? S.of(context).amount_is_estimate
|
|
|
|
: S.of(context).variable_pair_not_supported;
|
2020-09-29 17:56:11 +00:00
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
description,
|
2020-10-30 17:28:20 +00:00
|
|
|
textAlign: TextAlign.center,
|
2020-09-29 17:56:11 +00:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context)
|
2023-08-17 15:28:31 +00:00
|
|
|
.extension<ExchangePageTheme>()!
|
|
|
|
.receiveAmountColor,
|
2020-09-29 17:56:11 +00:00
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
fontSize: 12),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
2020-09-22 18:32:43 +00:00
|
|
|
),
|
2020-09-29 17:56:11 +00:00
|
|
|
Observer(
|
2021-01-05 18:31:03 +00:00
|
|
|
builder: (_) => LoadingPrimaryButton(
|
|
|
|
text: S.of(context).exchange,
|
|
|
|
onPressed: () {
|
2023-08-04 13:49:26 +00:00
|
|
|
if (_formKey.currentState != null &&
|
|
|
|
_formKey.currentState!.validate()) {
|
|
|
|
if ((exchangeViewModel.depositCurrency == CryptoCurrency.xmr) &&
|
|
|
|
(!(exchangeViewModel.status is SyncedSyncStatus))) {
|
2021-01-05 18:31:03 +00:00
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).exchange,
|
2023-08-04 13:49:26 +00:00
|
|
|
alertContent: S.of(context).exchange_sync_alert_content,
|
2021-01-05 18:31:03 +00:00
|
|
|
buttonText: S.of(context).ok,
|
2023-08-04 13:49:26 +00:00
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
2021-01-05 18:31:03 +00:00
|
|
|
});
|
|
|
|
} else {
|
2023-08-04 13:49:26 +00:00
|
|
|
final check = exchangeViewModel.shouldDisplayTOTP();
|
|
|
|
authService.authenticateAction(
|
|
|
|
context,
|
|
|
|
conditionToDetermineIfToUse2FA: check,
|
|
|
|
onAuthSuccess: (value) {
|
|
|
|
if (value) {
|
|
|
|
exchangeViewModel.createTrade();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-01-05 18:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-08-18 15:37:17 +00:00
|
|
|
color: Theme.of(context).primaryColor,
|
2021-01-05 18:31:03 +00:00
|
|
|
textColor: Colors.white,
|
2022-09-01 14:12:38 +00:00
|
|
|
isDisabled: exchangeViewModel.selectedProviders.isEmpty,
|
|
|
|
isLoading: exchangeViewModel.tradeState is TradeIsCreating)),
|
2020-09-29 17:56:11 +00:00
|
|
|
]),
|
|
|
|
)),
|
|
|
|
));
|
2020-08-21 20:26:23 +00:00
|
|
|
}
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2022-01-31 13:17:31 +00:00
|
|
|
Widget _buildTemplateSection(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
height: 40,
|
|
|
|
width: double.infinity,
|
|
|
|
padding: EdgeInsets.only(left: 24),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) {
|
|
|
|
final templates = exchangeViewModel.templates;
|
2023-08-04 13:49:26 +00:00
|
|
|
|
2022-01-31 13:17:31 +00:00
|
|
|
return Row(
|
|
|
|
children: <Widget>[
|
2023-04-14 04:39:08 +00:00
|
|
|
AddTemplateButton(
|
|
|
|
onTap: () => Navigator.of(context).pushNamed(Routes.exchangeTemplate),
|
|
|
|
currentTemplatesLength: templates.length,
|
2022-01-31 13:17:31 +00:00
|
|
|
),
|
|
|
|
ListView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: NeverScrollableScrollPhysics(),
|
2022-01-31 14:44:08 +00:00
|
|
|
itemCount: templates.length,
|
2022-01-31 13:17:31 +00:00
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final template = templates[index];
|
|
|
|
|
|
|
|
return TemplateTile(
|
|
|
|
key: UniqueKey(),
|
|
|
|
amount: template.amount,
|
2023-05-03 07:01:51 +00:00
|
|
|
from: template.depositCurrencyTitle,
|
|
|
|
to: template.receiveCurrencyTitle,
|
2022-01-31 13:17:31 +00:00
|
|
|
onTap: () {
|
|
|
|
applyTemplate(context, exchangeViewModel, template);
|
|
|
|
},
|
|
|
|
onRemove: () {
|
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (dialogContext) {
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
alertTitle: S.of(context).template,
|
2023-08-04 13:49:26 +00:00
|
|
|
alertContent: S.of(context).confirm_delete_template,
|
2022-01-31 13:17:31 +00:00
|
|
|
rightButtonText: S.of(context).delete,
|
|
|
|
leftButtonText: S.of(context).cancel,
|
|
|
|
actionRightButton: () {
|
|
|
|
Navigator.of(dialogContext).pop();
|
2023-08-04 13:49:26 +00:00
|
|
|
exchangeViewModel.removeTemplate(template: template);
|
2022-01-31 13:17:31 +00:00
|
|
|
exchangeViewModel.updateTemplate();
|
|
|
|
},
|
2023-08-04 13:49:26 +00:00
|
|
|
actionLeftButton: () => Navigator.of(dialogContext).pop());
|
2022-01-31 13:17:31 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
void applyTemplate(
|
|
|
|
BuildContext context, ExchangeViewModel exchangeViewModel, ExchangeTemplate template) async {
|
2020-09-22 18:32:43 +00:00
|
|
|
exchangeViewModel.changeDepositCurrency(
|
|
|
|
currency: CryptoCurrency.fromString(template.depositCurrency));
|
|
|
|
exchangeViewModel.changeReceiveCurrency(
|
|
|
|
currency: CryptoCurrency.fromString(template.receiveCurrency));
|
|
|
|
|
|
|
|
exchangeViewModel.changeDepositAmount(amount: template.amount);
|
|
|
|
exchangeViewModel.depositAddress = template.depositAddress;
|
|
|
|
exchangeViewModel.receiveAddress = template.receiveAddress;
|
2020-10-12 16:47:01 +00:00
|
|
|
exchangeViewModel.isReceiveAmountEntered = false;
|
2021-02-19 08:37:30 +00:00
|
|
|
exchangeViewModel.isFixedRateMode = false;
|
2021-04-20 17:49:53 +00:00
|
|
|
|
|
|
|
var domain = template.depositAddress;
|
2021-06-22 08:29:30 +00:00
|
|
|
var ticker = template.depositCurrency.toLowerCase();
|
2023-08-04 13:49:26 +00:00
|
|
|
exchangeViewModel.depositAddress = await fetchParsedAddress(context, domain, ticker);
|
2021-04-20 17:49:53 +00:00
|
|
|
|
|
|
|
domain = template.receiveAddress;
|
2021-06-22 08:29:30 +00:00
|
|
|
ticker = template.receiveCurrency.toLowerCase();
|
2023-08-04 13:49:26 +00:00
|
|
|
exchangeViewModel.receiveAddress = await fetchParsedAddress(context, domain, ticker);
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
void _setReactions(BuildContext context, ExchangeViewModel exchangeViewModel) {
|
2020-09-22 18:32:43 +00:00
|
|
|
if (_isReactionsSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
if (exchangeViewModel.isLowFee) {
|
2023-04-21 18:03:42 +00:00
|
|
|
_showFeeAlert(context);
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
final depositAddressController = depositKey.currentState!.addressController;
|
|
|
|
final depositAmountController = depositKey.currentState!.amountController;
|
|
|
|
final receiveAddressController = receiveKey.currentState!.addressController;
|
|
|
|
final receiveAmountController = receiveKey.currentState!.amountController;
|
2020-09-22 18:32:43 +00:00
|
|
|
final limitsState = exchangeViewModel.limitsState;
|
|
|
|
|
2020-10-24 12:55:24 +00:00
|
|
|
if (limitsState is LimitsLoadedSuccessfully) {
|
2023-08-04 13:49:26 +00:00
|
|
|
final min = limitsState.limits.min != null ? limitsState.limits.min.toString() : null;
|
|
|
|
final max = limitsState.limits.max != null ? limitsState.limits.max.toString() : null;
|
|
|
|
final key = exchangeViewModel.isFixedRateMode ? receiveKey : depositKey;
|
2022-10-12 17:09:57 +00:00
|
|
|
key.currentState!.changeLimits(min: min, max: max);
|
2020-10-24 12:55:24 +00:00
|
|
|
}
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
_onCurrencyChange(exchangeViewModel.receiveCurrency, exchangeViewModel, receiveKey);
|
|
|
|
_onCurrencyChange(exchangeViewModel.depositCurrency, exchangeViewModel, depositKey);
|
2020-09-22 18:32:43 +00:00
|
|
|
|
|
|
|
reaction(
|
2020-09-29 17:56:11 +00:00
|
|
|
(_) => exchangeViewModel.wallet.name,
|
2023-08-04 13:49:26 +00:00
|
|
|
(String _) =>
|
|
|
|
_onWalletNameChange(exchangeViewModel, exchangeViewModel.receiveCurrency, receiveKey));
|
2020-09-22 18:32:43 +00:00
|
|
|
|
|
|
|
reaction(
|
2020-09-29 17:56:11 +00:00
|
|
|
(_) => exchangeViewModel.wallet.name,
|
2023-08-04 13:49:26 +00:00
|
|
|
(String _) =>
|
|
|
|
_onWalletNameChange(exchangeViewModel, exchangeViewModel.depositCurrency, depositKey));
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
reaction((_) => exchangeViewModel.receiveCurrency,
|
|
|
|
(CryptoCurrency currency) => _onCurrencyChange(currency, exchangeViewModel, receiveKey));
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
reaction((_) => exchangeViewModel.depositCurrency,
|
|
|
|
(CryptoCurrency currency) => _onCurrencyChange(currency, exchangeViewModel, depositKey));
|
2020-09-22 18:32:43 +00:00
|
|
|
|
|
|
|
reaction((_) => exchangeViewModel.depositAmount, (String amount) {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (depositKey.currentState!.amountController.text != amount) {
|
|
|
|
depositKey.currentState!.amountController.text = amount;
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
reaction((_) => exchangeViewModel.depositAddress, (String address) {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (depositKey.currentState!.addressController.text != address) {
|
|
|
|
depositKey.currentState!.addressController.text = address;
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
reaction((_) => exchangeViewModel.isDepositAddressEnabled, (bool isEnabled) {
|
2022-10-12 17:09:57 +00:00
|
|
|
depositKey.currentState!.isAddressEditable(isEditable: isEnabled);
|
2020-09-29 17:56:11 +00:00
|
|
|
});
|
2020-09-22 18:32:43 +00:00
|
|
|
|
|
|
|
reaction((_) => exchangeViewModel.receiveAmount, (String amount) {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (receiveKey.currentState!.amountController.text != amount) {
|
|
|
|
receiveKey.currentState!.amountController.text = amount;
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
reaction((_) => exchangeViewModel.receiveAddress, (String address) {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (receiveKey.currentState!.addressController.text != address) {
|
|
|
|
receiveKey.currentState!.addressController.text = address;
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
reaction((_) => exchangeViewModel.isReceiveAddressEnabled, (bool isEnabled) {
|
2022-10-12 17:09:57 +00:00
|
|
|
receiveKey.currentState!.isAddressEditable(isEditable: isEnabled);
|
2020-09-29 17:56:11 +00:00
|
|
|
});
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
reaction((_) => exchangeViewModel.isReceiveAmountEditable, (bool isReceiveAmountEditable) {
|
2022-10-12 17:09:57 +00:00
|
|
|
receiveKey.currentState!.isAmountEditable(isEditable: isReceiveAmountEditable);
|
2020-09-25 19:55:41 +00:00
|
|
|
});
|
|
|
|
|
2020-10-24 12:55:24 +00:00
|
|
|
reaction((_) => exchangeViewModel.tradeState, (ExchangeTradeState state) {
|
|
|
|
if (state is TradeIsCreatedFailure) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
2020-12-03 13:47:13 +00:00
|
|
|
alertTitle: S.of(context).provider_error(state.title),
|
2020-10-24 12:55:24 +00:00
|
|
|
alertContent: state.error,
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (state is TradeIsCreatedSuccessfully) {
|
2020-11-19 16:48:09 +00:00
|
|
|
exchangeViewModel.reset();
|
2020-10-24 12:55:24 +00:00
|
|
|
Navigator.of(context).pushNamed(Routes.exchangeConfirm);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
reaction((_) => exchangeViewModel.limitsState, (LimitsState state) {
|
2022-10-12 17:09:57 +00:00
|
|
|
String? min;
|
|
|
|
String? max;
|
2020-10-24 12:55:24 +00:00
|
|
|
|
|
|
|
if (state is LimitsLoadedSuccessfully) {
|
|
|
|
min = state.limits.min != null ? state.limits.min.toString() : null;
|
|
|
|
max = state.limits.max != null ? state.limits.max.toString() : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state is LimitsLoadedFailure) {
|
|
|
|
min = '0';
|
|
|
|
max = '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state is LimitsIsLoading) {
|
|
|
|
min = '...';
|
|
|
|
max = '...';
|
|
|
|
}
|
|
|
|
|
2022-01-26 15:44:15 +00:00
|
|
|
if (exchangeViewModel.isFixedRateMode) {
|
2022-10-12 17:09:57 +00:00
|
|
|
depositKey.currentState!.changeLimits(min: null, max: null);
|
|
|
|
receiveKey.currentState!.changeLimits(min: min, max: max);
|
2022-01-26 15:44:15 +00:00
|
|
|
} else {
|
2022-10-12 17:09:57 +00:00
|
|
|
depositKey.currentState!.changeLimits(min: min, max: max);
|
|
|
|
receiveKey.currentState!.changeLimits(min: null, max: null);
|
2022-01-26 15:44:15 +00:00
|
|
|
}
|
2020-10-24 12:55:24 +00:00
|
|
|
});
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
depositAddressController
|
|
|
|
.addListener(() => exchangeViewModel.depositAddress = depositAddressController.text);
|
2020-09-22 18:32:43 +00:00
|
|
|
|
|
|
|
depositAmountController.addListener(() {
|
|
|
|
if (depositAmountController.text != exchangeViewModel.depositAmount) {
|
2023-08-04 13:49:26 +00:00
|
|
|
_depositAmountDebounce.run(() {
|
2023-04-20 01:13:37 +00:00
|
|
|
exchangeViewModel.changeDepositAmount(amount: depositAmountController.text);
|
2022-01-26 15:44:15 +00:00
|
|
|
exchangeViewModel.isReceiveAmountEntered = false;
|
|
|
|
});
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
receiveAddressController
|
|
|
|
.addListener(() => exchangeViewModel.receiveAddress = receiveAddressController.text);
|
2020-09-22 18:32:43 +00:00
|
|
|
|
|
|
|
receiveAmountController.addListener(() {
|
|
|
|
if (receiveAmountController.text != exchangeViewModel.receiveAmount) {
|
2022-01-26 15:44:15 +00:00
|
|
|
_receiveAmountDebounce.run(() {
|
2023-04-20 01:13:37 +00:00
|
|
|
exchangeViewModel.changeReceiveAmount(amount: receiveAmountController.text);
|
2022-01-26 15:44:15 +00:00
|
|
|
exchangeViewModel.isReceiveAmountEntered = true;
|
|
|
|
});
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
reaction((_) => exchangeViewModel.wallet.walletAddresses.address, (String address) {
|
2020-09-22 18:32:43 +00:00
|
|
|
if (exchangeViewModel.depositCurrency == CryptoCurrency.xmr) {
|
2022-10-12 17:09:57 +00:00
|
|
|
depositKey.currentState!.changeAddress(address: address);
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (exchangeViewModel.receiveCurrency == CryptoCurrency.xmr) {
|
2022-10-12 17:09:57 +00:00
|
|
|
receiveKey.currentState!.changeAddress(address: address);
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-20 17:49:53 +00:00
|
|
|
_depositAddressFocus.addListener(() async {
|
2023-08-04 13:49:26 +00:00
|
|
|
if (!_depositAddressFocus.hasFocus && depositAddressController.text.isNotEmpty) {
|
2021-04-20 17:49:53 +00:00
|
|
|
final domain = depositAddressController.text;
|
2021-06-22 08:29:30 +00:00
|
|
|
final ticker = exchangeViewModel.depositCurrency.title.toLowerCase();
|
2023-08-04 13:49:26 +00:00
|
|
|
exchangeViewModel.depositAddress = await fetchParsedAddress(context, domain, ticker);
|
2021-04-20 17:49:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_receiveAddressFocus.addListener(() async {
|
2023-08-04 13:49:26 +00:00
|
|
|
if (!_receiveAddressFocus.hasFocus && receiveAddressController.text.isNotEmpty) {
|
2021-04-20 17:49:53 +00:00
|
|
|
final domain = receiveAddressController.text;
|
2021-06-22 08:29:30 +00:00
|
|
|
final ticker = exchangeViewModel.receiveCurrency.title.toLowerCase();
|
2023-08-04 13:49:26 +00:00
|
|
|
exchangeViewModel.receiveAddress = await fetchParsedAddress(context, domain, ticker);
|
2021-04-20 17:49:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-16 19:06:23 +00:00
|
|
|
_receiveAmountFocus.addListener(() {
|
2022-09-01 14:12:38 +00:00
|
|
|
if (_receiveAmountFocus.hasFocus) {
|
|
|
|
exchangeViewModel.isFixedRateMode = true;
|
|
|
|
}
|
2022-10-20 17:47:36 +00:00
|
|
|
// exchangeViewModel.changeReceiveAmount(amount: receiveAmountController.text);
|
2021-02-16 19:06:23 +00:00
|
|
|
});
|
|
|
|
|
2022-01-27 09:20:51 +00:00
|
|
|
_depositAmountFocus.addListener(() {
|
|
|
|
exchangeViewModel.isFixedRateMode = false;
|
2022-10-20 17:47:36 +00:00
|
|
|
// exchangeViewModel.changeDepositAmount(
|
|
|
|
// amount: depositAmountController.text);
|
2021-02-16 19:06:23 +00:00
|
|
|
});
|
|
|
|
|
2020-09-22 18:32:43 +00:00
|
|
|
_isReactionsSet = true;
|
|
|
|
}
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
void _onCurrencyChange(CryptoCurrency currency, ExchangeViewModel exchangeViewModel,
|
|
|
|
GlobalKey<ExchangeCardState> key) {
|
2020-09-22 18:32:43 +00:00
|
|
|
final isCurrentTypeWallet = currency == exchangeViewModel.wallet.currency;
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
key.currentState!.changeSelectedCurrency(currency);
|
2023-08-04 13:49:26 +00:00
|
|
|
key.currentState!.changeWalletName(isCurrentTypeWallet ? exchangeViewModel.wallet.name : '');
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
key.currentState!.changeAddress(
|
2023-08-04 13:49:26 +00:00
|
|
|
address: isCurrentTypeWallet ? exchangeViewModel.wallet.walletAddresses.address : '');
|
2020-09-22 18:32:43 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
key.currentState!.changeAmount(amount: '');
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
void _onWalletNameChange(ExchangeViewModel exchangeViewModel, CryptoCurrency currency,
|
|
|
|
GlobalKey<ExchangeCardState> key) {
|
2020-09-22 18:32:43 +00:00
|
|
|
final isCurrentTypeWallet = currency == exchangeViewModel.wallet.currency;
|
|
|
|
|
|
|
|
if (isCurrentTypeWallet) {
|
2022-10-12 17:09:57 +00:00
|
|
|
key.currentState!.changeWalletName(exchangeViewModel.wallet.name);
|
2023-08-04 13:49:26 +00:00
|
|
|
key.currentState!.addressController.text = exchangeViewModel.wallet.walletAddresses.address;
|
2022-10-12 17:09:57 +00:00
|
|
|
} else if (key.currentState!.addressController.text ==
|
2021-07-13 05:46:34 +00:00
|
|
|
exchangeViewModel.wallet.walletAddresses.address) {
|
2022-10-12 17:09:57 +00:00
|
|
|
key.currentState!.changeWalletName('');
|
|
|
|
key.currentState!.addressController.text = '';
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-07 14:31:16 +00:00
|
|
|
|
2023-08-04 13:49:26 +00:00
|
|
|
Future<String> fetchParsedAddress(BuildContext context, String domain, String ticker) async {
|
2022-03-15 09:11:53 +00:00
|
|
|
final parsedAddress = await getIt.get<AddressResolver>().resolve(domain, ticker);
|
2021-09-29 11:38:31 +00:00
|
|
|
final address = await extractAddressFromParsed(context, parsedAddress);
|
2021-09-20 14:56:27 +00:00
|
|
|
return address;
|
2021-07-07 14:31:16 +00:00
|
|
|
}
|
2022-10-20 17:47:36 +00:00
|
|
|
|
2022-11-03 19:21:35 +00:00
|
|
|
void _showFeeAlert(BuildContext context) async {
|
|
|
|
await Future<void>.delayed(Duration(seconds: 1));
|
|
|
|
final confirmed = await showPopUp<bool>(
|
2023-08-04 13:49:26 +00:00
|
|
|
context: context,
|
|
|
|
builder: (dialogContext) {
|
|
|
|
return AlertWithTwoActions(
|
|
|
|
alertTitle: S.of(context).low_fee,
|
|
|
|
alertContent: S.of(context).low_fee_alert,
|
|
|
|
leftButtonText: S.of(context).ignor,
|
|
|
|
rightButtonText: S.of(context).use_suggested,
|
|
|
|
actionLeftButton: () => Navigator.of(dialogContext).pop(false),
|
|
|
|
actionRightButton: () => Navigator.of(dialogContext).pop(true));
|
|
|
|
}) ??
|
|
|
|
false;
|
2022-11-03 19:21:35 +00:00
|
|
|
if (confirmed) {
|
|
|
|
exchangeViewModel.setDefaultTransactionPriority();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-14 04:39:08 +00:00
|
|
|
void disposeBestRateSync() => exchangeViewModel.bestRateSync.cancel();
|
|
|
|
|
|
|
|
Widget _exchangeCardsSection(BuildContext context) {
|
2023-08-04 13:49:26 +00:00
|
|
|
final firstExchangeCard = Observer(
|
|
|
|
builder: (_) => ExchangeCard(
|
|
|
|
onDispose: disposeBestRateSync,
|
|
|
|
hasAllAmount: exchangeViewModel.hasAllAmount,
|
|
|
|
allAmount: exchangeViewModel.hasAllAmount
|
|
|
|
? () => exchangeViewModel.calculateDepositAllAmount()
|
|
|
|
: null,
|
|
|
|
amountFocusNode: _depositAmountFocus,
|
|
|
|
addressFocusNode: _depositAddressFocus,
|
|
|
|
key: depositKey,
|
|
|
|
title: S.of(context).you_will_send,
|
|
|
|
initialCurrency: exchangeViewModel.depositCurrency,
|
|
|
|
initialWalletName: depositWalletName ?? '',
|
|
|
|
initialAddress: exchangeViewModel.depositCurrency == exchangeViewModel.wallet.currency
|
|
|
|
? exchangeViewModel.wallet.walletAddresses.address
|
|
|
|
: exchangeViewModel.depositAddress,
|
|
|
|
initialIsAmountEditable: true,
|
|
|
|
initialIsAddressEditable: exchangeViewModel.isDepositAddressEnabled,
|
|
|
|
isAmountEstimated: false,
|
|
|
|
hasRefundAddress: true,
|
|
|
|
isMoneroWallet: exchangeViewModel.isMoneroWallet,
|
|
|
|
currencies: exchangeViewModel.depositCurrencies,
|
|
|
|
onCurrencySelected: (currency) {
|
|
|
|
// FIXME: need to move it into view model
|
|
|
|
if (currency == CryptoCurrency.xmr &&
|
|
|
|
exchangeViewModel.wallet.type != WalletType.monero) {
|
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (dialogContext) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).error,
|
|
|
|
alertContent: S.of(context).exchange_incorrect_current_wallet_for_xmr,
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(dialogContext).pop());
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
exchangeViewModel.changeDepositCurrency(currency: currency);
|
|
|
|
},
|
|
|
|
imageArrow: arrowBottomPurple,
|
|
|
|
currencyButtonColor: Colors.transparent,
|
2023-08-22 18:49:37 +00:00
|
|
|
addressButtonsColor: Theme.of(context).extension<SendPageTheme>()!.textFieldButtonColor,
|
2023-08-17 15:28:31 +00:00
|
|
|
borderColor: Theme.of(context).extension<ExchangePageTheme>()!.textFieldBorderTopPanelColor,
|
2023-08-04 13:49:26 +00:00
|
|
|
currencyValueValidator: (value) {
|
|
|
|
return !exchangeViewModel.isFixedRateMode
|
|
|
|
? AmountValidator(
|
|
|
|
isAutovalidate: true,
|
|
|
|
currency: exchangeViewModel.depositCurrency,
|
|
|
|
minValue: exchangeViewModel.limits.min.toString(),
|
|
|
|
maxValue: exchangeViewModel.limits.max.toString(),
|
|
|
|
).call(value)
|
|
|
|
: null;
|
|
|
|
},
|
|
|
|
addressTextFieldValidator: AddressValidator(type: exchangeViewModel.depositCurrency),
|
|
|
|
onPushPasteButton: (context) async {
|
|
|
|
final domain = exchangeViewModel.depositAddress;
|
|
|
|
final ticker = exchangeViewModel.depositCurrency.title.toLowerCase();
|
|
|
|
exchangeViewModel.depositAddress =
|
|
|
|
await fetchParsedAddress(context, domain, ticker);
|
|
|
|
},
|
|
|
|
onPushAddressBookButton: (context) async {
|
|
|
|
final domain = exchangeViewModel.depositAddress;
|
|
|
|
final ticker = exchangeViewModel.depositCurrency.title.toLowerCase();
|
|
|
|
exchangeViewModel.depositAddress =
|
|
|
|
await fetchParsedAddress(context, domain, ticker);
|
|
|
|
},
|
|
|
|
));
|
|
|
|
|
|
|
|
final secondExchangeCard = Observer(
|
|
|
|
builder: (_) => ExchangeCard(
|
|
|
|
onDispose: disposeBestRateSync,
|
|
|
|
amountFocusNode: _receiveAmountFocus,
|
|
|
|
addressFocusNode: _receiveAddressFocus,
|
|
|
|
key: receiveKey,
|
|
|
|
title: S.of(context).you_will_get,
|
|
|
|
initialCurrency: exchangeViewModel.receiveCurrency,
|
|
|
|
initialWalletName: receiveWalletName ?? '',
|
|
|
|
initialAddress: exchangeViewModel.receiveCurrency == exchangeViewModel.wallet.currency
|
|
|
|
? exchangeViewModel.wallet.walletAddresses.address
|
|
|
|
: exchangeViewModel.receiveAddress,
|
|
|
|
initialIsAmountEditable: exchangeViewModel.isReceiveAmountEditable,
|
|
|
|
initialIsAddressEditable: exchangeViewModel.isReceiveAddressEnabled,
|
|
|
|
isAmountEstimated: true,
|
|
|
|
isMoneroWallet: exchangeViewModel.isMoneroWallet,
|
|
|
|
currencies: exchangeViewModel.receiveCurrencies,
|
|
|
|
onCurrencySelected: (currency) =>
|
|
|
|
exchangeViewModel.changeReceiveCurrency(currency: currency),
|
|
|
|
imageArrow: arrowBottomCakeGreen,
|
|
|
|
currencyButtonColor: Colors.transparent,
|
2023-08-22 18:49:37 +00:00
|
|
|
addressButtonsColor: Theme.of(context).extension<SendPageTheme>()!.textFieldButtonColor,
|
2023-08-17 15:28:31 +00:00
|
|
|
borderColor: Theme.of(context).extension<ExchangePageTheme>()!.textFieldBorderBottomPanelColor,
|
2023-08-04 13:49:26 +00:00
|
|
|
currencyValueValidator: (value) {
|
|
|
|
return exchangeViewModel.isFixedRateMode
|
|
|
|
? AmountValidator(
|
|
|
|
isAutovalidate: true,
|
|
|
|
currency: exchangeViewModel.receiveCurrency,
|
|
|
|
minValue: exchangeViewModel.limits.min.toString(),
|
|
|
|
maxValue: exchangeViewModel.limits.max.toString(),
|
|
|
|
).call(value)
|
|
|
|
: null;
|
|
|
|
},
|
|
|
|
addressTextFieldValidator: AddressValidator(type: exchangeViewModel.receiveCurrency),
|
|
|
|
onPushPasteButton: (context) async {
|
|
|
|
final domain = exchangeViewModel.receiveAddress;
|
|
|
|
final ticker = exchangeViewModel.receiveCurrency.title.toLowerCase();
|
|
|
|
exchangeViewModel.receiveAddress =
|
|
|
|
await fetchParsedAddress(context, domain, ticker);
|
|
|
|
},
|
|
|
|
onPushAddressBookButton: (context) async {
|
|
|
|
final domain = exchangeViewModel.receiveAddress;
|
|
|
|
final ticker = exchangeViewModel.receiveCurrency.title.toLowerCase();
|
|
|
|
exchangeViewModel.receiveAddress =
|
|
|
|
await fetchParsedAddress(context, domain, ticker);
|
|
|
|
},
|
|
|
|
));
|
2023-04-14 04:39:08 +00:00
|
|
|
|
2023-06-13 23:04:52 +00:00
|
|
|
if (ResponsiveLayoutUtil.instance.isMobile) {
|
2023-04-14 04:39:08 +00:00
|
|
|
return MobileExchangeCardsSection(
|
|
|
|
firstExchangeCard: firstExchangeCard,
|
|
|
|
secondExchangeCard: secondExchangeCard,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DesktopExchangeCardsSection(
|
|
|
|
firstExchangeCard: firstExchangeCard,
|
|
|
|
secondExchangeCard: secondExchangeCard,
|
|
|
|
);
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|