cake_wallet/lib/buy/payment_method.dart

288 lines
8 KiB
Dart
Raw Normal View History

Cw 657 new buy sell flow (#1553) * init commit * onramper * moonPay * dfx provider * meld * dfx payment methods * fiat buy credentials * moonpay payment method * payment loading state * dfx sell quote * onramper launch trade * meld launch trade * country picker * update option tile * buy/sell action * meld refactor * update pr_test_build.yml * ui fixes * revert country picker commit * update the ui * recommended providers * payment method [skip ci] * provider option tile * remove buy action * minor fixes * update the best rate when the amount is changed * fixes for currency title * fix icons * code refactoring * null issue * code review fixes * Update pr_test_build_linux.yml * Update meld_buy_provider.dart * Update meld_buy_provider.dart * add show wallets action * remove default sell / buy provider setting * localisation * providerTypes * icons * remove duplicate file [skip ci] * minor changes [skip ci] * fixes from review * disable dfx for non eur/chf currencies fix providers to be fetched with the selected currency * fix breaking from loop if one element failed * fix minor naming issue from merging conflicts * add fiat check for moonpay * fix address validation * merge conflict * fix destination and source currency * minor fix * minor fix * update the flow * fix bch address format * fix wallet addresses * fix initial fetching amount. * Update address_validator.dart * review comments * revert switch case to return null * minor fix --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-11-09 19:00:56 +00:00
import 'dart:ui';
import 'package:cake_wallet/core/selectable_option.dart';
enum PaymentType {
all,
bankTransfer,
creditCard,
debitCard,
applePay,
googlePay,
revolutPay,
neteller,
skrill,
sepa,
sepaInstant,
ach,
achInstant,
Khipu,
palomaBanktTansfer,
ovo,
zaloPay,
zaloBankTransfer,
gcash,
imps,
dana,
ideal,
paypal,
sepaOpenBankingPayment,
gbpOpenBankingPayment,
lowCostAch,
mobileWallet,
pixInstantPayment,
yellowCardBankTransfer,
fiatBalance,
bancontact,
}
extension PaymentTypeTitle on PaymentType {
String? get title {
switch (this) {
case PaymentType.all:
return 'All Payment Methods';
case PaymentType.bankTransfer:
return 'Bank Transfer';
case PaymentType.creditCard:
return 'Credit Card';
case PaymentType.debitCard:
return 'Debit Card';
case PaymentType.applePay:
return 'Apple Pay';
case PaymentType.googlePay:
return 'Google Pay';
case PaymentType.revolutPay:
return 'Revolut Pay';
case PaymentType.neteller:
return 'Neteller';
case PaymentType.skrill:
return 'Skrill';
case PaymentType.sepa:
return 'SEPA';
case PaymentType.sepaInstant:
return 'SEPA Instant';
case PaymentType.ach:
return 'ACH';
case PaymentType.achInstant:
return 'ACH Instant';
case PaymentType.Khipu:
return 'Khipu';
case PaymentType.palomaBanktTansfer:
return 'Paloma Bank Transfer';
case PaymentType.ovo:
return 'OVO';
case PaymentType.zaloPay:
return 'Zalo Pay';
case PaymentType.zaloBankTransfer:
return 'Zalo Bank Transfer';
case PaymentType.gcash:
return 'GCash';
case PaymentType.imps:
return 'IMPS';
case PaymentType.dana:
return 'DANA';
case PaymentType.ideal:
return 'iDEAL';
case PaymentType.paypal:
return 'PayPal';
case PaymentType.sepaOpenBankingPayment:
return 'SEPA Open Banking Payment';
case PaymentType.gbpOpenBankingPayment:
return 'GBP Open Banking Payment';
case PaymentType.lowCostAch:
return 'Low Cost ACH';
case PaymentType.mobileWallet:
return 'Mobile Wallet';
case PaymentType.pixInstantPayment:
return 'PIX Instant Payment';
case PaymentType.yellowCardBankTransfer:
return 'Yellow Card Bank Transfer';
case PaymentType.fiatBalance:
return 'Fiat Balance';
case PaymentType.bancontact:
return 'Bancontact';
default:
return null;
}
}
String? get lightIconPath {
switch (this) {
case PaymentType.all:
return 'assets/images/usd_round_light.svg';
case PaymentType.creditCard:
case PaymentType.debitCard:
case PaymentType.yellowCardBankTransfer:
return 'assets/images/card.svg';
case PaymentType.bankTransfer:
return 'assets/images/bank_light.svg';
case PaymentType.skrill:
return 'assets/images/skrill.svg';
case PaymentType.applePay:
return 'assets/images/apple_pay_round_light.svg';
default:
return null;
}
}
String? get darkIconPath {
switch (this) {
case PaymentType.all:
return 'assets/images/usd_round_dark.svg';
case PaymentType.creditCard:
case PaymentType.debitCard:
case PaymentType.yellowCardBankTransfer:
return 'assets/images/card_dark.svg';
case PaymentType.bankTransfer:
return 'assets/images/bank_dark.svg';
case PaymentType.skrill:
return 'assets/images/skrill.svg';
case PaymentType.applePay:
return 'assets/images/apple_pay_round_dark.svg';
default:
return null;
}
}
String? get description {
switch (this) {
default:
return null;
}
}
}
class PaymentMethod extends SelectableOption {
PaymentMethod({
required this.paymentMethodType,
required this.customTitle,
required this.customIconPath,
this.customDescription,
}) : super(title: paymentMethodType.title ?? customTitle);
final PaymentType paymentMethodType;
final String customTitle;
final String customIconPath;
final String? customDescription;
bool isSelected = false;
@override
String? get description => paymentMethodType.description ?? customDescription;
@override
String get lightIconPath => paymentMethodType.lightIconPath ?? customIconPath;
@override
String get darkIconPath => paymentMethodType.darkIconPath ?? customIconPath;
@override
bool get isOptionSelected => isSelected;
factory PaymentMethod.all() {
return PaymentMethod(
paymentMethodType: PaymentType.all,
customTitle: 'All Payment Methods',
customIconPath: 'assets/images/dollar_coin.svg');
}
factory PaymentMethod.fromOnramperJson(Map<String, dynamic> json) {
final type = PaymentMethod.getPaymentTypeId(json['paymentTypeId'] as String?);
return PaymentMethod(
paymentMethodType: type,
customTitle: json['name'] as String? ?? 'Unknown',
customIconPath: json['icon'] as String? ?? 'assets/images/card.png',
customDescription: json['description'] as String?);
}
factory PaymentMethod.fromDFX(String paymentMethod, PaymentType paymentType) {
return PaymentMethod(
paymentMethodType: paymentType,
customTitle: paymentMethod,
customIconPath: 'assets/images/card.png');
}
factory PaymentMethod.fromMoonPayJson(Map<String, dynamic> json, PaymentType paymentType) {
return PaymentMethod(
paymentMethodType: paymentType,
customTitle: json['paymentMethod'] as String,
customIconPath: 'assets/images/card.png');
}
factory PaymentMethod.fromMeldJson(Map<String, dynamic> json) {
final type = PaymentMethod.getPaymentTypeId(json['paymentMethod'] as String?);
final logos = json['logos'] as Map<String, dynamic>;
return PaymentMethod(
paymentMethodType: type,
customTitle: json['name'] as String? ?? 'Unknown',
customIconPath: logos['dark'] as String? ?? 'assets/images/card.png',
customDescription: json['description'] as String?);
}
static PaymentType getPaymentTypeId(String? type) {
switch (type?.toLowerCase()) {
case 'banktransfer':
case 'bank':
case 'yellow_card_bank_transfer':
return PaymentType.bankTransfer;
case 'creditcard':
case 'card':
case 'credit_debit_card':
return PaymentType.creditCard;
case 'debitcard':
return PaymentType.debitCard;
case 'applepay':
case 'apple_pay':
return PaymentType.applePay;
case 'googlepay':
case 'google_pay':
return PaymentType.googlePay;
case 'revolutpay':
return PaymentType.revolutPay;
case 'neteller':
return PaymentType.neteller;
case 'skrill':
return PaymentType.skrill;
case 'sepabanktransfer':
case 'sepa':
case 'sepa_bank_transfer':
return PaymentType.sepa;
case 'sepainstant':
case 'sepa_instant':
return PaymentType.sepaInstant;
case 'ach':
case 'ach_bank_transfer':
return PaymentType.ach;
case 'iach':
case 'instant_ach':
return PaymentType.achInstant;
case 'khipu':
return PaymentType.Khipu;
case 'palomabanktransfer':
return PaymentType.palomaBanktTansfer;
case 'ovo':
return PaymentType.ovo;
case 'zalopay':
return PaymentType.zaloPay;
case 'zalobanktransfer':
case 'za_bank_transfer':
return PaymentType.zaloBankTransfer;
case 'gcash':
return PaymentType.gcash;
case 'imps':
return PaymentType.imps;
case 'dana':
return PaymentType.dana;
case 'ideal':
return PaymentType.ideal;
case 'paypal':
return PaymentType.paypal;
case 'sepa_open_banking_payment':
return PaymentType.sepaOpenBankingPayment;
case 'bancontact':
return PaymentType.bancontact;
default:
return PaymentType.all;
}
}
}