CAKE-278 | applied fixed rate mode only for pair xmr-btc; added _defineIsReceiveAmountEditable() to exchange_view_model.dart; added reaction on isReceiveAmountEditable to exchange_page.dart
OleksandrSobol committed
Feb 23, 2021 at 19:36 UTC
fc70852002476fc05f7c9e487ec3deb1cb6deaf8
2 files changed
+86
-78
lib/src/screens/exchange/exchange_page.dart
+73
-73
@@ -118,7 +118,7 @@ class ExchangePage extends BasePage {
118
key: _formKey,
119
child: ScrollableWithBottomSection(
120
contentPadding: EdgeInsets.only(bottom: 24),
121
- content: Column(
121
+ content: Observer(builder: (_) => Column(
122
children: <Widget>[
123
Container(
124
padding: EdgeInsets.only(bottom: 32),
@@ -168,22 +168,22 @@ class ExchangePage extends BasePage {
168
hasAllAmount: exchangeViewModel.hasAllAmount,
169
allAmount: exchangeViewModel.hasAllAmount
170
? () => exchangeViewModel
171
- .calculateDepositAllAmount()
171
+ .calculateDepositAllAmount()
172
: null,
173
amountFocusNode: _depositAmountFocus,
174
key: depositKey,
175
title: S.of(context).you_will_send,
176
initialCurrency:
177
- exchangeViewModel.depositCurrency,
177
+ exchangeViewModel.depositCurrency,
178
initialWalletName: depositWalletName,
179
initialAddress:
180
- exchangeViewModel.depositCurrency ==
181
- exchangeViewModel.wallet.currency
182
- ? exchangeViewModel.wallet.address
183
- : exchangeViewModel.depositAddress,
180
+ exchangeViewModel.depositCurrency ==
181
+ exchangeViewModel.wallet.currency
182
+ ? exchangeViewModel.wallet.address
183
+ : exchangeViewModel.depositAddress,
184
initialIsAmountEditable: true,
185
initialIsAddressEditable:
186
- exchangeViewModel.isDepositAddressEnabled,
186
+ exchangeViewModel.isDepositAddressEnabled,
187
isAmountEstimated: false,
188
hasRefundAddress: true,
189
currencies: CryptoCurrency.all,
@@ -214,7 +214,7 @@ class ExchangePage extends BasePage {
214
imageArrow: arrowBottomPurple,
215
currencyButtonColor: Colors.transparent,
216
addressButtonsColor:
217
- Theme.of(context).focusColor,
217
+ Theme.of(context).focusColor,
218
borderColor: Theme.of(context)
219
.primaryTextTheme
220
.body2
@@ -228,64 +228,64 @@ class ExchangePage extends BasePage {
228
),
229
Padding(
230
padding:
231
- EdgeInsets.only(top: 29, left: 24, right: 24),
231
+ EdgeInsets.only(top: 29, left: 24, right: 24),
232
child: Observer(
233
builder: (_) => ExchangeCard(
234
- amountFocusNode: _receiveAmountFocus,
235
- key: receiveKey,
236
- title: S.of(context).you_will_get,
237
- initialCurrency:
238
- exchangeViewModel.receiveCurrency,
239
- initialWalletName: receiveWalletName,
240
- initialAddress: exchangeViewModel
241
- .receiveCurrency ==
242
- exchangeViewModel.wallet.currency
243
- ? exchangeViewModel.wallet.address
244
- : exchangeViewModel.receiveAddress,
245
- initialIsAmountEditable: exchangeViewModel
246
- .isReceiveAmountEditable,
247
- initialIsAddressEditable:
248
- exchangeViewModel
249
- .isReceiveAddressEnabled,
250
- isAmountEstimated: true,
251
- currencies: CryptoCurrency.all,
252
- onCurrencySelected: (currency) =>
253
- exchangeViewModel
254
- .changeReceiveCurrency(
255
- currency: currency),
256
- imageArrow: arrowBottomCakeGreen,
257
- currencyButtonColor: Colors.transparent,
258
- addressButtonsColor:
259
- Theme.of(context).focusColor,
260
- borderColor: Theme.of(context)
261
- .primaryTextTheme
262
- .body2
263
- .decorationColor,
264
- currencyValueValidator: AmountValidator(
265
- type: exchangeViewModel.wallet.type),
266
- addressTextFieldValidator:
267
- AddressValidator(
268
- type: exchangeViewModel
269
- .receiveCurrency),
270
- )),
234
+ amountFocusNode: _receiveAmountFocus,
235
+ key: receiveKey,
236
+ title: S.of(context).you_will_get,
237
+ initialCurrency:
238
+ exchangeViewModel.receiveCurrency,
239
+ initialWalletName: receiveWalletName,
240
+ initialAddress: exchangeViewModel
241
+ .receiveCurrency ==
242
+ exchangeViewModel.wallet.currency
243
+ ? exchangeViewModel.wallet.address
244
+ : exchangeViewModel.receiveAddress,
245
+ initialIsAmountEditable: exchangeViewModel
246
+ .isReceiveAmountEditable,
247
+ initialIsAddressEditable:
248
+ exchangeViewModel
249
+ .isReceiveAddressEnabled,
250
+ isAmountEstimated: true,
251
+ currencies: CryptoCurrency.all,
252
+ onCurrencySelected: (currency) =>
253
+ exchangeViewModel
254
+ .changeReceiveCurrency(
255
+ currency: currency),
256
+ imageArrow: arrowBottomCakeGreen,
257
+ currencyButtonColor: Colors.transparent,
258
+ addressButtonsColor:
259
+ Theme.of(context).focusColor,
260
+ borderColor: Theme.of(context)
261
+ .primaryTextTheme
262
+ .body2
263
+ .decorationColor,
264
+ currencyValueValidator: AmountValidator(
265
+ type: exchangeViewModel.wallet.type),
266
+ addressTextFieldValidator:
267
+ AddressValidator(
268
+ type: exchangeViewModel
269
+ .receiveCurrency),
270
+ )),
271
)
272
],
273
),
274
),
275
- Padding(
276
- padding: EdgeInsets.only(top: 12, left: 24),
277
- child: Row(
278
- mainAxisAlignment: MainAxisAlignment.start,
279
- children: [
280
- StandardCheckbox(
281
- key: checkBoxKey,
282
- value: exchangeViewModel.isFixedRateMode,
283
- caption: 'Fixed rate', // FIXME
284
- onChanged: (value) =>
285
- exchangeViewModel.isFixedRateMode = value,
286
- ),
287
- ],
288
- )
275
+ if (exchangeViewModel.isReceiveAmountEditable) Padding(
276
+ padding: EdgeInsets.only(top: 12, left: 24),
277
+ child: Row(
278
+ mainAxisAlignment: MainAxisAlignment.start,
279
+ children: [
280
+ StandardCheckbox(
281
+ key: checkBoxKey,
282
+ value: exchangeViewModel.isFixedRateMode,
283
+ caption: 'Fixed rate', // FIXME
284
+ onChanged: (value) =>
285
+ exchangeViewModel.isFixedRateMode = value,
286
+ ),
287
+ ],
288
+ )
289
),
290
Padding(
291
padding: EdgeInsets.only(top: 30, left: 24, bottom: 24),
@@ -318,7 +318,7 @@ class ExchangePage extends BasePage {
318
.pushNamed(Routes.exchangeTemplate),
319
child: Container(
320
padding:
321
- EdgeInsets.only(left: 1, right: 10),
321
+ EdgeInsets.only(left: 1, right: 10),
322
child: DottedBorder(
323
borderType: BorderType.RRect,
324
dashPattern: [6, 4],
@@ -385,23 +385,23 @@ class ExchangePage extends BasePage {
385
.of(context)
386
.confirm_delete_template,
387
rightButtonText:
388
- S.of(context).delete,
388
+ S.of(context).delete,
389
leftButtonText:
390
- S.of(context).cancel,
390
+ S.of(context).cancel,
391
actionRightButton: () {
392
Navigator.of(
393
- dialogContext)
393
+ dialogContext)
394
.pop();
395
exchangeViewModel
396
.removeTemplate(
397
- template:
398
- template);
397
+ template:
398
+ template);
399
exchangeViewModel
400
.updateTemplate();
401
},
402
actionLeftButton: () =>
403
Navigator.of(
404
- dialogContext)
404
+ dialogContext)
405
.pop());
406
});
407
},
@@ -411,7 +411,7 @@ class ExchangePage extends BasePage {
411
],
412
)))
413
],
414
- ),
414
+ )),
415
bottomSectionPadding:
416
EdgeInsets.only(left: 24, right: 24, bottom: 24),
417
bottomSection: Column(children: <Widget>[
@@ -575,10 +575,10 @@ class ExchangePage extends BasePage {
575
receiveKey.currentState.isAddressEditable(isEditable: isEnabled);
576
});
577
578
- reaction((_) => exchangeViewModel.provider, (ExchangeProvider provider) {
579
- provider is ChangeNowExchangeProvider
580
- ? receiveKey.currentState.isAmountEditable(isEditable: true)
581
- : receiveKey.currentState.isAmountEditable(isEditable: false);
578
+ reaction((_) => exchangeViewModel.isReceiveAmountEditable,
579
+ (bool isReceiveAmountEditable) {
580
+ receiveKey.currentState
581
+ .isAmountEditable(isEditable: isReceiveAmountEditable);
582
});
583
584
reaction((_) => exchangeViewModel.tradeState, (ExchangeTradeState state) {
lib/view_model/exchange/exchange_view_model.dart
+13
-5
@@ -57,10 +57,8 @@ abstract class ExchangeViewModelBase with Store {
57
_onPairChange();
58
}
59
});
60
-
61
- isReceiveAmountEditable = provider is ChangeNowExchangeProvider;
60
+ _defineIsReceiveAmountEditable();
61
isFixedRateMode = false;
63
-
62
isReceiveAmountEntered = false;
63
loadLimits();
64
}
@@ -136,8 +134,8 @@ abstract class ExchangeViewModelBase with Store {
134
this.provider = provider;
135
depositAmount = '';
136
receiveAmount = '';
139
- isReceiveAmountEditable = provider is ChangeNowExchangeProvider;
137
isFixedRateMode = false;
138
+ _defineIsReceiveAmountEditable();
139
loadLimits();
140
}
141
@@ -380,7 +378,7 @@ abstract class ExchangeViewModelBase with Store {
378
}
379
}
380
383
- depositAddress = depositCurrency == wallet.currency ? wallet.address : '';
381
+ _defineIsReceiveAmountEditable();
382
depositAmount = '';
383
receiveAmount = '';
384
loadLimits();
@@ -405,4 +403,14 @@ abstract class ExchangeViewModelBase with Store {
403
break;
404
}
405
}
406
+
407
+ void _defineIsReceiveAmountEditable() {
408
+ if ((provider is ChangeNowExchangeProvider)
409
+ &&(depositCurrency == CryptoCurrency.xmr)
410
+ &&(receiveCurrency == CryptoCurrency.btc)) {
411
+ isReceiveAmountEditable = true;
412
+ } else {
413
+ isReceiveAmountEditable = false;
414
+ }
415
+ }
416
}