Merge pull request #149 from cake-tech/CAKE-185-digits-limit-on-monero-transaction

Cake 185 digits limit on monero transaction
This commit is contained in:
M
2020-12-04 11:20:33 +02:00
17 changed files with 146 additions and 9 deletions
+2 -1
View File
@@ -14,7 +14,8 @@ class TradeIsCreatedSuccessfully extends ExchangeTradeState {
}
class TradeIsCreatedFailure extends ExchangeTradeState {
TradeIsCreatedFailure({@required this.error});
TradeIsCreatedFailure({@required this.title, @required this.error});
final String title;
final String error;
}
@@ -12,6 +12,7 @@ import 'package:cake_wallet/exchange/xmrto/xmrto_trade_request.dart';
import 'package:cake_wallet/exchange/trade_not_created_exeption.dart';
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/exchange/trade_not_found_exeption.dart';
import 'package:cake_wallet/generated/i18n.dart';
class XMRTOExchangeProvider extends ExchangeProvider {
XMRTOExchangeProvider()
@@ -90,12 +91,25 @@ class XMRTOExchangeProvider extends ExchangeProvider {
Future<Trade> createTrade({TradeRequest request}) async {
final _request = request as XMRTOTradeRequest;
final url = originalApiUri + _orderCreateUriSuffix;
final _amount = _request.isBTCRequest
? _request.receiveAmount
: _request.amount;
final _amountCurrency = _request.isBTCRequest
? _request.to.toString()
: _request.from.toString();
final pattern = '^([0-9]+([.\,][0-9]{0,8})?|[.\,][0-9]{1,8})\$';
final isValid = RegExp(pattern).hasMatch(_amount);
if (!isValid) {
throw TradeNotCreatedException(description,
description: S.current.xmr_to_error_description);
}
final body = {
'amount':
_request.isBTCRequest ? _request.receiveAmount : _request.amount,
'amount_currency': _request.isBTCRequest
? _request.to.toString()
: _request.from.toString(),
'amount': _amount,
'amount_currency': _amountCurrency,
'btc_dest_address': _request.address
};
final response = await post(url,
+69
View File
@@ -326,6 +326,8 @@ class S implements WidgetsLocalizations {
String get xmr_available_balance => "Available Balance";
String get xmr_full_balance => "Full Balance";
String get xmr_hidden => "Hidden";
String get xmr_to_error => "XMR.TO error";
String get xmr_to_error_description => "Invalid amount. Maximum limit 8 digits after the decimal point";
String get yesterday => "Yesterday";
String get you_will_get => "Convert to";
String get you_will_send => "Convert from";
@@ -346,6 +348,7 @@ class S implements WidgetsLocalizations {
String min_value(String value, String currency) => "Min: ${value} ${currency}";
String openalias_alert_content(String recipient_name) => "You will be sending funds to\n${recipient_name}";
String powered_by(String title) => "Powered by ${title}";
String provider_error(String provider) => "${provider} error";
String router_no_route(String name) => "No route defined for ${name}";
String send_address(String cryptoCurrency) => "${cryptoCurrency} address";
String send_priority(String transactionPriority) => "Currently the fee is set at ${transactionPriority} priority.\nTransaction priority can be adjusted in the settings";
@@ -773,6 +776,8 @@ class $de extends S {
@override
String get seed_language_dutch => "Niederländisch";
@override
String get xmr_to_error => "XMR.TO-Fehler";
@override
String get restore_description_from_seed_keys => "Holen Sie sich Ihr Wallet von Seed / Schlüsseln zurück, die Sie an einem sicheren Ort aufbewahrt haben";
@override
String get copy => "Kopieren";
@@ -877,6 +882,8 @@ class $de extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "Ungültiger Betrag. Höchstgrenze 8 Stellen nach dem Dezimalpunkt";
@override
String get trade_state_confirming => "Bestätigung";
@override
String get send => "Senden";
@@ -1041,6 +1048,8 @@ class $de extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "Fehler beim Entfernen ${wallet_name} Wallet. ${error}";
@override
String provider_error(String provider) => "${provider} Error";
@override
String copied_key_to_clipboard(String key) => "Kopiert ${key} Zur Zwischenablage";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "Laden fehlgeschlagen ${wallet_name} Wallet. ${error}";
@@ -1459,6 +1468,8 @@ class $hi extends S {
@override
String get seed_language_dutch => "डच";
@override
String get xmr_to_error => "XMR.TO त्रुटि";
@override
String get restore_description_from_seed_keys => "अपने बटुए को बीज से वापस लें/वे कुंजियाँ जिन्हें आपने सुरक्षित स्थान पर सहेजा है";
@override
String get copy => "प्रतिलिपि";
@@ -1563,6 +1574,8 @@ class $hi extends S {
@override
String get trade_details_id => "आईडी";
@override
String get xmr_to_error_description => "अवैध राशि। दशमलव बिंदु के बाद अधिकतम सीमा 8 अंक";
@override
String get trade_state_confirming => "पुष्टि";
@override
String get send => "संदेश";
@@ -1727,6 +1740,8 @@ class $hi extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "निकालने में विफल ${wallet_name} बटुआ. ${error}";
@override
String provider_error(String provider) => "${provider} त्रुटि";
@override
String copied_key_to_clipboard(String key) => "की नकल की ${key} क्लिपबोर्ड पर";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "लोड करने में विफल ${wallet_name} बटुआ. ${error}";
@@ -2145,6 +2160,8 @@ class $ru extends S {
@override
String get seed_language_dutch => "Нидерландский";
@override
String get xmr_to_error => "Ошибка XMR.TO";
@override
String get restore_description_from_seed_keys => "Вы можете восстановить кошелёк из мнемонической фразы/ключей, которые вы сохранили ранее";
@override
String get copy => "Скопировать";
@@ -2249,6 +2266,8 @@ class $ru extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "Недопустимая сумма. Максимум 8 цифр после десятичной точки";
@override
String get trade_state_confirming => "Подтверждение";
@override
String get send => "Отправить";
@@ -2413,6 +2432,8 @@ class $ru extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "Ошибка при удалении ${wallet_name} кошелька. ${error}";
@override
String provider_error(String provider) => "${provider} ошибка";
@override
String copied_key_to_clipboard(String key) => "Скопировано ${key} в буфер обмена";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "Ошибка при загрузке ${wallet_name} кошелька. ${error}";
@@ -2831,6 +2852,8 @@ class $ko extends S {
@override
String get seed_language_dutch => "네덜란드 사람";
@override
String get xmr_to_error => "XMR.TO 오류";
@override
String get restore_description_from_seed_keys => "안전한 장소에 저장 한 종자 / 키로 지갑을 되 찾으십시오.";
@override
String get copy => "부";
@@ -2935,6 +2958,8 @@ class $ko extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "금액이 잘못되었습니다. 소수점 이하 최대 8 자리";
@override
String get trade_state_confirming => "확인 중";
@override
String get send => "보내다";
@@ -3099,6 +3124,8 @@ class $ko extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "제거하지 못했습니다 ${wallet_name} 지갑. ${error}";
@override
String provider_error(String provider) => "${provider} 오류";
@override
String copied_key_to_clipboard(String key) => "복사 ${key} 클립 보드로";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "불러 오지 못했습니다 ${wallet_name} 지갑. ${error}";
@@ -3517,6 +3544,8 @@ class $pt extends S {
@override
String get seed_language_dutch => "Holandesa";
@override
String get xmr_to_error => "Erro XMR.TO";
@override
String get restore_description_from_seed_keys => "Restaure a sua carteira a partir de sementes/chaves que você salvou em um local seguro";
@override
String get copy => "Copiar";
@@ -3621,6 +3650,8 @@ class $pt extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "Montante inválido. Limite máximo de 8 dígitos após o ponto decimal";
@override
String get trade_state_confirming => "Confirmando";
@override
String get send => "Enviar";
@@ -3785,6 +3816,8 @@ class $pt extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "Falha ao remover a carteira ${wallet_name}. ${error}";
@override
String provider_error(String provider) => "${provider} erro";
@override
String copied_key_to_clipboard(String key) => "${key} copiada para a área de transferência";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "Falha ao abrir a carteira ${wallet_name}. ${error}";
@@ -4203,6 +4236,8 @@ class $uk extends S {
@override
String get seed_language_dutch => "Голландська";
@override
String get xmr_to_error => "Помилка XMR.TO";
@override
String get restore_description_from_seed_keys => "Ви можете відновити гаманець з мнемонічної фрази/ключів, які ви зберегли раніше";
@override
String get copy => "Скопіювати";
@@ -4307,6 +4342,8 @@ class $uk extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "Неприпустима сума. Максимум 8 цифр після десяткової коми";
@override
String get trade_state_confirming => "Підтвердження";
@override
String get send => "Відправити";
@@ -4471,6 +4508,8 @@ class $uk extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "Помилка при видаленні ${wallet_name} гаманця. ${error}";
@override
String provider_error(String provider) => "${provider} помилка";
@override
String copied_key_to_clipboard(String key) => "Скопійовано ${key} в буфер обміну";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "Помилка при завантаженні ${wallet_name} гаманця. ${error}";
@@ -4889,6 +4928,8 @@ class $ja extends S {
@override
String get seed_language_dutch => "オランダの";
@override
String get xmr_to_error => "XMR.TOエラー";
@override
String get restore_description_from_seed_keys => "安全な場所に保存したシード/キーから財布を取り戻す";
@override
String get copy => "コピー";
@@ -4993,6 +5034,8 @@ class $ja extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "金額が無効です。 小数点以下8桁の上限";
@override
String get trade_state_confirming => "確認中";
@override
String get send => "送る";
@@ -5157,6 +5200,8 @@ class $ja extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "削除できませんでした ${wallet_name} 財布. ${error}";
@override
String provider_error(String provider) => "${provider} エラー";
@override
String copied_key_to_clipboard(String key) => "コピー済み ${key} クリップボードへ";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "読み込みに失敗しました ${wallet_name} 財布. ${error}";
@@ -5579,6 +5624,8 @@ class $pl extends S {
@override
String get seed_language_dutch => "Holenderski";
@override
String get xmr_to_error => "Pomyłka XMR.TO";
@override
String get restore_description_from_seed_keys => "Odzyskaj swój portfel z nasion / kluczy, które zapisałeś w bezpiecznym miejscu";
@override
String get copy => "Kopiuj";
@@ -5683,6 +5730,8 @@ class $pl extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "Nieprawidłowa kwota. Maksymalny limit 8 cyfr po przecinku";
@override
String get trade_state_confirming => "Potwierdzam";
@override
String get send => "Wysłać";
@@ -5847,6 +5896,8 @@ class $pl extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "Nie udało się usunąć ${wallet_name} portfel. ${error}";
@override
String provider_error(String provider) => "${provider} pomyłka";
@override
String copied_key_to_clipboard(String key) => "Skopiowane ${key} do schowka";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "Nie udało się załadować ${wallet_name} portfel. ${error}";
@@ -6265,6 +6316,8 @@ class $es extends S {
@override
String get seed_language_dutch => "Holandés";
@override
String get xmr_to_error => "Error de XMR.TO";
@override
String get restore_description_from_seed_keys => "Recupere su billetera de las semillas/claves que ha guardado en un lugar seguro";
@override
String get copy => "Dupdo";
@@ -6369,6 +6422,8 @@ class $es extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "Monto invalido. Límite máximo de 8 dígitos después del punto decimal";
@override
String get trade_state_confirming => "Confirmando";
@override
String get send => "Enviar";
@@ -6533,6 +6588,8 @@ class $es extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "Error al elimina ${wallet_name} billetera. ${error}";
@override
String provider_error(String provider) => "${provider} error";
@override
String copied_key_to_clipboard(String key) => "Copiado ${key} al portapapeles";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "No se pudo cargar ${wallet_name} la billetera. ${error}";
@@ -6951,6 +7008,8 @@ class $nl extends S {
@override
String get seed_language_dutch => "Nederlands";
@override
String get xmr_to_error => "XMR.TO-fout";
@override
String get restore_description_from_seed_keys => "Ontvang uw portemonnee terug uit seed / keys die u hebt opgeslagen op een veilige plaats";
@override
String get copy => "Kopiëren";
@@ -7055,6 +7114,8 @@ class $nl extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "Ongeldige hoeveelheid. Maximaal 8 cijfers achter de komma";
@override
String get trade_state_confirming => "Bevestiging";
@override
String get send => "Sturen";
@@ -7219,6 +7280,8 @@ class $nl extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "Verwijderen mislukt ${wallet_name} portemonnee. ${error}";
@override
String provider_error(String provider) => "${provider} fout";
@override
String copied_key_to_clipboard(String key) => "Gekopieerd ${key} naar het klembord";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "Laden mislukt ${wallet_name} portemonnee. ${error}";
@@ -7637,6 +7700,8 @@ class $zh extends S {
@override
String get seed_language_dutch => "荷蘭人";
@override
String get xmr_to_error => "XMR.TO錯誤";
@override
String get restore_description_from_seed_keys => "从保存到安全地方的种子/钥匙取回钱包";
@override
String get copy => "复制";
@@ -7741,6 +7806,8 @@ class $zh extends S {
@override
String get trade_details_id => "ID";
@override
String get xmr_to_error_description => "無效的金額。 小數點後最多8位數字";
@override
String get trade_state_confirming => "确认中";
@override
String get send => "发送";
@@ -7905,6 +7972,8 @@ class $zh extends S {
@override
String wallet_list_failed_to_remove(String wallet_name, String error) => "删除失败 ${wallet_name} 钱包. ${error}";
@override
String provider_error(String provider) => "${provider} 錯誤";
@override
String copied_key_to_clipboard(String key) => "复制 ${key} 到剪贴板";
@override
String wallet_list_failed_to_load(String wallet_name, String error) => "加载失败 ${wallet_name} 钱包. ${error}";
+1 -1
View File
@@ -547,7 +547,7 @@ class ExchangePage extends BasePage {
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: S.of(context).error,
alertTitle: S.of(context).provider_error(state.title),
alertContent: state.error,
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
@@ -174,7 +174,7 @@ abstract class ExchangeViewModelBase with Store {
return;
}
final _amount = double.parse(amount.replaceAll(',', '.'));
final _amount = double.parse(amount.replaceAll(',', '.')) ?? 0;
provider
.calculateAmount(
from: depositCurrency,
@@ -247,10 +247,12 @@ abstract class ExchangeViewModelBase with Store {
if (limitsState is LimitsLoadedSuccessfully && amount != null) {
if (double.parse(amount) < limits.min) {
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current.error_text_minimal_limit('${provider.description}',
'${limits.min}', currency.toString()));
} else if (limits.max != null && double.parse(amount) > limits.max) {
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current.error_text_maximum_limit('${provider.description}',
'${limits.max}', currency.toString()));
} else {
@@ -262,11 +264,14 @@ abstract class ExchangeViewModelBase with Store {
await trades.add(trade);
tradeState = TradeIsCreatedSuccessfully(trade: trade);
} catch (e) {
tradeState = TradeIsCreatedFailure(error: e.toString());
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: e.toString());
}
}
} else {
tradeState = TradeIsCreatedFailure(
title: provider.title,
error: S.current
.error_text_limits_loading_failed('${provider.description}'));
}