mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
cw-60: fill amount on scan qr on exchange page (#309)
* cw-60: fill amount on scan qr on exchange page
This commit is contained in:
parent
1cd90cf57d
commit
5890df86db
20 changed files with 92 additions and 42 deletions
|
@ -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<ExchangeCard> {
|
|||
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<ExchangeCard> {
|
|||
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<ExchangeCard> {
|
|||
: null),
|
||||
context: context);
|
||||
}
|
||||
|
||||
void _showAmountPopup(BuildContext context, PaymentRequest paymentRequest) {
|
||||
showPopUp<void>(
|
||||
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());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<SendCard>
|
|||
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,
|
||||
|
|
|
@ -193,6 +193,9 @@ class AddressTextField extends StatelessWidget {
|
|||
Future<void> _presentQRScanner(BuildContext context) async {
|
||||
try {
|
||||
final code = await presentQRScanner();
|
||||
if (code.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final uri = Uri.parse(code);
|
||||
var address = '';
|
||||
|
||||
|
|
18
lib/utils/payment_request.dart
Normal file
18
lib/utils/payment_request.dart
Normal file
|
@ -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;
|
||||
}
|
|
@ -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.",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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 की प्रतिलिपि बनाएँ या लिखें.",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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をコピーまたは書き留めてください.",
|
||||
|
|
|
@ -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를 복사하거나 적어 두십시오..",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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ć.",
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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 сделки.",
|
||||
|
|
|
@ -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 операції.",
|
||||
|
|
|
@ -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" : "请复制或写下交易编号以继续.",
|
||||
|
|
Loading…
Reference in a new issue