Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions lib/buy/moonpay/moonpay_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MoonPayProvider extends BuyProvider {
@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();

Expand All @@ -96,8 +96,9 @@ class MoonPayProvider extends BuyProvider {
}
}

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,
Expand All @@ -107,7 +108,8 @@ class MoonPayProvider extends BuyProvider {


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}');
Expand Down Expand Up @@ -297,18 +299,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 {
Expand Down
1 change: 1 addition & 0 deletions tool/utils/secret_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SecretKey {
SecretKey('wyreApiKey', () => ''),
SecretKey('wyreAccountId', () => ''),
SecretKey('moonPayApiKey', () => ''),
SecretKey('moonPaySandboxApiKey', () => ''),
SecretKey('moonPaySecretKey', () => ''),
SecretKey('sideShiftAffiliateId', () => ''),
SecretKey('simpleSwapApiKey', () => ''),
Expand Down
Loading