Notify user when a different currency is scanned

This commit is contained in:
OmarHatem28
2022-08-09 17:06:21 +02:00
parent 7bccf46832
commit e5fac16ef7
19 changed files with 69 additions and 37 deletions
+5 -12
View File
@@ -232,18 +232,11 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
void handleDeepLinking(Uri uri) {
if (uri == null || !mounted) return;
switch (uri.scheme) {
case "bitcoin":
case "litecoin":
case "haven":
case "monero":
default:
Navigator.pushNamed(
navigatorKey.currentContext,
Routes.send,
arguments: PaymentRequest.fromUri(uri),
);
}
Navigator.pushNamed(
navigatorKey.currentContext,
Routes.send,
arguments: PaymentRequest.fromUri(uri),
);
}
Future<void> _handleInitialUri() async {
+27 -8
View File
@@ -1,4 +1,5 @@
import 'dart:ui';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/payment_request.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cake_wallet/routes.dart';
@@ -45,8 +46,8 @@ class SendCardState extends State<SendCard>
SendCardState({
@required this.output,
@required this.sendViewModel,
PaymentRequest initialPaymentRequest})
: addressController = TextEditingController(text: initialPaymentRequest?.address),
this.initialPaymentRequest})
: addressController = TextEditingController(text: initialPaymentRequest?.address?.toLowerCase()),
cryptoAmountController = TextEditingController(text: initialPaymentRequest?.amount),
fiatAmountController = TextEditingController(),
noteController = TextEditingController(),
@@ -60,6 +61,7 @@ class SendCardState extends State<SendCard>
final Output output;
final SendViewModel sendViewModel;
final PaymentRequest initialPaymentRequest;
final TextEditingController addressController;
final TextEditingController cryptoAmountController;
@@ -72,6 +74,27 @@ class SendCardState extends State<SendCard>
bool _effectsInstalled = false;
@override
void initState() {
super.initState();
/// if the current wallet doesn't match the one in the qr code
if (initialPaymentRequest != null &&
sendViewModel.walletCurrencyName != initialPaymentRequest.scheme?.toLowerCase()) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: S.of(context).error,
alertContent: S.of(context).unmatched_currencies,
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
});
}
}
@override
Widget build(BuildContext context) {
super.build(context);
@@ -123,11 +146,6 @@ class SendCardState extends State<SendCard>
? sendViewModel.textValidator
: sendViewModel.addressValidator;
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
print("444444444444444444444444444444");
print(addressController.text);
print(cryptoAmountController.text);
return AddressTextField(
focusNode: addressFocusNode,
controller: addressController,
@@ -529,7 +547,8 @@ class SendCardState extends State<SendCard>
if (output.address.isNotEmpty) {
addressController.text = output.address;
}
if (output.cryptoAmount.isNotEmpty) {
if (output.cryptoAmount.isNotEmpty ||
sendViewModel.walletCurrencyName != initialPaymentRequest?.scheme?.toLowerCase()) {
cryptoAmountController.text = output.cryptoAmount;
}
fiatAmountController.text = output.fiatAmount;
+5 -2
View File
@@ -1,18 +1,21 @@
class PaymentRequest {
PaymentRequest(this.address, this.amount);
PaymentRequest(this.address, this.amount, {this.scheme});
factory PaymentRequest.fromUri(Uri uri) {
var address = "";
var amount = "";
var scheme = "";
if (uri != null) {
address = uri.path;
amount = uri.queryParameters['tx_amount'] ?? uri.queryParameters['amount'] ?? "";
scheme = uri.scheme;
}
return PaymentRequest(address, amount);
return PaymentRequest(address, amount, scheme: scheme);
}
final String address;
final String amount;
final String scheme;
}
+2
View File
@@ -157,6 +157,8 @@ abstract class SendViewModelBase with Store {
WalletType get walletType => _wallet.type;
String get walletCurrencyName => _wallet.currency.name.toLowerCase();
bool get hasCurrecyChanger => walletType == WalletType.haven;
final WalletBase _wallet;