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
53 changes: 15 additions & 38 deletions lib/services/exchange/trocador/trocador_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ const kTrocadorRefCode = "9eHm9BkQfS";
abstract class TrocadorAPI {
static const String authority = "api.trocador.app";
static const String onionAuthority =
"trocadorfyhlu27aefre5u7zri66gudtzdyelymftvr4yjwcxhfaqsid.onion";
"65bsisadnxvw4kfz7h7a3jwcyenrhluuj3kd5toslfzxbk5q4m3wy6qd.onion";

static const String markup = "1";
static const String minKYCRating = "C";
static HTTP client = HTTP();

static Uri _buildUri({
required String method,
required bool isOnion,
Map<String, String>? params,
}) {
return isOnion
static bool get _useTor =>
AppConfig.hasFeature(AppFeature.tor) && Prefs.instance.useTor;

static Uri _buildUri({required String method, Map<String, String>? params}) {
return _useTor
? Uri.http(onionAuthority, method, params)
: Uri.https(authority, method, params);
}
Expand All @@ -57,11 +56,7 @@ abstract class TrocadorAPI {
"Content-Type": "application/json",
"API-KEY": kTrocadorApiKey,
},
proxyInfo: !AppConfig.hasFeature(AppFeature.tor)
? null
: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
proxyInfo: _useTor ? TorService.sharedInstance.getProxyInfo() : null,
);

code = response.code;
Expand All @@ -87,14 +82,8 @@ abstract class TrocadorAPI {
}

/// fetch all supported coins
static Future<ExchangeResponse<List<TrocadorCoin>>> getCoins({
required bool isOnion,
}) async {
final uri = _buildUri(
isOnion: isOnion,
method: "coins",
params: {"ref": kTrocadorRefCode},
);
static Future<ExchangeResponse<List<TrocadorCoin>>> getCoins() async {
final uri = _buildUri(method: "coins", params: {"ref": kTrocadorRefCode});

try {
final json = await _makeGetRequest(uri);
Expand Down Expand Up @@ -122,11 +111,9 @@ abstract class TrocadorAPI {

/// get trade info
static Future<ExchangeResponse<TrocadorTrade>> getTrade({
required bool isOnion,
required String tradeId,
}) async {
final uri = _buildUri(
isOnion: isOnion,
method: "trade",
params: {"ref": kTrocadorRefCode, "id": tradeId},
);
Expand All @@ -149,7 +136,6 @@ abstract class TrocadorAPI {

/// get standard/floating rate
static Future<ExchangeResponse<TrocadorRate>> getNewStandardRate({
required bool isOnion,
required String fromTicker,
required String fromNetwork,
required String toTicker,
Expand All @@ -168,12 +154,11 @@ abstract class TrocadorAPI {
"markup": markup,
};

return await _getNewRate(isOnion: isOnion, params: params);
return await _getNewRate(params: params);
}

/// get fixed rate/payment rate
static Future<ExchangeResponse<TrocadorRate>> getNewPaymentRate({
required bool isOnion,
required String fromTicker,
required String fromNetwork,
required String toTicker,
Expand All @@ -192,14 +177,13 @@ abstract class TrocadorAPI {
"markup": markup,
};

return await _getNewRate(isOnion: isOnion, params: params);
return await _getNewRate(params: params);
}

static Future<ExchangeResponse<TrocadorRate>> _getNewRate({
required bool isOnion,
required Map<String, String> params,
}) async {
final uri = _buildUri(isOnion: isOnion, method: "new_rate", params: params);
final uri = _buildUri(method: "new_rate", params: params);

try {
final json = await _makeGetRequest(uri);
Expand All @@ -219,7 +203,6 @@ abstract class TrocadorAPI {

/// create new floating rate/standard trade
static Future<ExchangeResponse<TrocadorTradeNew>> createNewStandardRateTrade({
required bool isOnion,
required String? rateId,
required String fromTicker,
required String fromNetwork,
Expand Down Expand Up @@ -255,11 +238,10 @@ abstract class TrocadorAPI {
params["id"] = rateId;
}

return await _getNewTrade(isOnion: isOnion, params: params);
return await _getNewTrade(params: params);
}

static Future<ExchangeResponse<TrocadorTradeNew>> createNewPaymentRateTrade({
required bool isOnion,
required String? rateId,
required String fromTicker,
required String fromNetwork,
Expand Down Expand Up @@ -295,18 +277,13 @@ abstract class TrocadorAPI {
params["id"] = rateId;
}

return await _getNewTrade(isOnion: isOnion, params: params);
return await _getNewTrade(params: params);
}

static Future<ExchangeResponse<TrocadorTradeNew>> _getNewTrade({
required bool isOnion,
required Map<String, String> params,
}) async {
final uri = _buildUri(
isOnion: isOnion,
method: "new_trade",
params: params,
);
final uri = _buildUri(method: "new_trade", params: params);

try {
final json = await _makeGetRequest(uri);
Expand Down
11 changes: 2 additions & 9 deletions lib/services/exchange/trocador/trocador_exchange.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class TrocadorExchange extends Exchange {
}) async {
final response = reversed
? await TrocadorAPI.createNewPaymentRateTrade(
isOnion: false,
rateId: estimate?.rateId,
fromTicker: from.toLowerCase(),
fromNetwork: onlySupportedNetwork,
Expand All @@ -84,7 +83,6 @@ class TrocadorExchange extends Exchange {
isFixedRate: fixedRate,
)
: await TrocadorAPI.createNewStandardRateTrade(
isOnion: false,
rateId: estimate?.rateId,
fromTicker: from.toLowerCase(),
fromNetwork: onlySupportedNetwork,
Expand Down Expand Up @@ -139,7 +137,7 @@ class TrocadorExchange extends Exchange {
Future<ExchangeResponse<List<Currency>>> getAllCurrencies(
bool fixedRate,
) async {
_cachedCurrencies ??= (await TrocadorAPI.getCoins(isOnion: false)).value;
_cachedCurrencies ??= (await TrocadorAPI.getCoins()).value;

_cachedCurrencies?.removeWhere((e) => e.network != onlySupportedNetwork);

Expand Down Expand Up @@ -222,15 +220,13 @@ class TrocadorExchange extends Exchange {
) async {
final response = reversed
? await TrocadorAPI.getNewPaymentRate(
isOnion: false,
fromTicker: from,
fromNetwork: onlySupportedNetwork,
toTicker: to,
toNetwork: onlySupportedNetwork,
toAmount: amount.toString(),
)
: await TrocadorAPI.getNewStandardRate(
isOnion: false,
fromTicker: from,
fromNetwork: onlySupportedNetwork,
toTicker: to,
Expand Down Expand Up @@ -367,10 +363,7 @@ class TrocadorExchange extends Exchange {

@override
Future<ExchangeResponse<Trade>> updateTrade(Trade trade) async {
final response = await TrocadorAPI.getTrade(
isOnion: false,
tradeId: trade.tradeId,
);
final response = await TrocadorAPI.getTrade(tradeId: trade.tradeId);

if (response.value != null) {
final updated = response.value!;
Expand Down
Loading