mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 09:29:48 +00:00
fix: wrong card for vendor country (#1905)
* fix: wrong card for vendor country * Update lib/cake_pay/cake_pay_vendor.dart --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
542920a512
commit
b1c9be637f
4 changed files with 20 additions and 12 deletions
|
@ -204,8 +204,8 @@ class CakePayApi {
|
|||
/// Get Vendors
|
||||
Future<List<CakePayVendor>> getVendors({
|
||||
required String apiKey,
|
||||
required String country,
|
||||
int? page,
|
||||
String? country,
|
||||
String? countryCode,
|
||||
String? search,
|
||||
List<String>? vendorIds,
|
||||
|
@ -247,7 +247,7 @@ class CakePayApi {
|
|||
}
|
||||
|
||||
return (bodyJson['results'] as List)
|
||||
.map((e) => CakePayVendor.fromJson(e as Map<String, dynamic>))
|
||||
.map((e) => CakePayVendor.fromJson(e as Map<String, dynamic>, country))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,11 @@ class CakePayCard {
|
|||
}
|
||||
|
||||
static String fixEncoding(String text) {
|
||||
final bytes = latin1.encode(text);
|
||||
return utf8.decode(bytes, allowMalformed: true);
|
||||
try {
|
||||
final bytes = latin1.encode(text);
|
||||
return utf8.decode(bytes, allowMalformed: true);
|
||||
} catch (_) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ class CakePayService {
|
|||
|
||||
/// Get Vendors
|
||||
Future<List<CakePayVendor>> getVendors({
|
||||
required String country,
|
||||
int? page,
|
||||
String? country,
|
||||
String? countryCode,
|
||||
String? search,
|
||||
List<String>? vendorIds,
|
||||
|
|
|
@ -7,7 +7,7 @@ class CakePayVendor {
|
|||
final String name;
|
||||
final bool unavailable;
|
||||
final String? cakeWarnings;
|
||||
final List<String> countries;
|
||||
final String country;
|
||||
final CakePayCard? card;
|
||||
|
||||
CakePayVendor({
|
||||
|
@ -15,19 +15,23 @@ class CakePayVendor {
|
|||
required this.name,
|
||||
required this.unavailable,
|
||||
this.cakeWarnings,
|
||||
required this.countries,
|
||||
required this.country,
|
||||
this.card,
|
||||
});
|
||||
|
||||
factory CakePayVendor.fromJson(Map<String, dynamic> json) {
|
||||
factory CakePayVendor.fromJson(Map<String, dynamic> json, String country) {
|
||||
final name = stripHtmlIfNeeded(json['name'] as String);
|
||||
final decodedName = fixEncoding(name);
|
||||
|
||||
var cardsJson = json['cards'] as List?;
|
||||
CakePayCard? firstCard;
|
||||
CakePayCard? cardForVendor;
|
||||
|
||||
if (cardsJson != null && cardsJson.isNotEmpty) {
|
||||
firstCard = CakePayCard.fromJson(cardsJson.first as Map<String, dynamic>);
|
||||
try {
|
||||
cardForVendor = CakePayCard.fromJson(cardsJson
|
||||
.where((element) => element['country'] == country)
|
||||
.first as Map<String, dynamic>);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
return CakePayVendor(
|
||||
|
@ -35,8 +39,8 @@ class CakePayVendor {
|
|||
name: decodedName,
|
||||
unavailable: json['unavailable'] as bool? ?? false,
|
||||
cakeWarnings: json['cake_warnings'] as String?,
|
||||
countries: List<String>.from(json['countries'] as List? ?? []),
|
||||
card: firstCard,
|
||||
country: country,
|
||||
card: cardForVendor,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue