Notify user when a different currency is scanned
OmarHatem28 committed
Aug 9, 2022 at 17:06 UTC
e5fac16ef77ec032b768762913dfcae62802267d
19 files changed
+69
-37
lib/main.dart
+5
-12
@@ -232,18 +232,11 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
232
void handleDeepLinking(Uri uri) {
233
if (uri == null || !mounted) return;
234
235
- switch (uri.scheme) {
236
- case "bitcoin":
237
- case "litecoin":
238
- case "haven":
239
- case "monero":
240
- default:
241
- Navigator.pushNamed(
242
- navigatorKey.currentContext,
243
- Routes.send,
244
- arguments: PaymentRequest.fromUri(uri),
245
- );
246
- }
235
+ Navigator.pushNamed(
236
+ navigatorKey.currentContext,
237
+ Routes.send,
238
+ arguments: PaymentRequest.fromUri(uri),
239
+ );
240
}
241
242
Future<void> _handleInitialUri() async {
lib/src/screens/send/widgets/send_card.dart
+27
-8
@@ -1,4 +1,5 @@
1
import 'dart:ui';
2
+import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
3
import 'package:cake_wallet/utils/payment_request.dart';
4
import 'package:cw_core/transaction_priority.dart';
5
import 'package:cake_wallet/routes.dart';
@@ -45,8 +46,8 @@ class SendCardState extends State<SendCard>
46
SendCardState({
47
@required this.output,
48
@required this.sendViewModel,
48
- PaymentRequest initialPaymentRequest})
49
- : addressController = TextEditingController(text: initialPaymentRequest?.address),
49
+ this.initialPaymentRequest})
50
+ : addressController = TextEditingController(text: initialPaymentRequest?.address?.toLowerCase()),
51
cryptoAmountController = TextEditingController(text: initialPaymentRequest?.amount),
52
fiatAmountController = TextEditingController(),
53
noteController = TextEditingController(),
@@ -60,6 +61,7 @@ class SendCardState extends State<SendCard>
61
62
final Output output;
63
final SendViewModel sendViewModel;
64
+ final PaymentRequest initialPaymentRequest;
65
66
final TextEditingController addressController;
67
final TextEditingController cryptoAmountController;
@@ -72,6 +74,27 @@ class SendCardState extends State<SendCard>
74
75
bool _effectsInstalled = false;
76
77
+ @override
78
+ void initState() {
79
+ super.initState();
80
+
81
+ /// if the current wallet doesn't match the one in the qr code
82
+ if (initialPaymentRequest != null &&
83
+ sendViewModel.walletCurrencyName != initialPaymentRequest.scheme?.toLowerCase()) {
84
+ WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
85
+ showPopUp<void>(
86
+ context: context,
87
+ builder: (BuildContext context) {
88
+ return AlertWithOneAction(
89
+ alertTitle: S.of(context).error,
90
+ alertContent: S.of(context).unmatched_currencies,
91
+ buttonText: S.of(context).ok,
92
+ buttonAction: () => Navigator.of(context).pop());
93
+ });
94
+ });
95
+ }
96
+ }
97
+
98
@override
99
Widget build(BuildContext context) {
100
super.build(context);
@@ -123,11 +146,6 @@ class SendCardState extends State<SendCard>
146
? sendViewModel.textValidator
147
: sendViewModel.addressValidator;
148
126
- print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
127
- print("444444444444444444444444444444");
128
- print(addressController.text);
129
- print(cryptoAmountController.text);
130
-
149
return AddressTextField(
150
focusNode: addressFocusNode,
151
controller: addressController,
@@ -529,7 +547,8 @@ class SendCardState extends State<SendCard>
547
if (output.address.isNotEmpty) {
548
addressController.text = output.address;
549
}
532
- if (output.cryptoAmount.isNotEmpty) {
550
+ if (output.cryptoAmount.isNotEmpty ||
551
+ sendViewModel.walletCurrencyName != initialPaymentRequest?.scheme?.toLowerCase()) {
552
cryptoAmountController.text = output.cryptoAmount;
553
}
554
fiatAmountController.text = output.fiatAmount;
lib/utils/payment_request.dart
+5
-2
@@ -1,18 +1,21 @@
1
class PaymentRequest {
2
- PaymentRequest(this.address, this.amount);
2
+ PaymentRequest(this.address, this.amount, {this.scheme});
3
4
factory PaymentRequest.fromUri(Uri uri) {
5
var address = "";
6
var amount = "";
7
+ var scheme = "";
8
9
if (uri != null) {
10
address = uri.path;
11
amount = uri.queryParameters['tx_amount'] ?? uri.queryParameters['amount'] ?? "";
12
+ scheme = uri.scheme;
13
}
14
13
- return PaymentRequest(address, amount);
15
+ return PaymentRequest(address, amount, scheme: scheme);
16
}
17
18
final String address;
19
final String amount;
20
+ final String scheme;
21
}
\ No newline at end of file
lib/view_model/send/send_view_model.dart
+2
@@ -157,6 +157,8 @@ abstract class SendViewModelBase with Store {
157
158
WalletType get walletType => _wallet.type;
159
160
+ String get walletCurrencyName => _wallet.currency.name.toLowerCase();
161
+
162
bool get hasCurrecyChanger => walletType == WalletType.haven;
163
164
final WalletBase _wallet;
res/values/strings_de.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Geschenkkarte wird generiert",
633
"open_gift_card": "Geschenkkarte öffnen",
634
"contact_support": "Support kontaktieren",
635
- "gift_cards_unavailable": "Geschenkkarten können derzeit nur über Monero, Bitcoin und Litecoin erworben werden"
635
+ "gift_cards_unavailable": "Geschenkkarten können derzeit nur über Monero, Bitcoin und Litecoin erworben werden",
636
+ "unmatched_currencies": "Die Währung Ihres aktuellen Wallets stimmt nicht mit der des gescannten QR überein"
637
}
res/values/strings_en.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Gift Card is generated",
633
"open_gift_card": "Open Gift Card",
634
"contact_support": "Contact Support",
635
- "gift_cards_unavailable": "Gift cards are available for purchase only with Monero, Bitcoin, and Litecoin at this time"
635
+ "gift_cards_unavailable": "Gift cards are available for purchase only with Monero, Bitcoin, and Litecoin at this time",
636
+ "unmatched_currencies": "Your current wallet's currency does not match that of the scanned QR"
637
}
res/values/strings_es.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Se genera la tarjeta de regalo",
633
"open_gift_card": "Abrir tarjeta de regalo",
634
"contact_support": "Contactar con Soporte",
635
- "gift_cards_unavailable": "Las tarjetas de regalo están disponibles para comprar solo a través de Monero, Bitcoin y Litecoin en este momento"
635
+ "gift_cards_unavailable": "Las tarjetas de regalo están disponibles para comprar solo a través de Monero, Bitcoin y Litecoin en este momento",
636
+ "unmatched_currencies": "La moneda de su billetera actual no coincide con la del QR escaneado"
637
}
res/values/strings_fr.arb
+2
-1
@@ -630,5 +630,6 @@
630
"gift_card_is_generated": "La carte-cadeau est générée",
631
"open_gift_card": "Ouvrir la carte-cadeau",
632
"contact_support": "Contacter l'assistance",
633
- "gift_cards_unavailable": "Les cartes-cadeaux ne sont disponibles à l'achat que via Monero, Bitcoin et Litecoin pour le moment"
633
+ "gift_cards_unavailable": "Les cartes-cadeaux ne sont disponibles à l'achat que via Monero, Bitcoin et Litecoin pour le moment",
634
+ "unmatched_currencies": "La devise de votre portefeuille actuel ne correspond pas à celle du QR scanné"
635
}
res/values/strings_hi.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "गिफ्ट कार्ड जनरेट हुआ",
633
"open_gift_card": "गिफ्ट कार्ड खोलें",
634
"contact_support": "सहायता से संपर्क करें",
635
- "gift_cards_unavailable": "उपहार कार्ड इस समय केवल मोनेरो, बिटकॉइन और लिटकोइन के माध्यम से खरीदने के लिए उपलब्ध हैं"
635
+ "gift_cards_unavailable": "उपहार कार्ड इस समय केवल मोनेरो, बिटकॉइन और लिटकोइन के माध्यम से खरीदने के लिए उपलब्ध हैं",
636
+ "unmatched_currencies": "आपके वर्तमान वॉलेट की मुद्रा स्कैन किए गए क्यूआर से मेल नहीं खाती"
637
}
res/values/strings_hr.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Poklon kartica je generirana",
633
"open_gift_card": "Otvori darovnu karticu",
634
"contact_support": "Kontaktirajte podršku",
635
- "gift_cards_unavailable": "Poklon kartice trenutno su dostupne za kupnju samo putem Monera, Bitcoina i Litecoina"
635
+ "gift_cards_unavailable": "Poklon kartice trenutno su dostupne za kupnju samo putem Monera, Bitcoina i Litecoina",
636
+ "unmatched_currencies": "Valuta vašeg trenutnog novčanika ne odgovara onoj na skeniranom QR-u"
637
}
res/values/strings_it.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Il buono regalo è stato generato",
633
"open_gift_card": "Apri carta regalo",
634
"contact_support": "Contatta l'assistenza",
635
- "gift_cards_unavailable": "Le carte regalo sono disponibili per l'acquisto solo tramite Monero, Bitcoin e Litecoin in questo momento"
635
+ "gift_cards_unavailable": "Le carte regalo sono disponibili per l'acquisto solo tramite Monero, Bitcoin e Litecoin in questo momento",
636
+ "unmatched_currencies": "La valuta del tuo portafoglio attuale non corrisponde a quella del QR scansionato"
637
}
res/values/strings_ja.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "ギフトカードが生成されます",
633
"open_gift_card": "オープンギフトカード",
634
"contact_support": "サポートに連絡する",
635
- "gift_cards_unavailable": "現時点では、ギフトカードはMonero、Bitcoin、Litecoinからのみ購入できます。"
635
+ "gift_cards_unavailable": "現時点では、ギフトカードはMonero、Bitcoin、Litecoinからのみ購入できます。",
636
+ "unmatched_currencies": "現在のウォレットの通貨がスキャンされたQRの通貨と一致しません"
637
}
res/values/strings_ko.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "기프트 카드가 생성되었습니다",
633
"open_gift_card": "기프트 카드 열기",
634
"contact_support": "지원팀에 문의",
635
- "gift_cards_unavailable": "기프트 카드는 현재 Monero, Bitcoin 및 Litecoin을 통해서만 구매할 수 있습니다."
635
+ "gift_cards_unavailable": "기프트 카드는 현재 Monero, Bitcoin 및 Litecoin을 통해서만 구매할 수 있습니다.",
636
+ "unmatched_currencies": "현재 지갑의 통화가 스캔한 QR의 통화와 일치하지 않습니다."
637
}
res/values/strings_nl.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Cadeaukaart is gegenereerd",
633
"open_gift_card": "Geschenkkaart openen",
634
"contact_support": "Contact opnemen met ondersteuning",
635
- "gift_cards_unavailable": "Cadeaubonnen kunnen momenteel alleen worden gekocht via Monero, Bitcoin en Litecoin"
635
+ "gift_cards_unavailable": "Cadeaubonnen kunnen momenteel alleen worden gekocht via Monero, Bitcoin en Litecoin",
636
+ "unmatched_currencies": "De valuta van uw huidige portemonnee komt niet overeen met die van de gescande QR"
637
}
res/values/strings_pl.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Karta podarunkowa jest generowana",
633
"open_gift_card": "Otwórz kartę podarunkową",
634
"contact_support": "Skontaktuj się z pomocą techniczną",
635
- "gift_cards_unavailable": "Karty podarunkowe można obecnie kupić tylko za pośrednictwem Monero, Bitcoin i Litecoin"
635
+ "gift_cards_unavailable": "Karty podarunkowe można obecnie kupić tylko za pośrednictwem Monero, Bitcoin i Litecoin",
636
+ "unmatched_currencies": "Waluta Twojego obecnego portfela nie odpowiada walucie zeskanowanego kodu QR"
637
}
res/values/strings_pt.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Cartão presente é gerado",
633
"open_gift_card": "Abrir vale-presente",
634
"contact_support": "Contatar Suporte",
635
- "gift_cards_unavailable": "Os cartões-presente estão disponíveis para compra apenas através do Monero, Bitcoin e Litecoin no momento"
635
+ "gift_cards_unavailable": "Os cartões-presente estão disponíveis para compra apenas através do Monero, Bitcoin e Litecoin no momento",
636
+ "unmatched_currencies": "A moeda da sua carteira atual não corresponde à do QR digitalizado"
637
}
res/values/strings_ru.arb
+2
-1
@@ -632,5 +632,6 @@
632
"gift_card_is_generated": "Подарочная карта сгенерирована",
633
"open_gift_card": "Открыть подарочную карту",
634
"contact_support": "Связаться со службой поддержки",
635
- "gift_cards_unavailable": "В настоящее время подарочные карты можно приобрести только через Monero, Bitcoin и Litecoin."
635
+ "gift_cards_unavailable": "В настоящее время подарочные карты можно приобрести только через Monero, Bitcoin и Litecoin.",
636
+ "unmatched_currencies": "Валюта вашего текущего кошелька не соответствует валюте отсканированного QR-кода."
637
}
res/values/strings_uk.arb
+2
-1
@@ -631,5 +631,6 @@
631
"gift_card_is_generated": "Подарункова картка створена",
632
"open_gift_card": "Відкрити подарункову картку",
633
"contact_support": "Звернутися до служби підтримки",
634
- "gift_cards_unavailable": "Наразі подарункові картки можна придбати лише через Monero, Bitcoin і Litecoin"
634
+ "gift_cards_unavailable": "Наразі подарункові картки можна придбати лише через Monero, Bitcoin і Litecoin",
635
+ "unmatched_currencies": "Валюта вашого гаманця не збігається з валютою сканованого QR-коду"
636
}
res/values/strings_zh.arb
+2
-1
@@ -630,5 +630,6 @@
630
"gift_card_is_generated": "礼品卡生成",
631
"open_gift_card": "打开礼品卡",
632
"contact_support": "联系支持",
633
- "gift_cards_unavailable": "目前只能通过门罗币、比特币和莱特币购买礼品卡"
633
+ "gift_cards_unavailable": "目前只能通过门罗币、比特币和莱特币购买礼品卡",
634
+ "unmatched_currencies": "您当前钱包的货币与扫描的 QR 的货币不匹配"
635
}