diff --git a/lib/di.dart b/lib/di.dart index 26d291cfd..15a47f04b 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,3 +1,4 @@ + import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; import 'package:cake_wallet/core/wallet_service.dart'; import 'package:cake_wallet/entities/biometric_auth.dart'; @@ -332,7 +333,8 @@ Future setup( getIt.registerFactory(() => ExchangeTradeViewModel( wallet: getIt.get().wallet, trades: tradesSource, - tradesStore: getIt.get())); + tradesStore: getIt.get(), + sendViewModel: getIt.get())); getIt.registerFactory(() => ExchangePage(getIt.get())); diff --git a/lib/src/screens/exchange/widgets/currency_picker.dart b/lib/src/screens/exchange/widgets/currency_picker.dart index 8a5c2794f..e07c988b5 100644 --- a/lib/src/screens/exchange/widgets/currency_picker.dart +++ b/lib/src/screens/exchange/widgets/currency_picker.dart @@ -95,6 +95,7 @@ class CurrencyPickerState extends State { alignment: Alignment.center, children: [ GridView.count( + padding: EdgeInsets.all(0), controller: controller, crossAxisCount: crossAxisCount, childAspectRatio: 1.25, diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index 15c1a8a77..aced6304a 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -1,31 +1,26 @@ -import 'package:cake_wallet/palette.dart'; -import 'package:cake_wallet/entities/crypto_currency.dart'; -import 'package:cake_wallet/exchange/exchange_provider_description.dart'; -import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_item.dart'; -import 'package:cake_wallet/src/screens/exchange_trade/information_page.dart'; -import 'package:cake_wallet/src/widgets/standart_list_row.dart'; -import 'package:cake_wallet/utils/show_bar.dart'; -import 'package:cake_wallet/utils/show_pop_up.dart'; -import 'package:cake_wallet/view_model/exchange/exchange_trade_view_model.dart'; +import 'dart:ui'; import 'package:mobx/mobx.dart'; -import 'package:provider/provider.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'package:cake_wallet/generated/i18n.dart'; - -// import 'package:cake_wallet/src/stores/exchange_trade/exchange_trade_store.dart'; -// import 'package:cake_wallet/src/stores/send/send_store.dart'; -// import 'package:cake_wallet/src/stores/send/sending_state.dart'; -// import 'package:cake_wallet/src/stores/wallet/wallet_store.dart'; +import 'package:cake_wallet/core/execution_state.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/exchange/exchange_provider_description.dart'; +import 'package:cake_wallet/src/screens/exchange_trade/information_page.dart'; +import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart'; +import 'package:cake_wallet/src/widgets/standart_list_row.dart'; +import 'package:cake_wallet/utils/show_bar.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; +import 'package:cake_wallet/view_model/exchange/exchange_trade_view_model.dart'; +import 'package:cake_wallet/view_model/send/send_view_model_state.dart'; import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/exchange_trade/widgets/timer_widget.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/src/widgets/alert_with_two_actions.dart'; void showInformation( ExchangeTradeViewModel exchangeTradeViewModel, BuildContext context) { @@ -110,7 +105,7 @@ class ExchangeTradeState extends State { width: 16, color: Theme.of(context).primaryTextTheme.overline.color); - //_setEffects(context); + _setEffects(context); return Container( child: ScrollableWithBottomSection( @@ -227,44 +222,25 @@ class ExchangeTradeState extends State { ); }), bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 24), - bottomSection: - /*Observer( - builder: (_) => tradeStore.trade.from == CryptoCurrency.xmr && - !(sendStore.state is TransactionCommitted) - ? LoadingPrimaryButton( - isDisabled: tradeStore.trade.inputAddress == null || - tradeStore.trade.inputAddress.isEmpty, - isLoading: sendStore.state is CreatingTransaction || - sendStore.state is TransactionCommitted, - onPressed: () => sendStore.createTransaction( - address: tradeStore.trade.inputAddress, - amount: tradeStore.trade.amount), - text: tradeStore.trade.provider == - ExchangeProviderDescription.xmrto - ? S.of(context).confirm - : S.of(context).send_xmr, - color: Colors.blue, - textColor: Colors.white) - : Offstage()),*/ - Observer( - builder: (_) { - final trade = widget.exchangeTradeViewModel.trade; + bottomSection: Observer(builder: (_) { + final trade = widget.exchangeTradeViewModel.trade; + final sendingState = + widget.exchangeTradeViewModel.sendViewModel.state; - return trade.from == CryptoCurrency.xmr - ? LoadingPrimaryButton( + return trade.from == CryptoCurrency.xmr && !(sendingState is TransactionCommitted) + ? LoadingPrimaryButton( isDisabled: trade.inputAddress == null || trade.inputAddress.isEmpty, - isLoading: false, // FIXME - onPressed: () {}, // FIXME - text: trade.provider == - ExchangeProviderDescription.xmrto + isLoading: sendingState is IsExecutingState, + onPressed: () => + widget.exchangeTradeViewModel.confirmSending(), + text: trade.provider == ExchangeProviderDescription.xmrto ? S.of(context).confirm : S.of(context).send_xmr, color: Theme.of(context).accentTextTheme.body2.color, textColor: Colors.white) - : Offstage(); - }) - ), + : Offstage(); + })), ); } @@ -273,10 +249,9 @@ class ExchangeTradeState extends State { return; } - /*final sendStore = Provider.of(context); - - reaction((_) => sendStore.state, (SendingState state) { - if (state is SendingFailed) { + reaction((_) => this.widget.exchangeTradeViewModel.sendViewModel.state, + (ExecutionState state) { + if (state is FailureState) { WidgetsBinding.instance.addPostFrameCallback((_) { showPopUp( context: context, @@ -285,30 +260,126 @@ class ExchangeTradeState extends State { alertTitle: S.of(context).error, alertContent: state.error, buttonText: S.of(context).ok, - buttonAction: () => Navigator.of(context).pop() - ); + buttonAction: () => Navigator.of(context).pop()); }); }); } - if (state is TransactionCreatedSuccessfully) { + if (state is ExecutedSuccessfullyState) { WidgetsBinding.instance.addPostFrameCallback((_) { showPopUp( context: context, builder: (BuildContext context) { - return AlertWithTwoActions( + return ConfirmSendingAlert( alertTitle: S.of(context).confirm_sending, - alertContent: S.of(context).commit_transaction_amount_fee( - sendStore.pendingTransaction.amount, - sendStore.pendingTransaction.fee), - leftButtonText: S.of(context).ok, - rightButtonText: S.of(context).cancel, - actionLeftButton: () { + amount: S.of(context).send_amount, + amountValue: widget.exchangeTradeViewModel.sendViewModel + .pendingTransaction.amountFormatted, + fee: S.of(context).send_fee, + feeValue: widget.exchangeTradeViewModel.sendViewModel + .pendingTransaction.feeFormatted, + rightButtonText: S.of(context).ok, + leftButtonText: S.of(context).cancel, + actionRightButton: () { Navigator.of(context).pop(); - sendStore.commitTransaction(); + widget.exchangeTradeViewModel.sendViewModel + .commitTransaction(); + showPopUp( + context: context, + builder: (BuildContext context) { + return Observer(builder: (_) { + final state = widget + .exchangeTradeViewModel.sendViewModel.state; + + if (state is TransactionCommitted) { + return Stack( + children: [ + Container( + color: Theme.of(context).backgroundColor, + child: Center( + child: Image.asset( + 'assets/images/birthday_cake.png'), + ), + ), + Center( + child: Padding( + padding: EdgeInsets.only( + top: 220, left: 24, right: 24), + child: Text( + S.of(context).send_success, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .primaryTextTheme + .title + .color, + decoration: TextDecoration.none, + ), + ), + ), + ), + Positioned( + left: 24, + right: 24, + bottom: 24, + child: PrimaryButton( + onPressed: () => + Navigator.of(context).pop(), + text: S.of(context).send_got_it, + color: Theme.of(context) + .accentTextTheme + .body2 + .color, + textColor: Colors.white)) + ], + ); + } + + return Stack( + children: [ + Container( + color: Theme.of(context).backgroundColor, + child: Center( + child: Image.asset( + 'assets/images/birthday_cake.png'), + ), + ), + BackdropFilter( + filter: ImageFilter.blur( + sigmaX: 3.0, sigmaY: 3.0), + child: Container( + decoration: BoxDecoration( + color: Theme.of(context) + .backgroundColor + .withOpacity(0.25)), + child: Center( + child: Padding( + padding: EdgeInsets.only(top: 220), + child: Text( + S.of(context).send_sending, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .primaryTextTheme + .title + .color, + decoration: TextDecoration.none, + ), + ), + ), + ), + ), + ) + ], + ); + }); + }); }, - actionRightButton: () => Navigator.of(context).pop() - ); + actionLeftButton: () => Navigator.of(context).pop()); }); }); } @@ -322,12 +393,11 @@ class ExchangeTradeState extends State { alertTitle: S.of(context).sending, alertContent: S.of(context).transaction_sent, buttonText: S.of(context).ok, - buttonAction: () => Navigator.of(context).pop() - ); + buttonAction: () => Navigator.of(context).pop()); }); }); } - });*/ + }); _effectsInstalled = true; } diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 459e435d5..5cdb4b092 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -483,8 +483,16 @@ class SendPage extends BasePage { } }, text: S.of(context).send, - color: Theme.of(context).accentTextTheme.body2.color, - textColor: Colors.white, + color: Theme + .of(context) + .accentTextTheme + .subtitle + .decorationColor, + textColor: Theme + .of(context) + .accentTextTheme + .headline + .decorationColor, isLoading: sendViewModel.state is IsExecutingState || sendViewModel.state is TransactionCommitting, isDisabled: diff --git a/lib/src/screens/send/send_template_page.dart b/lib/src/screens/send/send_template_page.dart index 37708fcb2..b53117309 100644 --- a/lib/src/screens/send/send_template_page.dart +++ b/lib/src/screens/send/send_template_page.dart @@ -1,15 +1,17 @@ -import 'package:cake_wallet/src/widgets/address_text_field.dart'; -import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; -import 'package:cake_wallet/src/widgets/primary_button.dart'; -import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; +import 'package:mobx/mobx.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:keyboard_actions/keyboard_actions.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/view_model/send/send_view_model.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_mobx/flutter_mobx.dart'; -import 'package:mobx/mobx.dart'; +import 'package:cake_wallet/src/widgets/address_text_field.dart'; +import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; +import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; +import 'package:cake_wallet/src/widgets/primary_button.dart'; +import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; class SendTemplatePage extends BasePage { SendTemplatePage({@required this.sendViewModel}); @@ -20,6 +22,8 @@ class SendTemplatePage extends BasePage { final _fiatAmountController = TextEditingController(); final _nameController = TextEditingController(); final _formKey = GlobalKey(); + final FocusNode _cryptoAmountFocus = FocusNode(); + final FocusNode _fiatAmountFocus = FocusNode(); bool _effectsInstalled = false; @@ -42,94 +46,153 @@ class SendTemplatePage extends BasePage { Widget body(BuildContext context) { _setEffects(context); - return Container( - color: Theme.of(context).backgroundColor, - child: ScrollableWithBottomSection( - contentPadding: EdgeInsets.only(bottom: 24), - content: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(24), - bottomRight: Radius.circular(24) - ), - gradient: LinearGradient(colors: [ - Theme.of(context).primaryTextTheme.subhead.color, - Theme.of(context).primaryTextTheme.subhead.decorationColor, - ], begin: Alignment.topLeft, end: Alignment.bottomRight), - ), - child: Form( - key: _formKey, - child: Column(children: [ - Padding( - padding: EdgeInsets.fromLTRB(24, 90, 24, 32), - child: Column( - children: [ - BaseTextFormField( - controller: _nameController, - hintText: S.of(context).send_name, - borderColor: Theme.of(context) - .primaryTextTheme - .headline - .color, - textStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: Colors.white), - placeholderTextStyle: TextStyle( - color: Theme.of(context) - .primaryTextTheme - .headline - .decorationColor, - fontWeight: FontWeight.w500, - fontSize: 14), - validator: sendViewModel.templateValidator, - ), - Padding( - padding: EdgeInsets.only(top: 20), - child: AddressTextField( - controller: _addressController, - onURIScanned: (uri) { - var address = ''; - var amount = ''; + return KeyboardActions( + config: KeyboardActionsConfig( + keyboardActionsPlatform: KeyboardActionsPlatform.IOS, + keyboardBarColor: isDarkTheme + ? Color.fromRGBO(48, 51, 60, 1.0) + : Color.fromRGBO(98, 98, 98, 1.0), + nextFocus: false, + actions: [ + KeyboardActionsItem( + focusNode: _cryptoAmountFocus, + toolbarButtons: [(_) => KeyboardDoneButton()], + ), + KeyboardActionsItem( + focusNode: _fiatAmountFocus, + toolbarButtons: [(_) => KeyboardDoneButton()], + ) + ]), + child: Container( + height: 0, + color: Theme.of(context).backgroundColor, + child: ScrollableWithBottomSection( + contentPadding: EdgeInsets.only(bottom: 24), + content: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(24), + bottomRight: Radius.circular(24)), + gradient: LinearGradient(colors: [ + Theme.of(context).primaryTextTheme.subhead.color, + Theme.of(context).primaryTextTheme.subhead.decorationColor, + ], begin: Alignment.topLeft, end: Alignment.bottomRight), + ), + child: Form( + key: _formKey, + child: Column(children: [ + Padding( + padding: EdgeInsets.fromLTRB(24, 90, 24, 32), + child: Column( + children: [ + BaseTextFormField( + controller: _nameController, + hintText: S.of(context).send_name, + borderColor: + Theme.of(context).primaryTextTheme.headline.color, + textStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w500, + color: Colors.white), + placeholderTextStyle: TextStyle( + color: Theme.of(context) + .primaryTextTheme + .headline + .decorationColor, + fontWeight: FontWeight.w500, + fontSize: 14), + validator: sendViewModel.templateValidator, + ), + Padding( + padding: EdgeInsets.only(top: 20), + child: AddressTextField( + controller: _addressController, + onURIScanned: (uri) { + var address = ''; + var amount = ''; - if (uri != null) { - address = uri.path; - amount = uri.queryParameters['tx_amount']; - } else { - address = uri.toString(); - } + if (uri != null) { + address = uri.path; + amount = uri.queryParameters['tx_amount']; + } else { + address = uri.toString(); + } - _addressController.text = address; - _cryptoAmountController.text = amount; - }, - options: [ - AddressTextFieldOption.paste, - AddressTextFieldOption.qrCode, - AddressTextFieldOption.addressBook - ], - buttonColor: - Theme.of(context).primaryTextTheme.display1.color, - borderColor: - Theme.of(context).primaryTextTheme.headline.color, - textStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: Colors.white), - hintStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: Theme.of(context) + _addressController.text = address; + _cryptoAmountController.text = amount; + }, + options: [ + AddressTextFieldOption.paste, + AddressTextFieldOption.qrCode, + AddressTextFieldOption.addressBook + ], + buttonColor: Theme.of(context) + .primaryTextTheme + .display1 + .color, + borderColor: Theme.of(context) .primaryTextTheme .headline - .decorationColor), - validator: sendViewModel.addressValidator, - ), - ), - Observer(builder: (_) { - return Padding( - padding: const EdgeInsets.only(top: 20), - child: BaseTextFormField( - controller: _cryptoAmountController, + .color, + textStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w500, + color: Colors.white), + hintStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w500, + color: Theme.of(context) + .primaryTextTheme + .headline + .decorationColor), + validator: sendViewModel.addressValidator, + ), + ), + Observer(builder: (_) { + return Padding( + padding: const EdgeInsets.only(top: 20), + child: BaseTextFormField( + focusNode: _cryptoAmountFocus, + controller: _cryptoAmountController, + keyboardType: TextInputType.numberWithOptions( + signed: false, decimal: true), + inputFormatters: [ + BlacklistingTextInputFormatter( + RegExp('[\\-|\\ ]')) + ], + prefixIcon: Padding( + padding: EdgeInsets.only(top: 9), + child: + Text(sendViewModel.currency.title + ':', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Colors.white, + )), + ), + hintText: '0.0000', + borderColor: Theme.of(context) + .primaryTextTheme + .headline + .color, + textStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w500, + color: Colors.white), + placeholderTextStyle: TextStyle( + color: Theme.of(context) + .primaryTextTheme + .headline + .decorationColor, + fontWeight: FontWeight.w500, + fontSize: 14), + validator: sendViewModel.amountValidator)); + }), + Padding( + padding: const EdgeInsets.only(top: 20), + child: BaseTextFormField( + focusNode: _fiatAmountFocus, + controller: _fiatAmountController, keyboardType: TextInputType.numberWithOptions( signed: false, decimal: true), inputFormatters: [ @@ -138,15 +201,14 @@ class SendTemplatePage extends BasePage { ], prefixIcon: Padding( padding: EdgeInsets.only(top: 9), - child: - Text(sendViewModel.currency.title + ':', + child: Text(sendViewModel.fiat.title + ':', style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, color: Colors.white, )), ), - hintText: '0.0000', + hintText: '0.00', borderColor: Theme.of(context) .primaryTextTheme .headline @@ -162,68 +224,34 @@ class SendTemplatePage extends BasePage { .decorationColor, fontWeight: FontWeight.w500, fontSize: 14), - validator: sendViewModel.amountValidator)); - }), - Padding( - padding: const EdgeInsets.only(top: 20), - child: BaseTextFormField( - controller: _fiatAmountController, - keyboardType: TextInputType.numberWithOptions( - signed: false, decimal: true), - inputFormatters: [ - BlacklistingTextInputFormatter( - RegExp('[\\-|\\ ]')) - ], - prefixIcon: Padding( - padding: EdgeInsets.only(top: 9), - child: Text(sendViewModel.fiat.title + ':', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Colors.white, - )), - ), - hintText: '0.00', - borderColor: Theme.of(context) - .primaryTextTheme - .headline - .color, - textStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: Colors.white), - placeholderTextStyle: TextStyle( - color: Theme.of(context) - .primaryTextTheme - .headline - .decorationColor, - fontWeight: FontWeight.w500, - fontSize: 14), - )), - ], - ), - ) - ]), + )), + ], + ), + ) + ]), + ), + ), + bottomSectionPadding: + EdgeInsets.only(left: 24, right: 24, bottom: 24), + bottomSection: PrimaryButton( + onPressed: () { + if (_formKey.currentState.validate()) { + sendViewModel.addTemplate( + name: _nameController.text, + address: _addressController.text, + cryptoCurrency: sendViewModel.currency.title, + amount: _cryptoAmountController.text); + sendViewModel.updateTemplate(); + Navigator.of(context).pop(); + } + }, + text: S.of(context).save, + color: Theme.of(context).accentTextTheme.subtitle.decorationColor, + textColor: + Theme.of(context).accentTextTheme.headline.decorationColor, + ), ), - ), - bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24), - bottomSection: PrimaryButton( - onPressed: () { - if (_formKey.currentState.validate()) { - sendViewModel.addTemplate( - name: _nameController.text, - address: _addressController.text, - cryptoCurrency: sendViewModel.currency.title, - amount: _cryptoAmountController.text); - sendViewModel.updateTemplate(); - Navigator.of(context).pop(); - } - }, - text: S.of(context).save, - color: Colors.green, - textColor: Colors.white), - ), - ); + )); } void _setEffects(BuildContext context) { diff --git a/lib/src/screens/trade_details/trade_details_page.dart b/lib/src/screens/trade_details/trade_details_page.dart index 88e30bae9..30b29d115 100644 --- a/lib/src/screens/trade_details/trade_details_page.dart +++ b/lib/src/screens/trade_details/trade_details_page.dart @@ -13,29 +13,29 @@ import 'package:cake_wallet/src/widgets/standart_list_row.dart'; class TradeDetailsPage extends BasePage { TradeDetailsPage(this.trade) : _items = [] { final dateFormat = DateFormatter.withCurrentLocal(); - final items = [ + _items.addAll([ StandartListItem(title: S.current.trade_details_id, value: trade.id), StandartListItem( title: S.current.trade_details_state, value: trade.state != null ? trade.state.toString() : S.current.trade_details_fetching) - ]; + ]); if (trade.provider != null) { - items.add(StandartListItem( + _items.add(StandartListItem( title: S.current.trade_details_provider, value: trade.provider.toString())); } if (trade.createdAt != null) { - items.add(StandartListItem( + _items.add(StandartListItem( title: S.current.trade_details_created_at, value: dateFormat.format(trade.createdAt).toString())); } if (trade.from != null && trade.to != null) { - items.add(StandartListItem( + _items.add(StandartListItem( title: S.current.trade_details_pair, value: '${trade.from.toString()} → ${trade.to.toString()}')); } diff --git a/lib/view_model/exchange/exchange_trade_view_model.dart b/lib/view_model/exchange/exchange_trade_view_model.dart index 43490866e..dedb2c559 100644 --- a/lib/view_model/exchange/exchange_trade_view_model.dart +++ b/lib/view_model/exchange/exchange_trade_view_model.dart @@ -7,6 +7,7 @@ import 'package:cake_wallet/exchange/morphtoken/morphtoken_exchange_provider.dar import 'package:cake_wallet/exchange/trade.dart'; import 'package:cake_wallet/exchange/xmrto/xmrto_exchange_provider.dart'; import 'package:cake_wallet/store/dashboard/trades_store.dart'; +import 'package:cake_wallet/view_model/send/send_view_model.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_item.dart'; @@ -18,7 +19,8 @@ class ExchangeTradeViewModel = ExchangeTradeViewModelBase with _$ExchangeTradeViewModel; abstract class ExchangeTradeViewModelBase with Store { - ExchangeTradeViewModelBase({this.wallet, this.trades, this.tradesStore}) { + ExchangeTradeViewModelBase( + {this.wallet, this.trades, this.tradesStore, this.sendViewModel}) { trade = tradesStore.trade; isSendable = trade.from == wallet.currency || @@ -57,6 +59,7 @@ abstract class ExchangeTradeViewModelBase with Store { final WalletBase wallet; final Box trades; final TradesStore tradesStore; + final SendViewModel sendViewModel; @observable Trade trade; @@ -71,6 +74,17 @@ abstract class ExchangeTradeViewModelBase with Store { Timer _timer; + @action + Future confirmSending() async { + if (!isSendable) { + return; + } + + sendViewModel.address = trade.inputAddress; + sendViewModel.setCryptoAmount(trade.amount); + await sendViewModel.createTransaction(); + } + @action Future _updateTrade() async { try { diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index d49be63f7..32076d365 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -1,8 +1,8 @@ +import 'package:intl/intl.dart'; +import 'package:mobx/mobx.dart'; import 'package:cake_wallet/entities/openalias_record.dart'; import 'package:cake_wallet/entities/template.dart'; import 'package:cake_wallet/store/templates/send_template_store.dart'; -import 'package:intl/intl.dart'; -import 'package:mobx/mobx.dart'; import 'package:cake_wallet/core/template_validator.dart'; import 'package:cake_wallet/core/address_validator.dart'; import 'package:cake_wallet/core/amount_validator.dart';