cake_wallet/lib/cake_pay/cake_pay_card.dart
Serhii 30dc8f9238
Cw 591 in app cake pay integration (#1376)
* init commit

* buy card UI

* buy card detail page

* card filter

* dropdown button

* user auth flow

* create order

* denomination option

* fix searching

* denom option fix UI

* simulate payment

* Update pr_test_build.yml

* Update pr_test_build.yml

* Implement order expiration handling [skip ci]

* refactor code [skip ci]

* remove ionia related code [skip ci]

* change auth flow

* add currency prefix

* grid view UI

* fix country filter issue

* fix underline color

* fix fetching card list [skip ci]

* list view

* update cake pay title

* Optimize API usage by fetching CakePay vendors

* handle no cards found case

* adjust the flow of purchases

* UI fixes

* fix btc payment data

* link extractor

* fix fetch next page issue

* UI fixes

* fix text size

* revert base page changes

* Revert "revert base page changes"

* UI fixes

* fix UI

* fix link style + localization

* update cake pay title

* update cake pay subtitle

* Update cake_pay_order.dart

* revert inject_app_details update
2024-06-06 06:51:22 +02:00

87 lines
2.8 KiB
Dart

import 'dart:convert';
import 'package:cake_wallet/entities/fiat_currency.dart';
class CakePayCard {
final int id;
final String name;
final String? description;
final String? termsAndConditions;
final String? howToUse;
final String? expiryAndValidity;
final String? cardImageUrl;
final String? country;
final FiatCurrency fiatCurrency;
final List<String> denominationsUsd;
final List<String> denominations;
final String? minValueUsd;
final String? maxValueUsd;
final String? minValue;
final String? maxValue;
CakePayCard({
required this.id,
required this.name,
this.description,
this.termsAndConditions,
this.howToUse,
this.expiryAndValidity,
this.cardImageUrl,
this.country,
required this.fiatCurrency,
required this.denominationsUsd,
required this.denominations,
this.minValueUsd,
this.maxValueUsd,
this.minValue,
this.maxValue,
});
factory CakePayCard.fromJson(Map<String, dynamic> json) {
final name = stripHtmlIfNeeded(json['name'] as String? ?? '');
final decodedName = fixEncoding(name);
final description = stripHtmlIfNeeded(json['description'] as String? ?? '');
final decodedDescription = fixEncoding(description);
final termsAndConditions = stripHtmlIfNeeded(json['terms_and_conditions'] as String? ?? '');
final decodedTermsAndConditions = fixEncoding(termsAndConditions);
final howToUse = stripHtmlIfNeeded(json['how_to_use'] as String? ?? '');
final decodedHowToUse = fixEncoding(howToUse);
final fiatCurrency = FiatCurrency.deserialize(raw: json['currency_code'] as String? ?? '');
final List<String> denominationsUsd =
(json['denominations_usd'] as List?)?.map((e) => e.toString()).toList() ?? [];
final List<String> denominations =
(json['denominations'] as List?)?.map((e) => e.toString()).toList() ?? [];
return CakePayCard(
id: json['id'] as int? ?? 0,
name: decodedName,
description: decodedDescription,
termsAndConditions: decodedTermsAndConditions,
howToUse: decodedHowToUse,
expiryAndValidity: json['expiry_and_validity'] as String?,
cardImageUrl: json['card_image_url'] as String?,
country: json['country'] as String?,
fiatCurrency: fiatCurrency,
denominationsUsd: denominationsUsd,
denominations: denominations,
minValueUsd: json['min_value_usd'] as String?,
maxValueUsd: json['max_value_usd'] as String?,
minValue: json['min_value'] as String?,
maxValue: json['max_value'] as String?,
);
}
static String stripHtmlIfNeeded(String text) {
return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' ');
}
static String fixEncoding(String text) {
final bytes = latin1.encode(text);
return utf8.decode(bytes, allowMalformed: true);
}
}