CAKE-185 | added title property to TradeIsCreatedFailure class; applied title property in the createTrade() method (exchange_view_model.dart); applied title property as alert title in the exchange_page.dart

This commit is contained in:
OleksandrSobol 2020-12-02 21:51:06 +02:00
parent ca0c0d1ad6
commit 458079d3ae
3 changed files with 9 additions and 3 deletions

View file

@ -14,7 +14,8 @@ class TradeIsCreatedSuccessfully extends ExchangeTradeState {
} }
class TradeIsCreatedFailure extends ExchangeTradeState { class TradeIsCreatedFailure extends ExchangeTradeState {
TradeIsCreatedFailure({@required this.error}); TradeIsCreatedFailure({@required this.title, @required this.error});
final String title;
final String error; final String error;
} }

View file

@ -558,7 +558,7 @@ class ExchangePage extends BasePage {
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertWithOneAction( return AlertWithOneAction(
alertTitle: S.of(context).error, alertTitle: state.title,
alertContent: state.error, alertContent: state.error,
buttonText: S.of(context).ok, buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop()); buttonAction: () => Navigator.of(context).pop());

View file

@ -247,10 +247,12 @@ abstract class ExchangeViewModelBase with Store {
if (limitsState is LimitsLoadedSuccessfully && amount != null) { if (limitsState is LimitsLoadedSuccessfully && amount != null) {
if (double.parse(amount) < limits.min) { if (double.parse(amount) < limits.min) {
tradeState = TradeIsCreatedFailure( tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current.error_text_minimal_limit('${provider.description}', error: S.current.error_text_minimal_limit('${provider.description}',
'${limits.min}', currency.toString())); '${limits.min}', currency.toString()));
} else if (limits.max != null && double.parse(amount) > limits.max) { } else if (limits.max != null && double.parse(amount) > limits.max) {
tradeState = TradeIsCreatedFailure( tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current.error_text_maximum_limit('${provider.description}', error: S.current.error_text_maximum_limit('${provider.description}',
'${limits.max}', currency.toString())); '${limits.max}', currency.toString()));
} else { } else {
@ -262,11 +264,14 @@ abstract class ExchangeViewModelBase with Store {
await trades.add(trade); await trades.add(trade);
tradeState = TradeIsCreatedSuccessfully(trade: trade); tradeState = TradeIsCreatedSuccessfully(trade: trade);
} catch (e) { } catch (e) {
tradeState = TradeIsCreatedFailure(error: e.toString()); tradeState = TradeIsCreatedFailure(
title: provider.title,
error: e.toString());
} }
} }
} else { } else {
tradeState = TradeIsCreatedFailure( tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current error: S.current
.error_text_limits_loading_failed('${provider.description}')); .error_text_limits_loading_failed('${provider.description}'));
} }