diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index 727630f50..8811b677f 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -188,6 +188,7 @@ class ExchangePage extends BasePage { exchangeViewModel.isDepositAddressEnabled, isAmountEstimated: false, hasRefundAddress: true, + isMoneroWallet: exchangeViewModel.isMoneroWallet, currencies: CryptoCurrency.all, onCurrencySelected: (currency) { // FIXME: need to move it into view model @@ -260,6 +261,7 @@ class ExchangePage extends BasePage { exchangeViewModel .isReceiveAddressEnabled, isAmountEstimated: true, + isMoneroWallet: exchangeViewModel.isMoneroWallet, currencies: exchangeViewModel.receiveCurrencies, onCurrencySelected: (currency) => diff --git a/lib/src/screens/exchange/exchange_template_page.dart b/lib/src/screens/exchange/exchange_template_page.dart index fb90f5966..3708df87f 100644 --- a/lib/src/screens/exchange/exchange_template_page.dart +++ b/lib/src/screens/exchange/exchange_template_page.dart @@ -136,6 +136,7 @@ class ExchangeTemplatePage extends BasePage { .isDepositAddressEnabled, isAmountEstimated: false, hasRefundAddress: true, + isMoneroWallet: exchangeViewModel.isMoneroWallet, currencies: CryptoCurrency.all, onCurrencySelected: (currency) => exchangeViewModel.changeDepositCurrency( @@ -175,6 +176,7 @@ class ExchangeTemplatePage extends BasePage { initialIsAddressEditable: exchangeViewModel.isReceiveAddressEnabled, isAmountEstimated: true, + isMoneroWallet: exchangeViewModel.isMoneroWallet, currencies: exchangeViewModel.receiveCurrencies, onCurrencySelected: (currency) => exchangeViewModel.changeReceiveCurrency( diff --git a/lib/src/screens/exchange/widgets/exchange_card.dart b/lib/src/screens/exchange/widgets/exchange_card.dart index f534cccad..8b93f1db8 100644 --- a/lib/src/screens/exchange/widgets/exchange_card.dart +++ b/lib/src/screens/exchange/widgets/exchange_card.dart @@ -1,3 +1,5 @@ +import 'package:cake_wallet/entities/contact_base.dart'; +import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/services.dart'; @@ -19,6 +21,7 @@ class ExchangeCard extends StatefulWidget { this.initialIsAddressEditable, this.isAmountEstimated, this.hasRefundAddress = false, + this.isMoneroWallet = false, this.currencies, this.onCurrencySelected, this.imageArrow, @@ -44,6 +47,7 @@ class ExchangeCard extends StatefulWidget { final bool initialIsAddressEditable; final bool isAmountEstimated; final bool hasRefundAddress; + final bool isMoneroWallet; final Image imageArrow; final Color currencyButtonColor; final Color addressButtonsColor; @@ -72,6 +76,7 @@ class ExchangeCardState extends State { bool _isAmountEditable; bool _isAddressEditable; bool _isAmountEstimated; + bool _isMoneroWallet; @override void initState() { @@ -81,6 +86,7 @@ class ExchangeCardState extends State { _walletName = widget.initialWalletName; _selectedCurrency = widget.initialCurrency; _isAmountEstimated = widget.isAmountEstimated; + _isMoneroWallet = widget.isMoneroWallet; addressController.text = widget.initialAddress; super.initState(); } @@ -322,34 +328,93 @@ class ExchangeCardState extends State { : Padding( padding: EdgeInsets.only(top: 10), child: Builder( - builder: (context) => GestureDetector( - onTap: () { - Clipboard.setData( - ClipboardData(text: addressController.text)); - showBar( - context, S.of(context).copied_to_clipboard); - }, - child: Row( - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Text( - addressController.text, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Colors.white), - ), - ), - Padding( - padding: EdgeInsets.only(left: 16), - child: copyImage, + builder: (context) => Stack( + children: [ + BaseTextFormField( + controller: addressController, + readOnly: true, + borderColor: Colors.transparent, + suffixIcon: SizedBox( + width: _isMoneroWallet ? 80 : 36 + ), + textStyle: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Colors.white), + validator: widget.addressTextFieldValidator + ), + Positioned( + top: 2, + right: 0, + child: SizedBox( + width: _isMoneroWallet ? 80 : 36, + child: Row( + children: [ + if (_isMoneroWallet) Padding( + padding: EdgeInsets.only(left: 10), + child: Container( + width: 34, + height: 34, + padding: EdgeInsets.only(top: 0), + child: InkWell( + onTap: () async { + final contact = await Navigator + .of(context, rootNavigator: true) + .pushNamed( + Routes.pickerAddressBook); + + if (contact is ContactBase && + contact.address != null) { + setState(() => + addressController.text = + contact.address); + } + }, + child: Container( + padding: EdgeInsets.all(8), + decoration: BoxDecoration( + color: widget + .addressButtonsColor, + borderRadius: BorderRadius + .all(Radius.circular(6))), + child: Image.asset( + 'assets/images/open_book.png', + color: Theme.of(context) + .primaryTextTheme + .display1 + .decorationColor, + )), + )), + ), + Padding( + padding: EdgeInsets.only(left: 2), + child: Container( + width: 34, + height: 34, + padding: EdgeInsets.only(top: 0), + child: InkWell( + onTap: () { + Clipboard.setData( + ClipboardData( + text: addressController.text)); + showBar( + context, S.of(context) + .copied_to_clipboard); + }, + child: Container( + padding: EdgeInsets + .fromLTRB(8, 8, 0, 8), + color: Colors.transparent, + child: copyImage), + )) + ) + ] ) - ], - ), - )), + ) + ) + ] + ) + ), ), ]), ); diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 01246542b..97034358c 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -9,6 +9,7 @@ import 'package:cake_wallet/exchange/exchange_provider.dart'; import 'package:cake_wallet/exchange/limits.dart'; import 'package:cake_wallet/exchange/trade.dart'; import 'package:cake_wallet/exchange/limits_state.dart'; +import 'package:cake_wallet/monero/monero_wallet.dart'; import 'package:cake_wallet/store/dashboard/trades_store.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:intl/intl.dart'; @@ -125,6 +126,8 @@ abstract class ExchangeViewModelBase with Store { bool get hasAllAmount => wallet.type == WalletType.bitcoin && depositCurrency == wallet.currency; + bool get isMoneroWallet => wallet is MoneroWallet; + List receiveCurrencies; Limits limits;