Cw 1032 verify on ramper integration (#2172)

* refactor: cache onramp metadata

* remove unused parameters

* Skip onramper transaction page and go directly to provider (#1940)

* Skip onramper transaction page and go directly to provider

* change parameter to follow docs correctly

* remove old deprecated monero nodes [skip ci]

* Update onramper_buy_provider.dart

---------

Co-authored-by: Serhii <borodenko.sv@gmail.com>

* refactor: normalise network

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii 2025-04-10 04:55:31 +03:00 committed by GitHub
parent f58a5fb8fd
commit 2b020c0c1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -37,6 +37,7 @@ class OnRamperBuyProvider extends BuyProvider {
static const List<CryptoCurrency> _notSupportedCrypto = []; static const List<CryptoCurrency> _notSupportedCrypto = [];
static const List<FiatCurrency> _notSupportedFiat = []; static const List<FiatCurrency> _notSupportedFiat = [];
static Map<String, dynamic> _onrampMetadata = {};
final SettingsStore _settingsStore; final SettingsStore _settingsStore;
@ -59,11 +60,8 @@ class OnRamperBuyProvider extends BuyProvider {
Future<List<PaymentMethod>> getAvailablePaymentTypes( Future<List<PaymentMethod>> getAvailablePaymentTypes(
String fiatCurrency, CryptoCurrency cryptoCurrency, bool isBuyAction) async { String fiatCurrency, CryptoCurrency cryptoCurrency, bool isBuyAction) async {
final params = {
'fiatCurrency': fiatCurrency, final params = {'type': isBuyAction ? 'buy' : 'sell'};
'type': isBuyAction ? 'buy' : 'sell',
'isRecurringPayment': 'false'
};
final url = Uri.https(_baseApiUrl, '$supported$paymentTypes/$fiatCurrency', params); final url = Uri.https(_baseApiUrl, '$supported$paymentTypes/$fiatCurrency', params);
@ -136,16 +134,14 @@ class OnRamperBuyProvider extends BuyProvider {
final actionType = isBuyAction ? 'buy' : 'sell'; final actionType = isBuyAction ? 'buy' : 'sell';
final normalizedCryptoCurrency = _getNormalizeCryptoCurrency(cryptoCurrency); final normalizedCryptoCurrency =
cryptoCurrency.title + _getNormalizeNetwork(cryptoCurrency).toUpperCase();
final params = { final params = {
'amount': amount.toString(), 'amount': amount.toString(),
if (paymentMethod != null) 'paymentMethod': paymentMethod, if (paymentMethod != null) 'paymentMethod': paymentMethod,
'clientName': 'CakeWallet', 'clientName': 'CakeWallet',
'type': actionType, if (actionType == 'sell') 'type': actionType,
'walletAddress': walletAddress,
'isRecurringPayment': 'false',
'input': 'source',
}; };
log('Onramper: Fetching $actionType quote: ${isBuyAction ? normalizedCryptoCurrency : fiatCurrency.name} -> ${isBuyAction ? fiatCurrency.name : normalizedCryptoCurrency}, amount: $amount, paymentMethod: $paymentMethod'); log('Onramper: Fetching $actionType quote: ${isBuyAction ? normalizedCryptoCurrency : fiatCurrency.name} -> ${isBuyAction ? fiatCurrency.name : normalizedCryptoCurrency}, amount: $amount, paymentMethod: $paymentMethod');
@ -165,7 +161,7 @@ class OnRamperBuyProvider extends BuyProvider {
List<Quote> validQuotes = []; List<Quote> validQuotes = [];
final onrampMetadata = await getOnrampMetadata(); if (_onrampMetadata.isEmpty) _onrampMetadata = await getOnrampMetadata();
for (var item in data) { for (var item in data) {
@ -174,12 +170,12 @@ class OnRamperBuyProvider extends BuyProvider {
final paymentMethod = (item as Map<String, dynamic>)['paymentMethod'] as String; final paymentMethod = (item as Map<String, dynamic>)['paymentMethod'] as String;
final rampId = item['ramp'] as String?; final rampId = item['ramp'] as String?;
final rampMetaData = onrampMetadata[rampId] as Map<String, dynamic>?; final rampMetaData = _onrampMetadata[rampId] as Map<String, dynamic>?;
if (rampMetaData == null) continue; if (rampMetaData == null) continue;
final quote = Quote.fromOnramperJson( final quote = Quote.fromOnramperJson(
item, isBuyAction, onrampMetadata, _getPaymentTypeByString(paymentMethod)); item, isBuyAction, _onrampMetadata, _getPaymentTypeByString(paymentMethod));
quote.setFiatCurrency = fiatCurrency; quote.setFiatCurrency = fiatCurrency;
quote.setCryptoCurrency = cryptoCurrency; quote.setCryptoCurrency = cryptoCurrency;
validQuotes.add(quote); validQuotes.add(quote);
@ -206,7 +202,6 @@ class OnRamperBuyProvider extends BuyProvider {
required String cryptoCurrencyAddress, required String cryptoCurrencyAddress,
String? countryCode}) async { String? countryCode}) async {
final actionType = isBuyAction ? 'buy' : 'sell'; final actionType = isBuyAction ? 'buy' : 'sell';
final prefix = actionType == 'sell' ? actionType + '_' : '';
final primaryColor = getColorStr(Theme.of(context).primaryColor); final primaryColor = getColorStr(Theme.of(context).primaryColor);
final secondaryColor = getColorStr(Theme.of(context).colorScheme.background); final secondaryColor = getColorStr(Theme.of(context).colorScheme.background);
@ -220,18 +215,20 @@ class OnRamperBuyProvider extends BuyProvider {
cardColor = getColorStr(Colors.white); cardColor = getColorStr(Colors.white);
} }
final defaultCrypto = _getNormalizeCryptoCurrency(quote.cryptoCurrency); final defaultCrypto =
quote.cryptoCurrency.title + _getNormalizeNetwork(quote.cryptoCurrency).toLowerCase();
final paymentMethod = normalizePaymentMethod(quote.paymentType); final paymentMethod = normalizePaymentMethod(quote.paymentType);
final uri = Uri.https(_baseUrl, '', { final uri = Uri.https(_baseUrl, '', {
'apiKey': _apiKey, 'apiKey': _apiKey,
'mode': actionType, 'txnType': actionType,
'${prefix}defaultFiat': quote.fiatCurrency.name, 'txnFiat': quote.fiatCurrency.name,
'${prefix}defaultCrypto': defaultCrypto, 'txnCrypto': defaultCrypto,
'${prefix}defaultAmount': amount.toString(), 'txnAmount': amount.toString(),
if (paymentMethod != null) '${prefix}defaultPaymentMethod': paymentMethod, 'skipTransactionScreen': "true",
'onlyOnramps': quote.rampId, if (paymentMethod != null) 'txnPaymentMethod': paymentMethod,
'txnOnramp': quote.rampId,
'networkWallets': '${_tagToNetwork(quote.cryptoCurrency.tag ?? quote.cryptoCurrency.title)}:$cryptoCurrencyAddress', 'networkWallets': '${_tagToNetwork(quote.cryptoCurrency.tag ?? quote.cryptoCurrency.title)}:$cryptoCurrencyAddress',
'supportSwap': "false", 'supportSwap': "false",
'primaryColor': primaryColor, 'primaryColor': primaryColor,
@ -257,31 +254,29 @@ class OnRamperBuyProvider extends BuyProvider {
String _tagToNetwork(String tag) { String _tagToNetwork(String tag) {
switch (tag) { switch (tag) {
case 'OMNI':
case 'BSC':
return tag;
case 'POL': case 'POL':
return 'POLYGON'; return 'POLYGON';
case 'ETH':
return 'ETHEREUM';
case 'TRX':
return 'TRON';
case 'SOL':
return 'SOLANA';
case 'ZEC': case 'ZEC':
return 'ZCASH'; return 'ZCASH';
default: default:
try { return tag;
return CryptoCurrency.fromString(tag).fullName!;
} catch (_) {
return tag;
}
} }
} }
String _getNormalizeCryptoCurrency(Currency currency) { String _getNormalizeNetwork(CryptoCurrency currency) {
if (currency is CryptoCurrency) { if (mainCurrency.contains(currency)) return '';
if (!mainCurrency.contains(currency)) {
final network = currency.tag == null ? currency.fullName : _tagToNetwork(currency.tag!); if (currency == CryptoCurrency.eos) return '_EOSIO';
return '${currency.title}_${network?.replaceAll(' ', '')}'.toUpperCase();
} if (currency.tag != null) return '_' + _tagToNetwork(currency.tag!);
return currency.title.toUpperCase();
} return '_' + (currency.fullName?.replaceAll(' ', '') ?? currency.title);;
return currency.name.toUpperCase();
} }
String? normalizePaymentMethod(PaymentType paymentType) { String? normalizePaymentMethod(PaymentType paymentType) {