CAKE-343 | added address book button to xmr wallet's address text field on exchange_page.dart and exchange_template_page.dart

OleksandrSobol committed Jul 23, 2021 at 14:05 UTC 1d996c94c88f1aa4457a376d5ed86965a77765f7
4 files changed +99 -27
lib/src/screens/exchange/exchange_page.dart
+2
@@ -188,6 +188,7 @@ class ExchangePage extends BasePage {
188 exchangeViewModel.isDepositAddressEnabled,
189 isAmountEstimated: false,
190 hasRefundAddress: true,
191 + isMoneroWallet: exchangeViewModel.isMoneroWallet,
192 currencies: CryptoCurrency.all,
193 onCurrencySelected: (currency) {
194 // FIXME: need to move it into view model
@@ -260,6 +261,7 @@ class ExchangePage extends BasePage {
261 exchangeViewModel
262 .isReceiveAddressEnabled,
263 isAmountEstimated: true,
264 + isMoneroWallet: exchangeViewModel.isMoneroWallet,
265 currencies:
266 exchangeViewModel.receiveCurrencies,
267 onCurrencySelected: (currency) =>
lib/src/screens/exchange/exchange_template_page.dart
+2
@@ -136,6 +136,7 @@ class ExchangeTemplatePage extends BasePage {
136 .isDepositAddressEnabled,
137 isAmountEstimated: false,
138 hasRefundAddress: true,
139 + isMoneroWallet: exchangeViewModel.isMoneroWallet,
140 currencies: CryptoCurrency.all,
141 onCurrencySelected: (currency) =>
142 exchangeViewModel.changeDepositCurrency(
@@ -175,6 +176,7 @@ class ExchangeTemplatePage extends BasePage {
176 initialIsAddressEditable:
177 exchangeViewModel.isReceiveAddressEnabled,
178 isAmountEstimated: true,
179 + isMoneroWallet: exchangeViewModel.isMoneroWallet,
180 currencies: exchangeViewModel.receiveCurrencies,
181 onCurrencySelected: (currency) =>
182 exchangeViewModel.changeReceiveCurrency(
lib/src/screens/exchange/widgets/exchange_card.dart
+92 -27
@@ -1,3 +1,5 @@
1 +import 'package:cake_wallet/entities/contact_base.dart';
2 +import 'package:cake_wallet/routes.dart';
3 import 'package:cake_wallet/utils/show_bar.dart';
4 import 'package:cake_wallet/utils/show_pop_up.dart';
5 import 'package:flutter/services.dart';
@@ -19,6 +21,7 @@ class ExchangeCard extends StatefulWidget {
21 this.initialIsAddressEditable,
22 this.isAmountEstimated,
23 this.hasRefundAddress = false,
24 + this.isMoneroWallet = false,
25 this.currencies,
26 this.onCurrencySelected,
27 this.imageArrow,
@@ -44,6 +47,7 @@ class ExchangeCard extends StatefulWidget {
47 final bool initialIsAddressEditable;
48 final bool isAmountEstimated;
49 final bool hasRefundAddress;
50 + final bool isMoneroWallet;
51 final Image imageArrow;
52 final Color currencyButtonColor;
53 final Color addressButtonsColor;
@@ -72,6 +76,7 @@ class ExchangeCardState extends State<ExchangeCard> {
76 bool _isAmountEditable;
77 bool _isAddressEditable;
78 bool _isAmountEstimated;
79 + bool _isMoneroWallet;
80
81 @override
82 void initState() {
@@ -81,6 +86,7 @@ class ExchangeCardState extends State<ExchangeCard> {
86 _walletName = widget.initialWalletName;
87 _selectedCurrency = widget.initialCurrency;
88 _isAmountEstimated = widget.isAmountEstimated;
89 + _isMoneroWallet = widget.isMoneroWallet;
90 addressController.text = widget.initialAddress;
91 super.initState();
92 }
@@ -322,34 +328,93 @@ class ExchangeCardState extends State<ExchangeCard> {
328 : Padding(
329 padding: EdgeInsets.only(top: 10),
330 child: Builder(
325 - builder: (context) => GestureDetector(
326 - onTap: () {
327 - Clipboard.setData(
328 - ClipboardData(text: addressController.text));
329 - showBar<void>(
330 - context, S.of(context).copied_to_clipboard);
331 - },
332 - child: Row(
333 - mainAxisSize: MainAxisSize.max,
334 - children: <Widget>[
335 - Expanded(
336 - child: Text(
337 - addressController.text,
338 - maxLines: 1,
339 - overflow: TextOverflow.ellipsis,
340 - style: TextStyle(
341 - fontSize: 16,
342 - fontWeight: FontWeight.w600,
343 - color: Colors.white),
344 - ),
345 - ),
346 - Padding(
347 - padding: EdgeInsets.only(left: 16),
348 - child: copyImage,
331 + builder: (context) => Stack(
332 + children: <Widget> [
333 + BaseTextFormField(
334 + controller: addressController,
335 + readOnly: true,
336 + borderColor: Colors.transparent,
337 + suffixIcon: SizedBox(
338 + width: _isMoneroWallet ? 80 : 36
339 + ),
340 + textStyle: TextStyle(
341 + fontSize: 16,
342 + fontWeight: FontWeight.w600,
343 + color: Colors.white),
344 + validator: widget.addressTextFieldValidator
345 + ),
346 + Positioned(
347 + top: 2,
348 + right: 0,
349 + child: SizedBox(
350 + width: _isMoneroWallet ? 80 : 36,
351 + child: Row(
352 + children: <Widget>[
353 + if (_isMoneroWallet) Padding(
354 + padding: EdgeInsets.only(left: 10),
355 + child: Container(
356 + width: 34,
357 + height: 34,
358 + padding: EdgeInsets.only(top: 0),
359 + child: InkWell(
360 + onTap: () async {
361 + final contact = await Navigator
362 + .of(context, rootNavigator: true)
363 + .pushNamed(
364 + Routes.pickerAddressBook);
365 +
366 + if (contact is ContactBase &&
367 + contact.address != null) {
368 + setState(() =>
369 + addressController.text =
370 + contact.address);
371 + }
372 + },
373 + child: Container(
374 + padding: EdgeInsets.all(8),
375 + decoration: BoxDecoration(
376 + color: widget
377 + .addressButtonsColor,
378 + borderRadius: BorderRadius
379 + .all(Radius.circular(6))),
380 + child: Image.asset(
381 + 'assets/images/open_book.png',
382 + color: Theme.of(context)
383 + .primaryTextTheme
384 + .display1
385 + .decorationColor,
386 + )),
387 + )),
388 + ),
389 + Padding(
390 + padding: EdgeInsets.only(left: 2),
391 + child: Container(
392 + width: 34,
393 + height: 34,
394 + padding: EdgeInsets.only(top: 0),
395 + child: InkWell(
396 + onTap: () {
397 + Clipboard.setData(
398 + ClipboardData(
399 + text: addressController.text));
400 + showBar<void>(
401 + context, S.of(context)
402 + .copied_to_clipboard);
403 + },
404 + child: Container(
405 + padding: EdgeInsets
406 + .fromLTRB(8, 8, 0, 8),
407 + color: Colors.transparent,
408 + child: copyImage),
409 + ))
410 + )
411 + ]
412 )
350 - ],
351 - ),
352 - )),
413 + )
414 + )
415 + ]
416 + )
417 + ),
418 ),
419 ]),
420 );
lib/view_model/exchange/exchange_view_model.dart
+3
@@ -9,6 +9,7 @@ import 'package:cake_wallet/exchange/exchange_provider.dart';
9 import 'package:cake_wallet/exchange/limits.dart';
10 import 'package:cake_wallet/exchange/trade.dart';
11 import 'package:cake_wallet/exchange/limits_state.dart';
12 +import 'package:cake_wallet/monero/monero_wallet.dart';
13 import 'package:cake_wallet/store/dashboard/trades_store.dart';
14 import 'package:cake_wallet/store/settings_store.dart';
15 import 'package:intl/intl.dart';
@@ -125,6 +126,8 @@ abstract class ExchangeViewModelBase with Store {
126 bool get hasAllAmount =>
127 wallet.type == WalletType.bitcoin && depositCurrency == wallet.currency;
128
129 + bool get isMoneroWallet => wallet is MoneroWallet;
130 +
131 List<CryptoCurrency> receiveCurrencies;
132
133 Limits limits;