From 7ce30e08b0286b151bdec31c0a24b885787333ab Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Mon, 2 Nov 2020 13:33:45 +0200 Subject: [PATCH] CAKE-143 | added status parameter to exchange_view_model.dart; called alert when user tries exchange deposit xmr currency but wallet is not synchronized --- lib/src/screens/exchange/exchange_page.dart | 38 ++++++++++++------- .../exchange/exchange_view_model.dart | 4 ++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index bc9accb14..4b0e0a21e 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -1,4 +1,5 @@ import 'dart:ui'; +import 'package:cake_wallet/entities/sync_status.dart'; import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -394,19 +395,30 @@ class ExchangePage extends BasePage { }), ), Observer( - builder: (_) => LoadingPrimaryButton( - text: S.of(context).exchange, - onPressed: () { - if (_formKey.currentState.validate()) { - exchangeViewModel.createTrade(); - } - }, - color: - Theme.of(context).accentTextTheme.body2.color, - textColor: Colors.white, - isLoading: exchangeViewModel.tradeState - is TradeIsCreating, - )), + builder: (_) => LoadingPrimaryButton( + text: S.of(context).exchange, + onPressed: () { + if (_formKey.currentState.validate()) { + if ((exchangeViewModel.depositCurrency == CryptoCurrency.xmr) + &&(!(exchangeViewModel.status is SyncedSyncStatus))) { + showPopUp( + context: context, + builder: (BuildContext context) { + return AlertWithOneAction( + alertTitle: S.of(context).exchange, + alertContent: 'Please wait until your wallet is synchronized', + buttonText: S.of(context).ok, + buttonAction: () => Navigator.of(context).pop()); + }); + } else { + exchangeViewModel.createTrade(); + } + } + }, + color: Theme.of(context).accentTextTheme.body2.color, + textColor: Colors.white, + isLoading: exchangeViewModel.tradeState + is TradeIsCreating)), ]), )), )); diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 2f8d28cd4..199ae016f 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/core/wallet_base.dart'; import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/entities/sync_status.dart'; import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/exchange/exchange_provider.dart'; import 'package:cake_wallet/exchange/limits.dart'; @@ -100,6 +101,9 @@ abstract class ExchangeViewModelBase with Store { NumberFormat _cryptoNumberFormat; + @computed + SyncStatus get status => wallet.syncStatus; + @computed ObservableList get templates => _exchangeTemplateStore.templates;