feat: integrate `getOnramperSignature` method and add support for retrieving Onramper signature (#2553)

* feat: integrate `getOnramperSignature` method and add support for retrieving Onramper signature * fix: make `getOnramperSignature` call asynchronous * fix: normalize networkWallets parameter to lowercase [skip ci]

Konstantin Ullrich committed Oct 2, 2025 at 17:45 UTC 80bba64c2609641f819fd8e2635a4839eec4ab16
1 file changed +30 -2
lib/buy/onramper/onramper_buy_provider.dart
+30 -2
@@ -29,6 +29,7 @@ class OnRamperBuyProvider extends BuyProvider {
29
30 static const _baseUrl = 'buy.onramper.com';
31 static const _baseApiUrl = 'api.onramper.com';
32 + static const _cIdBaseUrl = 'exchange-helper.cakewallet.com';
33 static const quotes = '/quotes';
34 static const paymentTypes = '/payment-types';
35 static const supported = '/supported';
@@ -44,6 +45,8 @@ class OnRamperBuyProvider extends BuyProvider {
45
46 String get _apiKey => secrets.onramperApiKey;
47
48 + String get _exchangeHelperApiKey => secrets.exchangeHelperApiKey;
49 +
50 @override
51 String get title => 'Onramper';
52
@@ -59,6 +62,24 @@ class OnRamperBuyProvider extends BuyProvider {
62 @override
63 bool get isAggregator => true;
64
65 + Future<String> getOnramperSignature(String query) async {
66 + final uri = Uri.https(_cIdBaseUrl, "/api/onramper");
67 +
68 + final response = await ProxyWrapper().post(
69 + clearnetUri: uri,
70 + headers: {'Content-Type': 'application/json', 'x-api-key': _exchangeHelperApiKey},
71 + body: json.encode({'query': query}),
72 + );
73 +
74 +
75 + if (response.statusCode == 200) {
76 + return (jsonDecode(response.body) as Map<String, dynamic>)['signature'] as String;
77 + } else {
78 + throw Exception(
79 + 'Provider currently unavailable. Status: ${response.statusCode} ${response.body}');
80 + }
81 + }
82 +
83 Future<String?> getRecommendedPaymentType(bool isBuyAction) async {
84
85 final params = {'type': isBuyAction ? 'buy' : 'sell'};
@@ -261,6 +282,11 @@ class OnRamperBuyProvider extends BuyProvider {
282
283 final paymentMethod = quote.paymentType == PaymentType.unknown ? quote.customPaymentMethodType : normalizePaymentMethod(quote.paymentType);
284
285 + final networkWallets =
286 + '${_tagToNetwork(quote.cryptoCurrency.tag ?? quote.cryptoCurrency.title).toLowerCase()}:$cryptoCurrencyAddress';
287 +
288 + final signature = await getOnramperSignature("networkWallets=$networkWallets");
289 +
290 final uri = Uri.https(_baseUrl, '', {
291 'apiKey': _apiKey,
292 'txnType': actionType,
@@ -270,7 +296,7 @@ class OnRamperBuyProvider extends BuyProvider {
296 'skipTransactionScreen': "true",
297 if (paymentMethod != null) 'txnPaymentMethod': paymentMethod,
298 'txnOnramp': quote.rampId,
273 - 'networkWallets': '${_tagToNetwork(quote.cryptoCurrency.tag ?? quote.cryptoCurrency.title)}:$cryptoCurrencyAddress',
299 + 'networkWallets': networkWallets,
300 'supportSwap': "false",
301 'primaryColor': primaryColor,
302 'secondaryColor': secondaryColor,
@@ -278,6 +304,7 @@ class OnRamperBuyProvider extends BuyProvider {
304 'primaryTextColor': primaryTextColor,
305 'secondaryTextColor': secondaryTextColor,
306 'cardColor': cardColor,
307 + 'signature': signature,
308 });
309
310 if (await canLaunchUrl(uri)) {
@@ -422,5 +449,6 @@ class OnRamperBuyProvider extends BuyProvider {
449 }
450 }
451
425 - String getColorStr(Color color) => color.value.toRadixString(16).replaceAll(RegExp(r'^ff'), "");
452 + String getColorStr(Color color) =>
453 + color.toARGB32().toRadixString(16).replaceAll(RegExp(r'^ff'), "");
454 }