CAKE-278 | added isReceiveAmountEditable and isFixedRateMode to exchange_view_model.dart; fixed changeReceiveAmount() in the exchange_view_model.dart; applied StandardCheckbox to exchange_page.dart for checking fixed rate mode; applied alert dialog to exchange_page.dart when receive amount has focus and fixed rate mode is not checked; added reaction for isFixedRateMode in the exchange_page.dart; added key and changeValue() to standard_checkbox.dart

This commit is contained in:
OleksandrSobol 2021-02-16 21:06:23 +02:00
parent 35aabcd248
commit 317ef8f3e4
3 changed files with 71 additions and 7 deletions

View file

@ -1,6 +1,8 @@
import 'dart:ui';
import 'package:cake_wallet/entities/sync_status.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/exchange/changenow/changenow_exchange_provider.dart';
import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@ -37,6 +39,7 @@ class ExchangePage extends BasePage {
final ExchangeViewModel exchangeViewModel;
final depositKey = GlobalKey<ExchangeCardState>();
final receiveKey = GlobalKey<ExchangeCardState>();
final checkBoxKey = GlobalKey<StandardCheckboxState>();
final _formKey = GlobalKey<FormState>();
final _depositAmountFocus = FocusNode();
final _receiveAmountFocus = FocusNode();
@ -240,9 +243,7 @@ class ExchangePage extends BasePage {
? exchangeViewModel.wallet.address
: exchangeViewModel.receiveAddress,
initialIsAmountEditable: exchangeViewModel
.provider is XMRTOExchangeProvider
? true
: false,
.isReceiveAmountEditable,
initialIsAddressEditable:
exchangeViewModel
.isReceiveAddressEnabled,
@ -271,6 +272,21 @@ class ExchangePage extends BasePage {
],
),
),
Padding(
padding: EdgeInsets.only(top: 12, left: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
StandardCheckbox(
key: checkBoxKey,
value: exchangeViewModel.isFixedRateMode,
caption: 'Fixed rate', // FIXME
onChanged: (value) =>
exchangeViewModel.isFixedRateMode = value,
),
],
)
),
Padding(
padding: EdgeInsets.only(top: 30, left: 24, bottom: 24),
child: Row(
@ -567,7 +583,7 @@ class ExchangePage extends BasePage {
});
reaction((_) => exchangeViewModel.provider, (ExchangeProvider provider) {
provider is XMRTOExchangeProvider
provider is ChangeNowExchangeProvider
? receiveKey.currentState.isAmountEditable(isEditable: true)
: receiveKey.currentState.isAmountEditable(isEditable: false);
});
@ -647,6 +663,39 @@ class ExchangePage extends BasePage {
}
});
_receiveAmountFocus.addListener(() {
if (_receiveAmountFocus.hasFocus && !exchangeViewModel.isFixedRateMode) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).exchange,
alertContent: 'You will be able to enter receive amount when fixed rate is checked. Do you want to check fixed rate?', //FIXME
leftButtonText: S.of(context).cancel,
rightButtonText: S.of(context).ok,
actionLeftButton: () {
FocusScope.of(context).unfocus();
receiveAmountController.text = '';
Navigator.of(context).pop();
},
actionRightButton: () {
exchangeViewModel.isFixedRateMode = true;
checkBoxKey.currentState
.changeValue(exchangeViewModel.isFixedRateMode);
Navigator.of(context).pop();
});
});
}
});
reaction((_) => exchangeViewModel.isFixedRateMode, (bool isFixedRateMode) {
if ((_receiveAmountFocus.hasFocus ||
exchangeViewModel.isReceiveAmountEntered) && !isFixedRateMode) {
FocusScope.of(context).unfocus();
receiveAmountController.text = '';
}
});
_isReactionsSet = true;
}

View file

@ -4,9 +4,10 @@ import 'package:flutter/material.dart';
class StandardCheckbox extends StatefulWidget {
StandardCheckbox({
Key key,
@required this.value,
this.caption = '',
@required this.onChanged});
@required this.onChanged}) : super(key: key);
final bool value;
final String caption;
@ -24,6 +25,10 @@ class StandardCheckboxState extends State<StandardCheckbox> {
String caption;
Function(bool) onChanged;
void changeValue(bool newValue) {
setState(() => value = newValue);
}
@override
Widget build(BuildContext context) {
return GestureDetector(

View file

@ -58,6 +58,9 @@ abstract class ExchangeViewModelBase with Store {
}
});
isReceiveAmountEditable = provider is ChangeNowExchangeProvider;
isFixedRateMode = false;
isReceiveAmountEntered = false;
loadLimits();
}
@ -106,6 +109,12 @@ abstract class ExchangeViewModelBase with Store {
@observable
bool isReceiveAmountEntered;
@observable
bool isReceiveAmountEditable;
@observable
bool isFixedRateMode;
@computed
SyncStatus get status => wallet.syncStatus;
@ -127,6 +136,7 @@ abstract class ExchangeViewModelBase with Store {
this.provider = provider;
depositAmount = '';
receiveAmount = '';
isReceiveAmountEditable = provider is ChangeNowExchangeProvider;
loadLimits();
}
@ -160,8 +170,8 @@ abstract class ExchangeViewModelBase with Store {
provider
.calculateAmount(
from: depositCurrency,
to: receiveCurrency,
from: receiveCurrency,
to: depositCurrency,
amount: _amount,
isReceiveAmount: true)
.then((amount) => _cryptoNumberFormat