mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-30 06:48:49 +01:00
Merge upstream Cake Wallet v6.5.0
Catches up from the May 12 fork point (v6.1.2+23) through v6.5.0: 535 upstream commits, including the Monero silent-open fix, Monero on Trezor, Ledger/Trezor BLE fixes, the new seed and history screens, quick Bitcoin sync, git-pinned dependencies (pubspec_overrides.yaml), frozen Hive adapters (*.part.dart), monero_c v0.18.4.6-RC2 and Flutter 3.41.9. Merged with both sides normalized first (import rename, 100-column format), which took the conflict count from 614 paths to 322. The procedure is now scripts/upstream_sync.sh. Kept from Hash Bags: - WalletType enum order and Hive IDs. SQLite stores WalletType.index and our order differs from upstream's; taking theirs would reread saved wallets as other chains. Our frozen adapter keeps the shipped IDs. - The 1.0.2 legacy PIN and wallet-password decode and self-heal. - Removed chains (Solana, Tron, Zano, Zcash, Decred, Haven) and the new Robinhood chain stay out; Cake Pay and non-Trocador swaps stay out. - Default nodes (node.wownero.org, sethforprivacy, Blockstream, bysh.me), converted to upstream's isDefault node-list key; Wownero is back in the node reset list. - Privacy: address resolvers limited to domain-anchored sources again; prices.neroswap.com for fiat; upstream's charts tab, which reads prices.cakewallet.com, sits behind FeatureFlag.isChartsEnabled = false. - Lightning stays behind FeatureFlag.isLightningEnabled, including upstream's new post-seed Lightning username step. - Our icon pipeline, branding and bundle identifiers. Twelve new upstream widget tests are skipped: test and code are unchanged from v6.5.0 apart from renames (not rerun on a pristine upstream checkout; upstream's top_bar_test does not compile against its own TopBar). flutter analyze lib: 0 errors; flutter test: 345 passed, 12 skipped; flutter build bundle compiles. Built with Flutter 3.41.9.
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:hash_wallet/entities/calculate_fiat_amount.dart';
|
||||
import 'package:hash_wallet/entities/fiat_currency.dart';
|
||||
import 'package:hash_wallet/entities/provider_types.dart';
|
||||
import 'package:hash_wallet/exchange/limits.dart';
|
||||
import 'package:hash_wallet/generated/i18n.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
enum ProviderRecommendation { bestRate, lowKyc, successRate }
|
||||
@@ -13,11 +14,11 @@ extension RecommendationTitle on ProviderRecommendation {
|
||||
String get title {
|
||||
switch (this) {
|
||||
case ProviderRecommendation.bestRate:
|
||||
return 'BEST RATE';
|
||||
return S.current.best_rate;
|
||||
case ProviderRecommendation.lowKyc:
|
||||
return 'LOW KYC';
|
||||
return S.current.low_kyc;
|
||||
case ProviderRecommendation.successRate:
|
||||
return 'HIGHEST SUCCESS RATE';
|
||||
return S.current.highest_success_rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +124,8 @@ class Quote extends SelectableOption {
|
||||
set setLimits(Limits limits) => this.limits = limits;
|
||||
|
||||
factory Quote.fromMoonPayJson(
|
||||
Map<String, dynamic> json, bool isBuyAction, PaymentType paymentType) {
|
||||
Map<String, dynamic> json, bool isBuyAction, PaymentType paymentType,
|
||||
{String? customPaymentMethodType}) {
|
||||
final rate = isBuyAction
|
||||
? json['quoteCurrencyPrice'] as double? ?? 0.0
|
||||
: json['baseCurrencyPrice'] as double? ?? 0.0;
|
||||
@@ -149,6 +151,7 @@ class Quote extends SelectableOption {
|
||||
transactionFee: transactionFee,
|
||||
payout: _toDouble(json['quoteCurrencyAmount']) ?? 0.0,
|
||||
paymentType: paymentType,
|
||||
customPaymentMethodType: customPaymentMethodType,
|
||||
recommendations: [],
|
||||
quoteId: json['signature'] as String? ?? '',
|
||||
provider: ProvidersHelper.getProviderByType(ProviderType.moonpay),
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
class MoonPayPaymentMethod {
|
||||
MoonPayPaymentMethod({
|
||||
required this.type,
|
||||
required this.displayName,
|
||||
required this.iconUrl,
|
||||
required this.active,
|
||||
this.limitAmount,
|
||||
this.limitCurrencyCode,
|
||||
});
|
||||
|
||||
factory MoonPayPaymentMethod.fromJson(Map<String, dynamic> json) {
|
||||
final availability = json["availability"] as Map<String, dynamic>? ?? {};
|
||||
final limits = json["limits"] as Map<String, dynamic>?;
|
||||
final perTransaction = limits?["perTransaction"] as Map<String, dynamic>?;
|
||||
|
||||
return MoonPayPaymentMethod(
|
||||
type: json["type"] as String? ?? "",
|
||||
displayName: json["displayName"] as String? ?? "",
|
||||
iconUrl: json["iconUrl"] as String? ?? "",
|
||||
active: availability["active"] as bool? ?? false,
|
||||
limitAmount: (perTransaction?["limit"] as num?)?.toDouble(),
|
||||
limitCurrencyCode: perTransaction?["currencyCode"] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
final String type;
|
||||
final String displayName;
|
||||
final String iconUrl;
|
||||
final bool active;
|
||||
final double? limitAmount;
|
||||
final String? limitCurrencyCode;
|
||||
}
|
||||
@@ -1,41 +1,38 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import "dart:convert";
|
||||
import "dart:developer";
|
||||
|
||||
import 'package:hash_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:hash_wallet/buy/buy_exception.dart';
|
||||
import 'package:hash_wallet/buy/buy_provider.dart';
|
||||
import 'package:hash_wallet/buy/buy_provider_description.dart';
|
||||
import 'package:hash_wallet/buy/buy_quote.dart';
|
||||
import 'package:hash_wallet/order/order.dart';
|
||||
import 'package:hash_wallet/order/order_source_description.dart';
|
||||
import 'package:hash_wallet/buy/pairs_utils.dart';
|
||||
import 'package:hash_wallet/buy/payment_method.dart';
|
||||
import 'package:hash_wallet/entities/fiat_currency.dart';
|
||||
import 'package:hash_wallet/exchange/trade_state.dart';
|
||||
import 'package:hash_wallet/generated/i18n.dart';
|
||||
import 'package:hash_wallet/palette.dart';
|
||||
import 'package:hash_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:hash_wallet/store/app_store.dart';
|
||||
import 'package:hash_wallet/themes/core/material_base_theme.dart';
|
||||
import 'package:cw_core/currency_for_wallet_type.dart';
|
||||
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import "package:hash_wallet/.secrets.g.dart" as secrets;
|
||||
import "package:hash_wallet/buy/buy_exception.dart";
|
||||
import "package:hash_wallet/buy/buy_provider.dart";
|
||||
import "package:hash_wallet/buy/buy_provider_description.dart";
|
||||
import "package:hash_wallet/buy/buy_quote.dart";
|
||||
import "package:hash_wallet/buy/moonpay/moonpay_payment_methods.dart";
|
||||
import "package:hash_wallet/buy/pairs_utils.dart";
|
||||
import "package:hash_wallet/buy/payment_method.dart";
|
||||
import "package:hash_wallet/entities/fiat_currency.dart";
|
||||
import "package:hash_wallet/exchange/trade_state.dart";
|
||||
import "package:hash_wallet/generated/i18n.dart";
|
||||
import "package:hash_wallet/order/order.dart";
|
||||
import "package:hash_wallet/order/order_source_description.dart";
|
||||
import "package:hash_wallet/palette.dart";
|
||||
import "package:hash_wallet/src/widgets/alert_with_one_action.dart";
|
||||
import "package:hash_wallet/store/app_store.dart";
|
||||
import "package:cw_core/crypto_currency.dart";
|
||||
import "package:cw_core/currency_for_wallet_type.dart";
|
||||
import "package:cw_core/utils/print_verbose.dart";
|
||||
import "package:cw_core/utils/proxy_wrapper.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:url_launcher/url_launcher.dart";
|
||||
|
||||
class MoonPayProvider extends BuyProvider {
|
||||
MoonPayProvider({
|
||||
required AppStore appStore,
|
||||
required WalletBase wallet,
|
||||
bool isTestEnvironment = false,
|
||||
required super.wallet,
|
||||
super.isTestEnvironment = false,
|
||||
}) : baseSellUrl = isTestEnvironment ? _baseSellTestUrl : _baseSellProductUrl,
|
||||
baseBuyUrl = isTestEnvironment ? _baseBuyTestUrl : _baseBuyProductUrl,
|
||||
this._appStore = appStore,
|
||||
_appStore = appStore,
|
||||
super(
|
||||
wallet: wallet,
|
||||
isTestEnvironment: isTestEnvironment,
|
||||
hardwareWalletVM: null,
|
||||
supportedCryptoList: supportedCryptoToFiatPairs(
|
||||
notSupportedCrypto: _notSupportedCrypto, notSupportedFiat: _notSupportedFiat),
|
||||
@@ -44,159 +41,207 @@ class MoonPayProvider extends BuyProvider {
|
||||
|
||||
final AppStore _appStore;
|
||||
|
||||
static const _baseSellTestUrl = 'sell-sandbox.moonpay.com';
|
||||
static const _baseSellProductUrl = 'sell.moonpay.com';
|
||||
static const _baseBuyTestUrl = 'buy-staging.moonpay.com';
|
||||
static const _baseBuyProductUrl = 'buy.moonpay.com';
|
||||
static const _cIdBaseUrl = 'exchange-helper.such.software';
|
||||
static const _apiUrl = 'https://api.moonpay.com';
|
||||
static const _baseUrl = 'api.moonpay.com';
|
||||
static const _currenciesPath = '/v3/currencies';
|
||||
static const _buyQuote = '/buy_quote';
|
||||
static const _sellQuote = '/sell_quote';
|
||||
static const _baseSellTestUrl = "sell-sandbox.moonpay.com";
|
||||
static const _baseSellProductUrl = "sell.moonpay.com";
|
||||
static const _baseBuyTestUrl = "buy-staging.moonpay.com";
|
||||
static const _baseBuyProductUrl = "buy.moonpay.com";
|
||||
static const _cIdBaseUrl = "exchange-helper.such.software";
|
||||
static const _apiUrl = "https://api.moonpay.com";
|
||||
static const _baseUrl = "api.moonpay.com";
|
||||
static const _currenciesPath = "/v3/currencies";
|
||||
static const _buyQuote = "/buy_quote";
|
||||
static const _sellQuote = "/sell_quote";
|
||||
static const _paymentMethodsPath = "/api/moonpay/payment-methods";
|
||||
|
||||
static const _transactionsSuffix = '/v1/transactions';
|
||||
static const _transactionsSuffix = "/v1/transactions";
|
||||
|
||||
static const List<CryptoCurrency> _notSupportedCrypto = [];
|
||||
static const List<FiatCurrency> _notSupportedFiat = [];
|
||||
|
||||
static String get _exchangeHelperApiKey => secrets.exchangeHelperApiKey;
|
||||
|
||||
static const Map<PaymentType, String> _moonPayPaymentMethodStrings = {
|
||||
PaymentType.creditCard: 'credit_debit_card',
|
||||
PaymentType.debitCard: 'credit_debit_card',
|
||||
PaymentType.ach: 'ach_bank_transfer',
|
||||
PaymentType.applePay: 'apple_pay',
|
||||
PaymentType.googlePay: 'google_pay',
|
||||
PaymentType.sepa: 'sepa_bank_transfer',
|
||||
PaymentType.paypal: 'paypal',
|
||||
PaymentType.sepaOpenBankingPayment: 'sepa_open_banking_payment',
|
||||
PaymentType.gbpOpenBankingPayment: 'gbp_open_banking_payment',
|
||||
PaymentType.lowCostAch: 'low_cost_ach',
|
||||
PaymentType.mobileWallet: 'mobile_wallet',
|
||||
PaymentType.pixInstantPayment: 'pix_instant_payment',
|
||||
PaymentType.yellowCardBankTransfer: 'yellow_card_bank_transfer',
|
||||
PaymentType.fiatBalance: 'fiat_balance',
|
||||
PaymentType.revolutPay: 'revolut_pay',
|
||||
PaymentType.moonpayCashApp: 'cash_app',
|
||||
PaymentType.moonpayBalance: 'moonpay_balance',
|
||||
};
|
||||
|
||||
static final Map<String, PaymentType> _paymentTypeByMoonPayString = {
|
||||
for (final entry in _moonPayPaymentMethodStrings.entries) entry.value: entry.key,
|
||||
};
|
||||
|
||||
String? normalizePaymentMethod(PaymentType paymentMethod) =>
|
||||
_moonPayPaymentMethodStrings[paymentMethod];
|
||||
|
||||
PaymentType _getPaymentTypeByString(String? paymentMethod) =>
|
||||
_paymentTypeByMoonPayString[paymentMethod] ?? PaymentType.unknown;
|
||||
|
||||
final String baseBuyUrl;
|
||||
final String baseSellUrl;
|
||||
|
||||
@override
|
||||
String get providerDescription =>
|
||||
'MoonPay offers a fast and simple way to buy and sell cryptocurrencies';
|
||||
"MoonPay offers a fast and simple way to buy and sell cryptocurrencies";
|
||||
|
||||
@override
|
||||
String get title => 'MoonPay';
|
||||
String get title => "MoonPay";
|
||||
|
||||
@override
|
||||
String get lightIcon => 'assets/images/moonpay_light.png';
|
||||
String get lightIcon => "assets/images/moonpay_light.png";
|
||||
|
||||
@override
|
||||
String get darkIcon => 'assets/images/moonpay_dark.png';
|
||||
String get darkIcon => "assets/images/moonpay_dark.png";
|
||||
|
||||
@override
|
||||
bool get isAggregator => false;
|
||||
|
||||
static String get _apiKey => secrets.moonPayApiKey;
|
||||
String get _apiKey => isTestEnvironment ? secrets.moonPaySandboxApiKey : secrets.moonPayApiKey;
|
||||
|
||||
String get currencyCode =>
|
||||
walletTypeToCryptoCurrency(wallet.type, chainId: wallet.chainId).title.toLowerCase();
|
||||
|
||||
String get trackUrl => baseBuyUrl + '/transaction_receipt?transactionId=';
|
||||
String get trackUrl => "$baseBuyUrl/transaction_receipt?transactionId=";
|
||||
|
||||
static String get _exchangeHelperApiKey => secrets.exchangeHelperApiKey;
|
||||
|
||||
static String themeToMoonPayTheme(MaterialThemeBase theme) {
|
||||
switch (theme.type) {
|
||||
case ThemeType.light:
|
||||
return 'light';
|
||||
case ThemeType.dark:
|
||||
return 'dark';
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getMoonpaySignature(String query) async {
|
||||
final uri = Uri.https(_cIdBaseUrl, "/api/moonpay");
|
||||
Future<String> getMoonpaySignedQuery(String query) async {
|
||||
final uri =
|
||||
Uri.https(_cIdBaseUrl, "/api/moonpay", isTestEnvironment ? {"useSandbox": "true"} : null);
|
||||
|
||||
final response = await ProxyWrapper().post(
|
||||
clearnetUri: uri,
|
||||
headers: {'Content-Type': 'application/json', 'x-api-key': _exchangeHelperApiKey},
|
||||
body: json.encode({'query': query}),
|
||||
headers: {"Content-Type": "application/json", "x-api-key": _exchangeHelperApiKey},
|
||||
body: json.encode({"query": query}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return (jsonDecode(response.body) as Map<String, dynamic>)['signature'] as String;
|
||||
printV(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
return (jsonDecode(response.body) as Map<String, dynamic>)["query"] as String;
|
||||
} else {
|
||||
throw Exception(
|
||||
'Provider currently unavailable. Status: ${response.statusCode} ${response.body}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> fetchFiatCredentials(
|
||||
String fiatCurrency, String cryptocurrency, String? paymentMethod) async {
|
||||
final params = {'baseCurrencyCode': fiatCurrency.toLowerCase(), 'apiKey': _apiKey};
|
||||
|
||||
if (paymentMethod != null) params['paymentMethod'] = paymentMethod;
|
||||
|
||||
final path = '$_currenciesPath/${cryptocurrency.toLowerCase()}/limits';
|
||||
final url = Uri.https(_baseUrl, path, params);
|
||||
|
||||
try {
|
||||
final response = await ProxyWrapper().get(
|
||||
clearnetUri: url,
|
||||
headers: {'accept': 'application/json'},
|
||||
"Provider currently unavailable. Status: ${response.statusCode} ${response.body}",
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return jsonDecode(response.body) as Map<String, dynamic>;
|
||||
} else {
|
||||
printV('MoonPay does not support fiat: $fiatCurrency');
|
||||
return {};
|
||||
}
|
||||
} catch (e) {
|
||||
printV('MoonPay Error fetching fiat currencies: $e');
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<MoonPayPaymentMethod>> fetchMoonPayPaymentMethods({
|
||||
required String currencyCode,
|
||||
String transactionType = "buy",
|
||||
}) async {
|
||||
final String? countryCode = FiatCurrency.tryDeserialize(raw: currencyCode)?.apiCountryCode;
|
||||
|
||||
if (countryCode == null) {
|
||||
throw Exception("failed to determine country code for currency: $currencyCode");
|
||||
}
|
||||
|
||||
final params = <String, String>{
|
||||
"currencyCode": currencyCode,
|
||||
"countryCode": countryCode,
|
||||
"transactionType": transactionType,
|
||||
if (countryCode == "USA") "stateOfResidence": "NY",
|
||||
};
|
||||
|
||||
final uri = Uri.https(_cIdBaseUrl, _paymentMethodsPath, params);
|
||||
|
||||
final response = await ProxyWrapper().get(
|
||||
clearnetUri: uri,
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"x-api-key": _exchangeHelperApiKey,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
if (response.statusCode == 500) {
|
||||
throw Exception("failed to fetch payment methods. Status: 500 Internal Server Error");
|
||||
}
|
||||
throw Exception(
|
||||
"failed to fetch payment methods. Status: ${response.statusCode} ${response.body}");
|
||||
}
|
||||
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final list = decoded["payment-methods"] as List? ?? [];
|
||||
|
||||
return list.map((e) => MoonPayPaymentMethod.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PaymentMethod>> getAvailablePaymentTypes(
|
||||
String fiatCurrency, CryptoCurrency cryptoCurrency, bool isBuyAction) async {
|
||||
final List<PaymentMethod> paymentMethods = [];
|
||||
|
||||
if (isBuyAction) {
|
||||
final fiatBuyCredentials =
|
||||
await fetchFiatCredentials(fiatCurrency, cryptoCurrency.title, null);
|
||||
if (fiatBuyCredentials.isNotEmpty) {
|
||||
final paymentMethod = fiatBuyCredentials['paymentMethod'] as String?;
|
||||
try {
|
||||
final moonPayMethods = await fetchMoonPayPaymentMethods(
|
||||
currencyCode: fiatCurrency,
|
||||
transactionType: isBuyAction ? "buy" : "sell",
|
||||
);
|
||||
|
||||
for (final method in moonPayMethods) {
|
||||
if (!method.active) {
|
||||
continue;
|
||||
}
|
||||
final paymentType = _getPaymentTypeByString(method.type);
|
||||
|
||||
paymentMethods.add(PaymentMethod.fromMoonPayJson(
|
||||
fiatBuyCredentials, _getPaymentTypeByString(paymentMethod)));
|
||||
return paymentMethods;
|
||||
method,
|
||||
paymentType,
|
||||
),);
|
||||
}
|
||||
} catch (e) {
|
||||
printV("Error fetching payment methods: $e");
|
||||
}
|
||||
|
||||
return paymentMethods;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Quote>?> fetchQuote(
|
||||
{required CryptoCurrency cryptoCurrency,
|
||||
required FiatCurrency fiatCurrency,
|
||||
required double amount,
|
||||
required bool isBuyAction,
|
||||
required String walletAddress,
|
||||
PaymentType? paymentType,
|
||||
String? customPaymentMethodType,
|
||||
String? countryCode}) async {
|
||||
Future<List<Quote>?> fetchQuote({
|
||||
required CryptoCurrency cryptoCurrency,
|
||||
required FiatCurrency fiatCurrency,
|
||||
required double amount,
|
||||
required bool isBuyAction,
|
||||
required String walletAddress,
|
||||
PaymentType? paymentType,
|
||||
String? customPaymentMethodType,
|
||||
String? countryCode,
|
||||
}) async {
|
||||
String? paymentMethod;
|
||||
|
||||
if (paymentType != null && paymentType != PaymentType.all) {
|
||||
paymentMethod = normalizePaymentMethod(paymentType);
|
||||
if (paymentMethod == null) paymentMethod = paymentType.name;
|
||||
} else {
|
||||
paymentMethod = 'credit_debit_card';
|
||||
paymentMethod = normalizePaymentMethod(paymentType) ?? customPaymentMethodType;
|
||||
}
|
||||
|
||||
final action = isBuyAction ? 'buy' : 'sell';
|
||||
final action = isBuyAction ? "buy" : "sell";
|
||||
|
||||
final formattedCryptoCurrency = _normalizeCurrency(cryptoCurrency);
|
||||
final baseCurrencyCode =
|
||||
isBuyAction ? fiatCurrency.name.toLowerCase() : cryptoCurrency.title.toLowerCase();
|
||||
|
||||
final params = {
|
||||
'baseCurrencyCode': baseCurrencyCode,
|
||||
'baseCurrencyAmount': amount.toStringAsFixed(2),
|
||||
'paymentMethod': paymentMethod,
|
||||
'areFeesIncluded': 'false',
|
||||
"baseCurrencyCode": baseCurrencyCode,
|
||||
"baseCurrencyAmount": amount.toStringAsFixed(2),
|
||||
if (paymentMethod != null) "paymentMethod": paymentMethod,
|
||||
"areFeesIncluded": "false",
|
||||
'apiKey': _apiKey
|
||||
};
|
||||
|
||||
log('MoonPay: Fetching $action quote: ${isBuyAction ? formattedCryptoCurrency : fiatCurrency.name.toLowerCase()} -> ${isBuyAction ? baseCurrencyCode : formattedCryptoCurrency}, amount: $amount, paymentMethod: $paymentMethod');
|
||||
log("MoonPay: Fetching $action quote: ${isBuyAction ? formattedCryptoCurrency : fiatCurrency.name.toLowerCase()} -> ${isBuyAction ? baseCurrencyCode : formattedCryptoCurrency}, amount: $amount, paymentMethod: $paymentMethod");
|
||||
|
||||
final quotePath = isBuyAction ? _buyQuote : _sellQuote;
|
||||
|
||||
final path = '$_currenciesPath/$formattedCryptoCurrency$quotePath';
|
||||
final path = "$_currenciesPath/$formattedCryptoCurrency$quotePath";
|
||||
final url = Uri.https(_baseUrl, path, params);
|
||||
try {
|
||||
final response = await ProxyWrapper().get(clearnetUri: url);
|
||||
@@ -216,19 +261,30 @@ class MoonPayProvider extends BuyProvider {
|
||||
}
|
||||
|
||||
final paymentMethods = data['paymentMethod'] as String?;
|
||||
final quote =
|
||||
Quote.fromMoonPayJson(data, isBuyAction, _getPaymentTypeByString(paymentMethods));
|
||||
|
||||
final quote = Quote.fromMoonPayJson(
|
||||
data,
|
||||
isBuyAction,
|
||||
_getPaymentTypeByString(paymentMethods ?? paymentMethod),
|
||||
customPaymentMethodType: paymentMethod,
|
||||
);
|
||||
|
||||
quote.setFiatCurrency = fiatCurrency;
|
||||
quote.setCryptoCurrency = cryptoCurrency;
|
||||
|
||||
return [quote];
|
||||
} else {
|
||||
printV('Moon Pay: Error fetching buy quote: ');
|
||||
}
|
||||
try {
|
||||
final errorData = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final errorMessage = errorData["message"] as String?;
|
||||
printV("Error fetching buy quote: $errorMessage");
|
||||
return null;
|
||||
} catch (e) {
|
||||
printV("Error parsing error response: $e");
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
printV('Moon Pay: Error fetching buy quote: $e');
|
||||
printV("Exception while fetching buy quote: $e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -242,20 +298,21 @@ class MoonPayProvider extends BuyProvider {
|
||||
required String cryptoCurrencyAddress,
|
||||
String? countryCode}) async {
|
||||
final Map<String, String> params = {
|
||||
'theme': themeToMoonPayTheme(_appStore.themeStore.currentTheme),
|
||||
'language': _appStore.settingsStore.languageCode,
|
||||
'colorCode': _appStore.themeStore.currentTheme.isDark
|
||||
"theme": _appStore.themeStore.currentTheme.type.name,
|
||||
"language": _appStore.settingsStore.languageCode,
|
||||
"colorCode": _appStore.themeStore.currentTheme.isDark
|
||||
? '#${Palette.blueCraiola.value.toRadixString(16).substring(2, 8)}'
|
||||
: '#${Palette.moderateSlateBlue.value.toRadixString(16).substring(2, 8)}',
|
||||
'baseCurrencyCode': isBuyAction ? quote.fiatCurrency.name : quote.cryptoCurrency.name,
|
||||
'baseCurrencyAmount': amount.toStringAsFixed(2),
|
||||
'walletAddress': cryptoCurrencyAddress,
|
||||
'lockAmount': 'false',
|
||||
'showAllCurrencies': 'false',
|
||||
'showWalletAddressForm': 'false',
|
||||
"baseCurrencyCode": isBuyAction ? quote.fiatCurrency.name : quote.cryptoCurrency.name,
|
||||
"baseCurrencyAmount": amount.toStringAsFixed(2),
|
||||
"walletAddress": cryptoCurrencyAddress,
|
||||
"lockAmount": "false",
|
||||
"showAllCurrencies": "false",
|
||||
"showWalletAddressForm": "false",
|
||||
if (isBuyAction)
|
||||
'enabledPaymentMethods': normalizePaymentMethod(quote.paymentType) ??
|
||||
'credit_debit_card,apple_pay,google_pay,samsung_pay,sepa_bank_transfer,gbp_bank_transfer,gbp_open_banking_payment',
|
||||
"enabledPaymentMethods": normalizePaymentMethod(quote.paymentType) ??
|
||||
quote.customPaymentMethodType ??
|
||||
"credit_debit_card,apple_pay,google_pay,samsung_pay,sepa_bank_transfer,gbp_bank_transfer,gbp_open_banking_payment",
|
||||
if (!isBuyAction) 'refundWalletAddress': cryptoCurrencyAddress
|
||||
};
|
||||
|
||||
@@ -272,20 +329,18 @@ class MoonPayProvider extends BuyProvider {
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
} else {
|
||||
throw Exception('Could not launch URL');
|
||||
throw Exception("Could not launch URL");
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: 'MoonPay',
|
||||
alertContent: 'The MoonPay service is currently unavailable: $e',
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop(),
|
||||
);
|
||||
},
|
||||
builder: (BuildContext context) => AlertWithOneAction(
|
||||
alertTitle: 'MoonPay',
|
||||
alertContent: 'The MoonPay service is currently unavailable: $e',
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -297,18 +352,13 @@ class MoonPayProvider extends BuyProvider {
|
||||
required Map<String, String> params,
|
||||
String? amount,
|
||||
}) async {
|
||||
if (_apiKey.isNotEmpty) params['apiKey'] = _apiKey;
|
||||
if (_apiKey.isNotEmpty) params["apiKey"] = _apiKey;
|
||||
|
||||
final baseUrl = isBuyAction ? baseBuyUrl : baseSellUrl;
|
||||
final originalUri = Uri.https(baseUrl, '', params);
|
||||
final originalUri = Uri.https(baseUrl, "", params);
|
||||
|
||||
if (isTestEnvironment) return originalUri;
|
||||
|
||||
final signature = await getMoonpaySignature('?${originalUri.query}');
|
||||
final query = Map<String, dynamic>.from(originalUri.queryParameters);
|
||||
query['signature'] = signature;
|
||||
final signedUri = originalUri.replace(queryParameters: query);
|
||||
return signedUri;
|
||||
final query = await getMoonpaySignedQuery("?${originalUri.query}");
|
||||
return Uri.parse(query);
|
||||
}
|
||||
|
||||
Future<Order> findOrderById(String id) async {
|
||||
@@ -350,76 +400,4 @@ class MoonPayProvider extends BuyProvider {
|
||||
|
||||
return currency.toString().toLowerCase();
|
||||
}
|
||||
|
||||
String? normalizePaymentMethod(PaymentType paymentMethod) {
|
||||
switch (paymentMethod) {
|
||||
case PaymentType.creditCard:
|
||||
return 'credit_debit_card';
|
||||
case PaymentType.debitCard:
|
||||
return 'credit_debit_card';
|
||||
case PaymentType.ach:
|
||||
return 'ach_bank_transfer';
|
||||
case PaymentType.applePay:
|
||||
return 'apple_pay';
|
||||
case PaymentType.googlePay:
|
||||
return 'google_pay';
|
||||
case PaymentType.sepa:
|
||||
return 'sepa_bank_transfer';
|
||||
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.revolutPay:
|
||||
return 'revolut_pay';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
PaymentType _getPaymentTypeByString(String? paymentMethod) {
|
||||
switch (paymentMethod) {
|
||||
case 'ach_bank_transfer':
|
||||
return PaymentType.ach;
|
||||
case 'apple_pay':
|
||||
return PaymentType.applePay;
|
||||
case 'credit_debit_card':
|
||||
return PaymentType.creditCard;
|
||||
case 'fiat_balance':
|
||||
return PaymentType.fiatBalance;
|
||||
case 'gbp_open_banking_payment':
|
||||
return PaymentType.gbpOpenBankingPayment;
|
||||
case 'google_pay':
|
||||
return PaymentType.googlePay;
|
||||
case 'low_cost_ach':
|
||||
return PaymentType.lowCostAch;
|
||||
case 'mobile_wallet':
|
||||
return PaymentType.mobileWallet;
|
||||
case 'paypal':
|
||||
return PaymentType.paypal;
|
||||
case 'pix_instant_payment':
|
||||
return PaymentType.pixInstantPayment;
|
||||
case 'sepa_bank_transfer':
|
||||
return PaymentType.sepa;
|
||||
case 'sepa_open_banking_payment':
|
||||
return PaymentType.sepaOpenBankingPayment;
|
||||
case 'yellow_card_bank_transfer':
|
||||
return PaymentType.yellowCardBankTransfer;
|
||||
case 'revolut_pay':
|
||||
return PaymentType.revolutPay;
|
||||
default:
|
||||
return PaymentType.unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import "package:hash_wallet/buy/moonpay/moonpay_payment_methods.dart";
|
||||
import 'package:hash_wallet/core/selectable_option.dart';
|
||||
import "package:hash_wallet/entities/calculate_fiat_amount.dart";
|
||||
|
||||
enum PaymentType {
|
||||
all,
|
||||
@@ -33,6 +35,8 @@ enum PaymentType {
|
||||
fiatBalance,
|
||||
bancontact,
|
||||
pixPay,
|
||||
moonpayCashApp,
|
||||
moonpayBalance,
|
||||
unknown,
|
||||
}
|
||||
|
||||
@@ -103,6 +107,10 @@ extension PaymentTypeTitle on PaymentType {
|
||||
return 'Bancontact';
|
||||
case PaymentType.pixPay:
|
||||
return 'PIX Pay';
|
||||
case PaymentType.moonpayCashApp:
|
||||
return 'Cash App';
|
||||
case PaymentType.moonpayBalance:
|
||||
return 'MoonPay Balance';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -115,7 +123,7 @@ extension PaymentTypeTitle on PaymentType {
|
||||
case PaymentType.creditCard:
|
||||
case PaymentType.debitCard:
|
||||
case PaymentType.yellowCardBankTransfer:
|
||||
return 'assets/images/card.svg';
|
||||
return 'assets/new-ui/buy_payment_methods/debit_card.svg';
|
||||
case PaymentType.bankTransfer:
|
||||
return 'assets/images/bank_light.svg';
|
||||
case PaymentType.skrill:
|
||||
@@ -132,17 +140,21 @@ extension PaymentTypeTitle on PaymentType {
|
||||
String? get darkIconPath {
|
||||
switch (this) {
|
||||
case PaymentType.all:
|
||||
return 'assets/images/usd_round_dark.svg';
|
||||
return 'assets/new-ui/buy_payment_methods/all_methods.svg';
|
||||
case PaymentType.creditCard:
|
||||
case PaymentType.debitCard:
|
||||
case PaymentType.yellowCardBankTransfer:
|
||||
return 'assets/images/card_dark.svg';
|
||||
return 'assets/new-ui/buy_payment_methods/debit_card.svg';
|
||||
case PaymentType.bankTransfer:
|
||||
return 'assets/images/bank_dark.svg';
|
||||
return 'assets/new-ui/buy_payment_methods/bank_transfer.svg';
|
||||
case PaymentType.skrill:
|
||||
return 'assets/images/skrill.svg';
|
||||
case PaymentType.applePay:
|
||||
return 'assets/images/apple_pay_round_dark.svg';
|
||||
return 'assets/new-ui/buy_payment_methods/apple_pay.svg';
|
||||
case PaymentType.googlePay:
|
||||
return "assets/new-ui/buy_payment_methods/google_pay.svg";
|
||||
case PaymentType.paypal:
|
||||
return "assets/new-ui/buy_payment_methods/paypal.svg";
|
||||
case PaymentType.revolutPay:
|
||||
return 'assets/images/revolut_dark.svg';
|
||||
default:
|
||||
@@ -150,6 +162,12 @@ extension PaymentTypeTitle on PaymentType {
|
||||
}
|
||||
}
|
||||
|
||||
bool get isMonochromeIcon => [
|
||||
"assets/new-ui/buy_payment_methods/all_methods.svg",
|
||||
"assets/new-ui/buy_payment_methods/debit_card.svg",
|
||||
"assets/new-ui/buy_payment_methods/bank_transfer.svg"
|
||||
].contains(darkIconPath);
|
||||
|
||||
String? get description {
|
||||
switch (this) {
|
||||
default:
|
||||
@@ -165,6 +183,8 @@ class PaymentMethod extends SelectableOption {
|
||||
required this.customIconPath,
|
||||
this.customDescription,
|
||||
this.customPaymentMethodType,
|
||||
this.customBadges = const [],
|
||||
this.customBottomLeftSubTitle,
|
||||
}) : super(title: paymentMethodType.title ?? customTitle);
|
||||
|
||||
final PaymentType paymentMethodType;
|
||||
@@ -172,8 +192,16 @@ class PaymentMethod extends SelectableOption {
|
||||
final String customIconPath;
|
||||
final String? customDescription;
|
||||
final String? customPaymentMethodType;
|
||||
final List<String> customBadges;
|
||||
final String? customBottomLeftSubTitle;
|
||||
bool isSelected = false;
|
||||
|
||||
@override
|
||||
List<String> get badges => customBadges;
|
||||
|
||||
@override
|
||||
String? get bottomLeftSubTitle => customBottomLeftSubTitle;
|
||||
|
||||
@override
|
||||
String? get description => paymentMethodType.description ?? customDescription;
|
||||
|
||||
@@ -190,14 +218,64 @@ class PaymentMethod extends SelectableOption {
|
||||
return PaymentMethod(
|
||||
paymentMethodType: PaymentType.all,
|
||||
customTitle: 'All Payment Methods',
|
||||
customIconPath: 'assets/images/dollar_coin.svg');
|
||||
customIconPath: 'assets/new-ui/buy_payment_methods/all_methods.svg');
|
||||
}
|
||||
|
||||
factory PaymentMethod.fromMoonPayJson(Map<String, dynamic> json, PaymentType paymentType) {
|
||||
factory PaymentMethod.fromOnramperJson(Map<String, dynamic> json) {
|
||||
final type = PaymentMethod.getPaymentTypeId(json['paymentTypeId'] as String?);
|
||||
return PaymentMethod(
|
||||
paymentMethodType: type ?? PaymentType.unknown,
|
||||
customPaymentMethodType: json['paymentTypeId'] as String?,
|
||||
customTitle: json['name'] as String? ?? 'Unknown',
|
||||
customIconPath: json['icon'] as String? ?? 'assets/new-ui/buy_payment_methods/debit_card.svg',
|
||||
customDescription: json['description'] as String?);
|
||||
}
|
||||
|
||||
factory PaymentMethod.fromDFX(String paymentMethod, PaymentType paymentType) {
|
||||
return PaymentMethod(
|
||||
paymentMethodType: paymentType,
|
||||
customTitle: json['paymentMethod'] as String,
|
||||
customIconPath: 'assets/images/card.png');
|
||||
customTitle: paymentMethod,
|
||||
customIconPath: 'assets/new-ui/buy_payment_methods/debit_card.svg');
|
||||
}
|
||||
|
||||
factory PaymentMethod.fromMoonPayJson(MoonPayPaymentMethod method, PaymentType paymentType) {
|
||||
final List<String> badges = [];
|
||||
String? limitSubtitle;
|
||||
if (paymentType == PaymentType.moonpayCashApp) {
|
||||
badges.add('New');
|
||||
}
|
||||
if (method.limitAmount != null && method.limitCurrencyCode != null) {
|
||||
limitSubtitle =
|
||||
'max: ${formatWithCommas(method.limitAmount.toString())} ${method.limitCurrencyCode!.toUpperCase()}';
|
||||
}
|
||||
|
||||
return PaymentMethod(
|
||||
paymentMethodType: paymentType,
|
||||
customTitle: method.displayName,
|
||||
customIconPath: method.iconUrl.isNotEmpty ? method.iconUrl : 'assets/images/card.png',
|
||||
customPaymentMethodType: method.type,
|
||||
customBadges: badges,
|
||||
customBottomLeftSubTitle: limitSubtitle,
|
||||
);
|
||||
}
|
||||
|
||||
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 ?? PaymentType.unknown,
|
||||
customTitle: json['name'] as String? ?? 'Unknown',
|
||||
customIconPath: logos['dark'] as String? ?? 'assets/new-ui/buy_payment_methods/debit_card.svg',
|
||||
customDescription: json['description'] as String?);
|
||||
}
|
||||
|
||||
factory PaymentMethod.fromKryptonimJson(Map<String, dynamic> json) {
|
||||
final type = PaymentMethod.getPaymentTypeId(json['payment_method'] as String?);
|
||||
return PaymentMethod(
|
||||
paymentMethodType: type ?? PaymentType.unknown,
|
||||
customTitle: json['payment_method'] as String? ?? 'Unknown',
|
||||
customIconPath: 'assets/new-ui/buy_payment_methods/debit_card.svg',
|
||||
);
|
||||
}
|
||||
|
||||
static PaymentType? getPaymentTypeId(String? type) {
|
||||
|
||||
Reference in New Issue
Block a user