diff --git a/lib/src/screens/exchange/widgets/exchange_card.dart b/lib/src/screens/exchange/widgets/exchange_card.dart index b86d1cf63..ec57323ac 100644 --- a/lib/src/screens/exchange/widgets/exchange_card.dart +++ b/lib/src/screens/exchange/widgets/exchange_card.dart @@ -1,7 +1,9 @@ import 'package:cake_wallet/entities/contact_base.dart'; import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/generated/i18n.dart'; @@ -308,6 +310,16 @@ class ExchangeCardState extends State { child: AddressTextField( focusNode: widget.addressFocusNode, controller: addressController, + onURIScanned: (uri) { + final paymentRequest = PaymentRequest.fromUri(uri); + addressController.text = paymentRequest.address; + + if (amountController.text.isNotEmpty) { + _showAmountPopup(context, paymentRequest); + } else { + amountController.text = paymentRequest.amount; + } + }, placeholder: widget.hasRefundAddress ? S.of(context).refund_address : null, @@ -331,7 +343,9 @@ class ExchangeCardState extends State { buttonColor: widget.addressButtonsColor, validator: widget.addressTextFieldValidator, onPushPasteButton: widget.onPushPasteButton, - onPushAddressBookButton: widget.onPushAddressBookButton), + onPushAddressBookButton: widget.onPushAddressBookButton + ), + ) : Padding( padding: EdgeInsets.only(top: 10), @@ -440,4 +454,22 @@ class ExchangeCardState extends State { : null), context: context); } + + void _showAmountPopup(BuildContext context, PaymentRequest paymentRequest) { + showPopUp( + context: context, + builder: (dialogContext) { + return AlertWithTwoActions( + alertTitle: S.of(context).overwrite_amount, + alertContent: S.of(context).qr_payment_amount, + rightButtonText: S.of(context).ok, + leftButtonText: S.of(context).cancel, + actionRightButton: () { + amountController.text = paymentRequest.amount; + Navigator.of(context).pop(); + }, + actionLeftButton: () => Navigator.of(dialogContext).pop()); + } + ); + } } diff --git a/lib/src/screens/send/send_template_page.dart b/lib/src/screens/send/send_template_page.dart index 0d3ed4d70..a3e0b8928 100644 --- a/lib/src/screens/send/send_template_page.dart +++ b/lib/src/screens/send/send_template_page.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:mobx/mobx.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -109,19 +110,9 @@ class SendTemplatePage extends BasePage { child: AddressTextField( controller: _addressController, onURIScanned: (uri) { - var address = ''; - var amount = ''; - - if (uri != null) { - address = uri.path; - amount = uri.queryParameters['tx_amount'] ?? - uri.queryParameters['amount']; - } else { - address = uri.toString(); - } - - _addressController.text = address; - _cryptoAmountController.text = amount; + final paymentRequest = PaymentRequest.fromUri(uri); + _addressController.text = paymentRequest.address; + _cryptoAmountController.text = paymentRequest.amount; }, options: [ AddressTextFieldOption.paste, diff --git a/lib/src/screens/send/widgets/send_card.dart b/lib/src/screens/send/widgets/send_card.dart index 7782524f2..eb110f3b1 100644 --- a/lib/src/screens/send/widgets/send_card.dart +++ b/lib/src/screens/send/widgets/send_card.dart @@ -1,4 +1,5 @@ import 'dart:ui'; +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; @@ -114,19 +115,9 @@ class SendCardState extends State focusNode: addressFocusNode, controller: addressController, onURIScanned: (uri) { - var address = ''; - var amount = ''; - - if (uri != null) { - address = uri.path; - amount = uri.queryParameters['tx_amount'] ?? - uri.queryParameters['amount']; - } else { - address = uri.toString(); - } - - addressController.text = address; - cryptoAmountController.text = amount; + final paymentRequest = PaymentRequest.fromUri(uri); + addressController.text = paymentRequest.address; + cryptoAmountController.text = paymentRequest.amount; }, options: [ AddressTextFieldOption.paste, diff --git a/lib/src/widgets/address_text_field.dart b/lib/src/widgets/address_text_field.dart index fbdc3ed54..81eaa9313 100644 --- a/lib/src/widgets/address_text_field.dart +++ b/lib/src/widgets/address_text_field.dart @@ -193,6 +193,9 @@ class AddressTextField extends StatelessWidget { Future _presentQRScanner(BuildContext context) async { try { final code = await presentQRScanner(); + if (code.isEmpty) { + return; + } final uri = Uri.parse(code); var address = ''; diff --git a/lib/utils/payment_request.dart b/lib/utils/payment_request.dart new file mode 100644 index 000000000..d4338a39a --- /dev/null +++ b/lib/utils/payment_request.dart @@ -0,0 +1,18 @@ +class PaymentRequest { + PaymentRequest(this.address, this.amount); + + factory PaymentRequest.fromUri(Uri uri) { + var address = ""; + var amount = ""; + + if (uri != null) { + address = uri.path; + amount = uri.queryParameters['tx_amount'] ?? uri.queryParameters['amount'] ?? ""; + } + + return PaymentRequest(address, amount); + } + + final String address; + final String amount; +} \ No newline at end of file diff --git a/res/values/strings_de.arb b/res/values/strings_de.arb index c65b1a9e7..b29cbf053 100644 --- a/res/values/strings_de.arb +++ b/res/values/strings_de.arb @@ -78,7 +78,8 @@ "min_value" : "Min: ${value} ${currency}", "max_value" : "Max: ${value} ${currency}", "change_currency" : "Währung ändern", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "ID kopieren", "exchange_result_write_down_trade_id" : "Bitte kopieren oder notieren Sie die Handels-ID, um fortzufahren.", diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index d6c99a594..2de02e8b8 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -78,7 +78,8 @@ "min_value" : "Min: ${value} ${currency}", "max_value" : "Max: ${value} ${currency}", "change_currency" : "Change Currency", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Copy ID", "exchange_result_write_down_trade_id" : "Please copy or write down the trade ID to continue.", diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb index 2ccf30077..a3cbb755a 100644 --- a/res/values/strings_es.arb +++ b/res/values/strings_es.arb @@ -78,7 +78,8 @@ "min_value" : "Min: ${value} ${currency}", "max_value" : "Max: ${value} ${currency}", "change_currency" : "Cambiar moneda", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Copiar ID", "exchange_result_write_down_trade_id" : "Por favor, copia o escribe el ID.", diff --git a/res/values/strings_fr.arb b/res/values/strings_fr.arb index 8f736246e..7e373a3af 100644 --- a/res/values/strings_fr.arb +++ b/res/values/strings_fr.arb @@ -76,7 +76,8 @@ "min_value" : "Min: ${value} ${currency}", "max_value" : "Max: ${value} ${currency}", "change_currency" : "Changer de Devise", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Copier l'ID", "exchange_result_write_down_trade_id" : "Merci de copier ou d'écrire l'ID d'échange pour continuer.", diff --git a/res/values/strings_hi.arb b/res/values/strings_hi.arb index d6ff77d76..6baae968c 100644 --- a/res/values/strings_hi.arb +++ b/res/values/strings_hi.arb @@ -78,7 +78,8 @@ "min_value" : "मिन: ${value} ${currency}", "max_value" : "मैक्स: ${value} ${currency}", "change_currency" : "मुद्रा परिवर्तन करें", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "प्रतिलिपि ID", "exchange_result_write_down_trade_id" : "जारी रखने के लिए कृपया ट्रेड ID की प्रतिलिपि बनाएँ या लिखें.", diff --git a/res/values/strings_hr.arb b/res/values/strings_hr.arb index 34f99adb8..5650fd30e 100644 --- a/res/values/strings_hr.arb +++ b/res/values/strings_hr.arb @@ -78,7 +78,8 @@ "min_value" : "Min.: ${value} ${currency}", "max_value" : "Maks.: ${value} ${currency}", "change_currency" : "Promijenite valutu", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Kopirati ID", "exchange_result_write_down_trade_id" : "Molimo kopirajte ili zapišite transakcijski ID za nastavak.", diff --git a/res/values/strings_it.arb b/res/values/strings_it.arb index 3cd380159..715698d31 100644 --- a/res/values/strings_it.arb +++ b/res/values/strings_it.arb @@ -78,7 +78,8 @@ "min_value" : "Min: ${value} ${currency}", "max_value" : "Max: ${value} ${currency}", "change_currency" : "Cambia Moneta", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Copia ID", "exchange_result_write_down_trade_id" : "Gentilmente fai una copia o trascrivi l'ID dello scambio per continuare.", diff --git a/res/values/strings_ja.arb b/res/values/strings_ja.arb index 5a47c7c40..410fe3a89 100644 --- a/res/values/strings_ja.arb +++ b/res/values/strings_ja.arb @@ -78,7 +78,8 @@ "min_value" : "分: ${value} ${currency}", "max_value" : "マックス: ${value} ${currency}", "change_currency" : "通貨を変更する", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "IDをコピー", "exchange_result_write_down_trade_id" : "続行するには、取引IDをコピーまたは書き留めてください.", diff --git a/res/values/strings_ko.arb b/res/values/strings_ko.arb index 6c0f08af4..bec483e44 100644 --- a/res/values/strings_ko.arb +++ b/res/values/strings_ko.arb @@ -78,7 +78,8 @@ "min_value" : "최소: ${value} ${currency}", "max_value" : "맥스: ${value} ${currency}", "change_currency" : "통화 변경", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "부 ID", "exchange_result_write_down_trade_id" : "계속하려면 거래 ID를 복사하거나 적어 두십시오..", diff --git a/res/values/strings_nl.arb b/res/values/strings_nl.arb index 21e1ed0b4..8987df4ec 100644 --- a/res/values/strings_nl.arb +++ b/res/values/strings_nl.arb @@ -78,7 +78,8 @@ "min_value" : "Min: ${value} ${currency}", "max_value" : "Max: ${value} ${currency}", "change_currency" : "Verander valuta", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "ID kopiëren", "exchange_result_write_down_trade_id" : "Kopieer of noteer de handels-ID om door te gaan.", diff --git a/res/values/strings_pl.arb b/res/values/strings_pl.arb index c47c566ae..7249c88b0 100644 --- a/res/values/strings_pl.arb +++ b/res/values/strings_pl.arb @@ -81,7 +81,8 @@ "min_value" : "Min: ${value} ${currency}", "max_value" : "Max: ${value} ${currency}", "change_currency" : "Change Currency", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "ID kopii", "exchange_result_write_down_trade_id" : "Skopiuj lub zanotuj identyfikator transakcji, aby kontynuować.", diff --git a/res/values/strings_pt.arb b/res/values/strings_pt.arb index 0f692d0b7..15db684fd 100644 --- a/res/values/strings_pt.arb +++ b/res/values/strings_pt.arb @@ -78,7 +78,8 @@ "min_value" : "Mín: ${value} ${currency}", "max_value" : "Máx: ${value} ${currency}", "change_currency" : "Alterar moeda", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Copiar ID", "exchange_result_write_down_trade_id" : "Copie ou anote o ID da troca para continuar.", diff --git a/res/values/strings_ru.arb b/res/values/strings_ru.arb index 127ea5114..2719e82ee 100644 --- a/res/values/strings_ru.arb +++ b/res/values/strings_ru.arb @@ -78,7 +78,8 @@ "min_value" : "Мин: ${value} ${currency}", "max_value" : "Макс: ${value} ${currency}", "change_currency" : "Изменить валюту", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Скопировать ID", "exchange_result_write_down_trade_id" : "Пожалуйста, скопируйте или запишите ID сделки.", diff --git a/res/values/strings_uk.arb b/res/values/strings_uk.arb index 94ea5b7d4..383f812f0 100644 --- a/res/values/strings_uk.arb +++ b/res/values/strings_uk.arb @@ -78,7 +78,8 @@ "min_value" : "Мін: ${value} ${currency}", "max_value" : "Макс: ${value} ${currency}", "change_currency" : "Змінити валюту", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "Скопіювати ID", "exchange_result_write_down_trade_id" : "Будь ласка, скопіюйте або запишіть ID операції.", diff --git a/res/values/strings_zh.arb b/res/values/strings_zh.arb index 0fe27248f..787d7bd58 100644 --- a/res/values/strings_zh.arb +++ b/res/values/strings_zh.arb @@ -78,7 +78,8 @@ "min_value" : "最低: ${value} ${currency}", "max_value" : "最高: ${value} ${currency}", "change_currency" : "更改币种", - + "overwrite_amount" : "Overwrite amount", + "qr_payment_amount" : "This QR code contains a payment amount. Do you want to overwrite the current value?", "copy_id" : "复制ID", "exchange_result_write_down_trade_id" : "请复制或写下交易编号以继续.",