mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
CW-243-Better-error-message-for-too-many-decimals (#818)
* update amoung validation * fix decimal validator * minor fix
This commit is contained in:
parent
fc2627df38
commit
7dfc5b23bc
29 changed files with 78 additions and 23 deletions
|
@ -1,32 +1,59 @@
|
|||
import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
class AmountValidator extends TextValidator {
|
||||
AmountValidator({required WalletType type, bool isAutovalidate = false})
|
||||
AmountValidator({required CryptoCurrency currency, bool isAutovalidate = false}) {
|
||||
symbolsAmountValidator =
|
||||
SymbolsAmountValidator(isAutovalidate: isAutovalidate);
|
||||
decimalAmountValidator = DecimalAmountValidator(currency: currency);
|
||||
}
|
||||
|
||||
late final SymbolsAmountValidator symbolsAmountValidator;
|
||||
|
||||
late final DecimalAmountValidator decimalAmountValidator;
|
||||
|
||||
String? call(String? value) => symbolsAmountValidator(value) ?? decimalAmountValidator(value);
|
||||
}
|
||||
|
||||
class SymbolsAmountValidator extends TextValidator {
|
||||
SymbolsAmountValidator({required bool isAutovalidate})
|
||||
: super(
|
||||
errorMessage: S.current.error_text_amount,
|
||||
pattern: _pattern(type),
|
||||
errorMessage: S.current.error_text_amount,
|
||||
pattern: _pattern(),
|
||||
isAutovalidate: isAutovalidate,
|
||||
minLength: 0,
|
||||
maxLength: 0);
|
||||
|
||||
static String _pattern() => '^([0-9]+([.\,][0-9]+)?|[.\,][0-9]+)\$';
|
||||
}
|
||||
|
||||
class DecimalAmountValidator extends TextValidator {
|
||||
DecimalAmountValidator({required CryptoCurrency currency, bool isAutovalidate = false})
|
||||
: super(
|
||||
errorMessage: S.current.decimal_places_error,
|
||||
pattern: _pattern(currency),
|
||||
isAutovalidate: isAutovalidate,
|
||||
minLength: 0,
|
||||
maxLength: 0);
|
||||
|
||||
static String _pattern(WalletType type) {
|
||||
switch (type) {
|
||||
case WalletType.monero:
|
||||
return '^([0-9]+([.\,][0-9]{0,12})?|[.\,][0-9]{1,12})\$';
|
||||
case WalletType.bitcoin:
|
||||
return '^([0-9]+([.\,][0-9]{0,8})?|[.\,][0-9]{1,8})\$';
|
||||
static String _pattern(CryptoCurrency currency) {
|
||||
switch (currency) {
|
||||
case CryptoCurrency.xmr:
|
||||
return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,12})\$';
|
||||
case CryptoCurrency.btc:
|
||||
return '^([0-9]+([.\,][0-9]{1,8})?|[.\,][0-9]{1,8})\$';
|
||||
default:
|
||||
return '';
|
||||
return '^([0-9]+([.\,][0-9]{1,12})?|[.\,][0-9]{1,12})\$';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AllAmountValidator extends TextValidator {
|
||||
AllAmountValidator() : super(
|
||||
errorMessage: S.current.error_text_amount,
|
||||
pattern: S.current.all,
|
||||
minLength: 0,
|
||||
maxLength: 0);
|
||||
AllAmountValidator()
|
||||
: super(
|
||||
errorMessage: S.current.error_text_amount,
|
||||
pattern: S.current.all,
|
||||
minLength: 0,
|
||||
maxLength: 0);
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ class ExchangePage extends BasePage {
|
|||
.bodyText1!
|
||||
.color!,
|
||||
currencyValueValidator: AmountValidator(
|
||||
type: exchangeViewModel.wallet.type),
|
||||
currency: exchangeViewModel.depositCurrency),
|
||||
addressTextFieldValidator: AddressValidator(
|
||||
type: exchangeViewModel.depositCurrency),
|
||||
onPushPasteButton: (context) async {
|
||||
|
@ -304,7 +304,7 @@ class ExchangePage extends BasePage {
|
|||
.bodyText1!
|
||||
.decorationColor!,
|
||||
currencyValueValidator: AmountValidator(
|
||||
type: exchangeViewModel.wallet.type),
|
||||
currency: exchangeViewModel.receiveCurrency),
|
||||
addressTextFieldValidator:
|
||||
AddressValidator(
|
||||
type: exchangeViewModel
|
||||
|
|
|
@ -165,7 +165,7 @@ class ExchangeTemplatePage extends BasePage {
|
|||
.bodyText1!
|
||||
.color!,
|
||||
currencyValueValidator: AmountValidator(
|
||||
type: exchangeViewModel.wallet.type),
|
||||
currency: exchangeViewModel.depositCurrency),
|
||||
//addressTextFieldValidator: AddressValidator(
|
||||
// type: exchangeViewModel.depositCurrency),
|
||||
),
|
||||
|
@ -206,7 +206,7 @@ class ExchangeTemplatePage extends BasePage {
|
|||
.bodyText1!
|
||||
.decorationColor!,
|
||||
currencyValueValidator: AmountValidator(
|
||||
type: exchangeViewModel.wallet.type),
|
||||
currency: exchangeViewModel.receiveCurrency),
|
||||
//addressTextFieldValidator: AddressValidator(
|
||||
// type: exchangeViewModel.receiveCurrency),
|
||||
)),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:device_display_brightness/device_display_brightness.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
@ -119,7 +120,8 @@ class QRWidget extends StatelessWidget {
|
|||
hintText: S.of(context).receive_amount,
|
||||
textColor: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!,
|
||||
borderColor: Theme.of(context).textTheme!.headline5!.decorationColor!,
|
||||
validator: AmountValidator(type: addressListViewModel.type, isAutovalidate: true),
|
||||
validator: AmountValidator(currency:
|
||||
walletTypeToCryptoCurrency(addressListViewModel.type), isAutovalidate: true),
|
||||
// FIX-ME: Check does it equal to autovalidate: true,
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
placeholderTextStyle: TextStyle(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:cake_wallet/view_model/send/output.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/entities/template.dart';
|
||||
import 'package:cake_wallet/store/templates/send_template_store.dart';
|
||||
|
@ -26,7 +27,8 @@ abstract class SendTemplateViewModelBase with Store {
|
|||
|
||||
Output output;
|
||||
|
||||
Validator get amountValidator => AmountValidator(type: _wallet.type);
|
||||
Validator get amountValidator =>
|
||||
AmountValidator(currency: walletTypeToCryptoCurrency(_wallet.type));
|
||||
|
||||
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
||||
|
||||
|
|
|
@ -126,7 +126,8 @@ abstract class SendViewModelBase with Store {
|
|||
|
||||
CryptoCurrency get currency => _wallet.currency;
|
||||
|
||||
Validator get amountValidator => AmountValidator(type: _wallet.type);
|
||||
Validator get amountValidator =>
|
||||
AmountValidator(currency: walletTypeToCryptoCurrency(_wallet.type));
|
||||
|
||||
Validator get allAmountValidator => AllAmountValidator();
|
||||
|
||||
|
|
|
@ -683,5 +683,6 @@
|
|||
"arrive_in_this_address" : "سيصل ${currency} ${tag}إلى هذا العنوان",
|
||||
"do_not_send": "لا ترسل",
|
||||
"error_dialog_content": "عفوًا ، لقد حصلنا على بعض الخطأ.\n\nيرجى إرسال تقرير التعطل إلى فريق الدعم لدينا لتحسين التطبيق.",
|
||||
"decimal_places_error": "عدد كبير جدًا من المنازل العشرية",
|
||||
"edit_node": "تحرير العقدة"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}ще отидат на този адрес",
|
||||
"do_not_send": "Не изпращай",
|
||||
"error_dialog_content": "Получихме грешка.\n\nМоля, изпратете доклада до нашия отдел поддръжка, за да подобрим приложението.",
|
||||
"decimal_places_error": "Твърде много знаци след десетичната запетая",
|
||||
"edit_node": "Редактиране на възел"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}přijde na tuto adresu",
|
||||
"do_not_send": "Neodesílat",
|
||||
"error_dialog_content": "Nastala chyba.\n\nProsím odešlete zprávu o chybě naší podpoře, aby mohli zajistit opravu.",
|
||||
"decimal_places_error": "Příliš mnoho desetinných míst",
|
||||
"edit_node": "Upravit uzel"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}wird an dieser Adresse ankommen",
|
||||
"do_not_send": "Nicht senden",
|
||||
"error_dialog_content": "Hoppla, wir haben einen Fehler.\n\nBitte senden Sie den Absturzbericht an unser Support-Team, um die Anwendung zu verbessern.",
|
||||
"decimal_places_error": "Zu viele Nachkommastellen",
|
||||
"edit_node": "Knoten bearbeiten"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}will arrive in this address",
|
||||
"do_not_send": "Don't send",
|
||||
"error_dialog_content": "Oops, we got some error.\n\nPlease send the crash report to our support team to make the application better.",
|
||||
"decimal_places_error": "Too many decimal places",
|
||||
"edit_node": "Edit Node"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}llegará a esta dirección",
|
||||
"do_not_send": "no enviar",
|
||||
"error_dialog_content": "Vaya, tenemos un error.\n\nEnvíe el informe de bloqueo a nuestro equipo de soporte para mejorar la aplicación.",
|
||||
"decimal_places_error": "Demasiados lugares decimales",
|
||||
"edit_node": "Edit Node"
|
||||
}
|
||||
|
|
|
@ -683,5 +683,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}arrivera à cette adresse",
|
||||
"do_not_send": "N'envoyez pas",
|
||||
"error_dialog_content": "Oups, nous avons eu une erreur.\n\nVeuillez envoyer le rapport de plantage à notre équipe d'assistance pour améliorer l'application.",
|
||||
"decimal_places_error": "Trop de décimales",
|
||||
"edit_node": "Modifier le nœud"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}इस पते पर पहुंचेंगे",
|
||||
"do_not_send": "मत भेजो",
|
||||
"error_dialog_content": "ओह, हमसे कुछ गड़बड़ी हुई है.\n\nएप्लिकेशन को बेहतर बनाने के लिए कृपया क्रैश रिपोर्ट हमारी सहायता टीम को भेजें।",
|
||||
"decimal_places_error": "बहुत अधिक दशमलव स्थान",
|
||||
"edit_node": "नोड संपादित करें"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}će stići na ovu adresu",
|
||||
"do_not_send": "Ne šalji",
|
||||
"error_dialog_content": "Ups, imamo grešku.\n\nPošaljite izvješće o padu našem timu za podršku kako bismo poboljšali aplikaciju.",
|
||||
"decimal_places_error": "Previše decimalnih mjesta",
|
||||
"edit_node": "Uredi čvor"
|
||||
}
|
||||
|
|
|
@ -667,5 +667,6 @@
|
|||
"orbot_running_alert": "Pastikan Orbot sedang berjalan sebelum menghubungkan ke node ini.",
|
||||
"contact_list_contacts": "Kontak",
|
||||
"contact_list_wallets": "Dompet Saya",
|
||||
"decimal_places_error": "Terlalu banyak tempat desimal",
|
||||
"edit_node": "Sunting Node"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}arriverà a questo indirizzo",
|
||||
"do_not_send": "Non inviare",
|
||||
"error_dialog_content": "Spiacenti, abbiamo riscontrato un errore.\n\nSi prega di inviare il rapporto sull'arresto anomalo al nostro team di supporto per migliorare l'applicazione.",
|
||||
"decimal_places_error": "Troppe cifre decimali",
|
||||
"edit_node": "Modifica nodo"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}はこの住所に到着します",
|
||||
"do_not_send": "送信しない",
|
||||
"error_dialog_content": "エラーが発生しました。\n\nアプリケーションを改善するために、クラッシュ レポートをサポート チームに送信してください。",
|
||||
"decimal_places_error": "小数点以下の桁数が多すぎる",
|
||||
"edit_node": "ノードを編集"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}이(가) 이 주소로 도착합니다",
|
||||
"do_not_send": "보내지 마세요",
|
||||
"error_dialog_content": "죄송합니다. 오류가 발생했습니다.\n\n응용 프로그램을 개선하려면 지원 팀에 충돌 보고서를 보내주십시오.",
|
||||
"decimal_places_error": "소수점 이하 자릿수가 너무 많습니다.",
|
||||
"edit_node": "노드 편집"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}ဤလိပ်စာသို့ ရောက်ရှိပါမည်။",
|
||||
"do_not_send": "မပို့ပါနှင့်",
|
||||
"error_dialog_content": "အိုး၊ ကျွန်ုပ်တို့တွင် အမှားအယွင်းအချို့ရှိသည်။\n\nအပလီကေးရှင်းကို ပိုမိုကောင်းမွန်စေရန်အတွက် ပျက်စီးမှုအစီရင်ခံစာကို ကျွန်ုပ်တို့၏ပံ့ပိုးကူညီရေးအဖွဲ့ထံ ပေးပို့ပါ။",
|
||||
"decimal_places_error": "ဒဿမနေရာများ များလွန်းသည်။",
|
||||
"edit_node": "Node ကို တည်းဖြတ်ပါ။"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}komt aan op dit adres",
|
||||
"do_not_send": "Niet sturen",
|
||||
"error_dialog_content": "Oeps, er is een fout opgetreden.\n\nStuur het crashrapport naar ons ondersteuningsteam om de applicatie te verbeteren.",
|
||||
"decimal_places_error": "Te veel decimalen",
|
||||
"edit_node": "Knooppunt bewerken"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}dotrze na ten adres",
|
||||
"do_not_send": "Nie wysyłaj",
|
||||
"error_dialog_content": "Ups, wystąpił błąd.\n\nPrześlij raport o awarii do naszego zespołu wsparcia, aby ulepszyć aplikację.",
|
||||
"decimal_places_error": "Za dużo miejsc dziesiętnych",
|
||||
"edit_node": "Edytuj węzeł"
|
||||
}
|
||||
|
|
|
@ -684,5 +684,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}chegará neste endereço",
|
||||
"do_not_send": "não envie",
|
||||
"error_dialog_content": "Ops, houve algum erro.\n\nPor favor, envie o relatório de falha para nossa equipe de suporte para melhorar o aplicativo.",
|
||||
"decimal_places_error": "Muitas casas decimais",
|
||||
"edit_node": "Editar nó"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}придет на этот адрес",
|
||||
"do_not_send": "Не отправлять",
|
||||
"error_dialog_content": "Ой, у нас какая-то ошибка.\n\nПожалуйста, отправьте отчет о сбое в нашу службу поддержки, чтобы сделать приложение лучше.",
|
||||
"decimal_places_error": "Слишком много десятичных знаков",
|
||||
"edit_node": "Редактировать узел"
|
||||
}
|
||||
|
|
|
@ -683,5 +683,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}จะมาถึงที่อยู่นี้",
|
||||
"do_not_send": "อย่าส่ง",
|
||||
"error_dialog_content": "อ๊ะ เราพบข้อผิดพลาดบางอย่าง\n\nโปรดส่งรายงานข้อขัดข้องไปยังทีมสนับสนุนของเราเพื่อปรับปรุงแอปพลิเคชันให้ดียิ่งขึ้น",
|
||||
"decimal_places_error": "ทศนิยมมากเกินไป",
|
||||
"edit_node": "แก้ไขโหนด"
|
||||
}
|
||||
|
|
|
@ -685,5 +685,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}bu adrese ulaşacak",
|
||||
"do_not_send": "Gönderme",
|
||||
"error_dialog_content": "Hay aksi, bir hatamız var.\n\nUygulamayı daha iyi hale getirmek için lütfen kilitlenme raporunu destek ekibimize gönderin.",
|
||||
"decimal_places_error": "Çok fazla ondalık basamak",
|
||||
"edit_node": "Düğümü Düzenle"
|
||||
}
|
||||
|
|
|
@ -684,5 +684,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}надійде на цю адресу",
|
||||
"do_not_send": "Не надсилайте",
|
||||
"error_dialog_content": "На жаль, ми отримали помилку.\n\nБудь ласка, надішліть звіт про збій нашій команді підтримки, щоб покращити додаток.",
|
||||
"decimal_places_error": "Забагато знаків після коми",
|
||||
"edit_node": "Редагувати вузол"
|
||||
}
|
||||
|
|
|
@ -686,5 +686,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}اس پتے پر پہنچے گا۔",
|
||||
"do_not_send" : "مت بھیجیں۔",
|
||||
"error_dialog_content" : "افوہ، ہمیں کچھ خرابی ملی۔\n\nایپلی کیشن کو بہتر بنانے کے لیے براہ کرم کریش رپورٹ ہماری سپورٹ ٹیم کو بھیجیں۔",
|
||||
"decimal_places_error": "بہت زیادہ اعشاریہ جگہیں۔",
|
||||
"edit_node": "نوڈ میں ترمیم کریں۔"
|
||||
}
|
||||
|
|
|
@ -683,5 +683,6 @@
|
|||
"arrive_in_this_address" : "${currency} ${tag}将到达此地址",
|
||||
"do_not_send": "不要发送",
|
||||
"error_dialog_content": "糟糕,我们遇到了一些错误。\n\n请将崩溃报告发送给我们的支持团队,以改进应用程序。",
|
||||
"decimal_places_error": "小数位太多",
|
||||
"edit_node": "编辑节点"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue