mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
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]
This commit is contained in:
@@ -29,6 +29,7 @@ class OnRamperBuyProvider extends BuyProvider {
|
||||
|
||||
static const _baseUrl = 'buy.onramper.com';
|
||||
static const _baseApiUrl = 'api.onramper.com';
|
||||
static const _cIdBaseUrl = 'exchange-helper.cakewallet.com';
|
||||
static const quotes = '/quotes';
|
||||
static const paymentTypes = '/payment-types';
|
||||
static const supported = '/supported';
|
||||
@@ -44,6 +45,8 @@ class OnRamperBuyProvider extends BuyProvider {
|
||||
|
||||
String get _apiKey => secrets.onramperApiKey;
|
||||
|
||||
String get _exchangeHelperApiKey => secrets.exchangeHelperApiKey;
|
||||
|
||||
@override
|
||||
String get title => 'Onramper';
|
||||
|
||||
@@ -59,6 +62,24 @@ class OnRamperBuyProvider extends BuyProvider {
|
||||
@override
|
||||
bool get isAggregator => true;
|
||||
|
||||
Future<String> getOnramperSignature(String query) async {
|
||||
final uri = Uri.https(_cIdBaseUrl, "/api/onramper");
|
||||
|
||||
final response = await ProxyWrapper().post(
|
||||
clearnetUri: uri,
|
||||
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;
|
||||
} else {
|
||||
throw Exception(
|
||||
'Provider currently unavailable. Status: ${response.statusCode} ${response.body}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> getRecommendedPaymentType(bool isBuyAction) async {
|
||||
|
||||
final params = {'type': isBuyAction ? 'buy' : 'sell'};
|
||||
@@ -261,6 +282,11 @@ class OnRamperBuyProvider extends BuyProvider {
|
||||
|
||||
final paymentMethod = quote.paymentType == PaymentType.unknown ? quote.customPaymentMethodType : normalizePaymentMethod(quote.paymentType);
|
||||
|
||||
final networkWallets =
|
||||
'${_tagToNetwork(quote.cryptoCurrency.tag ?? quote.cryptoCurrency.title).toLowerCase()}:$cryptoCurrencyAddress';
|
||||
|
||||
final signature = await getOnramperSignature("networkWallets=$networkWallets");
|
||||
|
||||
final uri = Uri.https(_baseUrl, '', {
|
||||
'apiKey': _apiKey,
|
||||
'txnType': actionType,
|
||||
@@ -270,7 +296,7 @@ class OnRamperBuyProvider extends BuyProvider {
|
||||
'skipTransactionScreen': "true",
|
||||
if (paymentMethod != null) 'txnPaymentMethod': paymentMethod,
|
||||
'txnOnramp': quote.rampId,
|
||||
'networkWallets': '${_tagToNetwork(quote.cryptoCurrency.tag ?? quote.cryptoCurrency.title)}:$cryptoCurrencyAddress',
|
||||
'networkWallets': networkWallets,
|
||||
'supportSwap': "false",
|
||||
'primaryColor': primaryColor,
|
||||
'secondaryColor': secondaryColor,
|
||||
@@ -278,6 +304,7 @@ class OnRamperBuyProvider extends BuyProvider {
|
||||
'primaryTextColor': primaryTextColor,
|
||||
'secondaryTextColor': secondaryTextColor,
|
||||
'cardColor': cardColor,
|
||||
'signature': signature,
|
||||
});
|
||||
|
||||
if (await canLaunchUrl(uri)) {
|
||||
@@ -422,5 +449,6 @@ class OnRamperBuyProvider extends BuyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
String getColorStr(Color color) => color.value.toRadixString(16).replaceAll(RegExp(r'^ff'), "");
|
||||
String getColorStr(Color color) =>
|
||||
color.toARGB32().toRadixString(16).replaceAll(RegExp(r'^ff'), "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user