mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-20 17:54:41 +00:00
fix cakepay text encoding (#1902)
Some checks failed
Cache Dependencies / test (push) Has been cancelled
Some checks failed
Cache Dependencies / test (push) Has been cancelled
* fix text encoding * fix initial encoding
This commit is contained in:
parent
2fe2f58cb4
commit
4cdee649d1
3 changed files with 8 additions and 32 deletions
|
@ -230,6 +230,7 @@ class CakePayApi {
|
||||||
|
|
||||||
var headers = {
|
var headers = {
|
||||||
'accept': 'application/json; charset=UTF-8',
|
'accept': 'application/json; charset=UTF-8',
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
'Authorization': 'Api-Key $apiKey',
|
'Authorization': 'Api-Key $apiKey',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -240,7 +241,7 @@ class CakePayApi {
|
||||||
'Failed to fetch vendors: statusCode - ${response.statusCode}, queryParams -$queryParams, response - ${response.body}');
|
'Failed to fetch vendors: statusCode - ${response.statusCode}, queryParams -$queryParams, response - ${response.body}');
|
||||||
}
|
}
|
||||||
|
|
||||||
final bodyJson = json.decode(response.body);
|
final bodyJson = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
|
||||||
if (bodyJson is List<dynamic> && bodyJson.isEmpty) {
|
if (bodyJson is List<dynamic> && bodyJson.isEmpty) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||||
|
|
||||||
class CakePayCard {
|
class CakePayCard {
|
||||||
|
@ -38,17 +36,11 @@ class CakePayCard {
|
||||||
});
|
});
|
||||||
|
|
||||||
factory CakePayCard.fromJson(Map<String, dynamic> json) {
|
factory CakePayCard.fromJson(Map<String, dynamic> json) {
|
||||||
|
|
||||||
final name = stripHtmlIfNeeded(json['name'] as String? ?? '');
|
final name = stripHtmlIfNeeded(json['name'] as String? ?? '');
|
||||||
final decodedName = fixEncoding(name);
|
|
||||||
|
|
||||||
final description = stripHtmlIfNeeded(json['description'] as String? ?? '');
|
final description = stripHtmlIfNeeded(json['description'] as String? ?? '');
|
||||||
final decodedDescription = fixEncoding(description);
|
|
||||||
|
|
||||||
final termsAndConditions = stripHtmlIfNeeded(json['terms_and_conditions'] as String? ?? '');
|
final termsAndConditions = stripHtmlIfNeeded(json['terms_and_conditions'] as String? ?? '');
|
||||||
final decodedTermsAndConditions = fixEncoding(termsAndConditions);
|
|
||||||
|
|
||||||
final howToUse = stripHtmlIfNeeded(json['how_to_use'] as String? ?? '');
|
final howToUse = stripHtmlIfNeeded(json['how_to_use'] as String? ?? '');
|
||||||
final decodedHowToUse = fixEncoding(howToUse);
|
|
||||||
|
|
||||||
final fiatCurrency = FiatCurrency.deserialize(raw: json['currency_code'] as String? ?? '');
|
final fiatCurrency = FiatCurrency.deserialize(raw: json['currency_code'] as String? ?? '');
|
||||||
|
|
||||||
|
@ -59,10 +51,10 @@ class CakePayCard {
|
||||||
|
|
||||||
return CakePayCard(
|
return CakePayCard(
|
||||||
id: json['id'] as int? ?? 0,
|
id: json['id'] as int? ?? 0,
|
||||||
name: decodedName,
|
name: name,
|
||||||
description: decodedDescription,
|
description: description,
|
||||||
termsAndConditions: decodedTermsAndConditions,
|
termsAndConditions: termsAndConditions,
|
||||||
howToUse: decodedHowToUse,
|
howToUse: howToUse,
|
||||||
expiryAndValidity: json['expiry_and_validity'] as String?,
|
expiryAndValidity: json['expiry_and_validity'] as String?,
|
||||||
cardImageUrl: json['card_image_url'] as String?,
|
cardImageUrl: json['card_image_url'] as String?,
|
||||||
country: json['country'] as String?,
|
country: json['country'] as String?,
|
||||||
|
@ -79,13 +71,4 @@ class CakePayCard {
|
||||||
static String stripHtmlIfNeeded(String text) {
|
static String stripHtmlIfNeeded(String text) {
|
||||||
return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' ');
|
return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
static String fixEncoding(String text) {
|
|
||||||
try {
|
|
||||||
final bytes = latin1.encode(text);
|
|
||||||
return utf8.decode(bytes, allowMalformed: true);
|
|
||||||
} catch (_) {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'cake_pay_card.dart';
|
import 'cake_pay_card.dart';
|
||||||
|
|
||||||
class CakePayVendor {
|
class CakePayVendor {
|
||||||
|
@ -21,7 +19,6 @@ class CakePayVendor {
|
||||||
|
|
||||||
factory CakePayVendor.fromJson(Map<String, dynamic> json, String country) {
|
factory CakePayVendor.fromJson(Map<String, dynamic> json, String country) {
|
||||||
final name = stripHtmlIfNeeded(json['name'] as String);
|
final name = stripHtmlIfNeeded(json['name'] as String);
|
||||||
final decodedName = fixEncoding(name);
|
|
||||||
|
|
||||||
var cardsJson = json['cards'] as List?;
|
var cardsJson = json['cards'] as List?;
|
||||||
CakePayCard? cardForVendor;
|
CakePayCard? cardForVendor;
|
||||||
|
@ -36,7 +33,7 @@ class CakePayVendor {
|
||||||
|
|
||||||
return CakePayVendor(
|
return CakePayVendor(
|
||||||
id: json['id'] as int,
|
id: json['id'] as int,
|
||||||
name: decodedName,
|
name: name,
|
||||||
unavailable: json['unavailable'] as bool? ?? false,
|
unavailable: json['unavailable'] as bool? ?? false,
|
||||||
cakeWarnings: json['cake_warnings'] as String?,
|
cakeWarnings: json['cake_warnings'] as String?,
|
||||||
country: country,
|
country: country,
|
||||||
|
@ -47,9 +44,4 @@ class CakePayVendor {
|
||||||
static String stripHtmlIfNeeded(String text) {
|
static String stripHtmlIfNeeded(String text) {
|
||||||
return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' ');
|
return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
static String fixEncoding(String text) {
|
|
||||||
final bytes = latin1.encode(text);
|
|
||||||
return utf8.decode(bytes, allowMalformed: true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue