2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
import 'package:decimal/decimal.dart';
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../../models/exchange/response_objects/estimate.dart';
|
|
|
|
import '../../models/exchange/response_objects/range.dart';
|
|
|
|
import '../../models/exchange/response_objects/trade.dart';
|
|
|
|
import '../../models/isar/exchange_cache/currency.dart';
|
|
|
|
import '../../models/isar/exchange_cache/pair.dart';
|
|
|
|
import 'change_now/change_now_exchange.dart';
|
|
|
|
import 'exchange_response.dart';
|
|
|
|
import 'majestic_bank/majestic_bank_exchange.dart';
|
|
|
|
import 'simpleswap/simpleswap_exchange.dart';
|
|
|
|
import 'trocador/trocador_exchange.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
abstract class Exchange {
|
2023-02-05 20:32:39 +00:00
|
|
|
static Exchange get defaultExchange => ChangeNowExchange.instance;
|
|
|
|
|
2022-10-04 17:06:14 +00:00
|
|
|
static Exchange fromName(String name) {
|
|
|
|
switch (name) {
|
|
|
|
case ChangeNowExchange.exchangeName:
|
2023-02-05 20:32:39 +00:00
|
|
|
return ChangeNowExchange.instance;
|
2022-10-04 17:06:14 +00:00
|
|
|
case SimpleSwapExchange.exchangeName:
|
2023-02-05 20:32:39 +00:00
|
|
|
return SimpleSwapExchange.instance;
|
|
|
|
case MajesticBankExchange.exchangeName:
|
|
|
|
return MajesticBankExchange.instance;
|
2023-04-28 20:31:26 +00:00
|
|
|
case TrocadorExchange.exchangeName:
|
|
|
|
return TrocadorExchange.instance;
|
2022-10-04 17:06:14 +00:00
|
|
|
default:
|
2023-04-28 20:40:36 +00:00
|
|
|
final split = name.split(" ");
|
|
|
|
if (split.length >= 2) {
|
|
|
|
// silly way to check for 'Trocador ($providerName)'
|
|
|
|
return fromName(split.first);
|
|
|
|
}
|
2022-10-04 17:06:14 +00:00
|
|
|
throw ArgumentError("Unknown exchange name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 00:54:35 +00:00
|
|
|
String get name;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
Future<ExchangeResponse<List<Currency>>> getAllCurrencies(bool fixedRate);
|
|
|
|
|
2023-02-13 15:05:22 +00:00
|
|
|
Future<ExchangeResponse<List<Currency>>> getPairedCurrencies(
|
|
|
|
String forCurrency,
|
|
|
|
bool fixedRate,
|
|
|
|
);
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
Future<ExchangeResponse<List<Pair>>> getPairsFor(
|
|
|
|
String currency,
|
|
|
|
bool fixedRate,
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<ExchangeResponse<List<Pair>>> getAllPairs(bool fixedRate);
|
|
|
|
|
|
|
|
Future<ExchangeResponse<Trade>> getTrade(String tradeId);
|
2022-10-02 21:48:43 +00:00
|
|
|
Future<ExchangeResponse<Trade>> updateTrade(Trade trade);
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
Future<ExchangeResponse<List<Trade>>> getTrades();
|
|
|
|
|
2022-10-02 21:48:43 +00:00
|
|
|
Future<ExchangeResponse<Range>> getRange(
|
2022-10-02 19:37:11 +00:00
|
|
|
String from,
|
|
|
|
String to,
|
|
|
|
bool fixedRate,
|
|
|
|
);
|
|
|
|
|
2023-05-01 22:26:12 +00:00
|
|
|
Future<ExchangeResponse<List<Estimate>>> getEstimates(
|
2022-10-02 19:37:11 +00:00
|
|
|
String from,
|
|
|
|
String to,
|
|
|
|
Decimal amount,
|
|
|
|
bool fixedRate,
|
2022-10-02 21:48:43 +00:00
|
|
|
bool reversed,
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Future<ExchangeResponse<Trade>> createTrade({
|
|
|
|
required String from,
|
|
|
|
required String to,
|
|
|
|
required bool fixedRate,
|
|
|
|
required Decimal amount,
|
|
|
|
required String addressTo,
|
2022-10-03 00:54:35 +00:00
|
|
|
String? extraId,
|
2022-10-02 19:37:11 +00:00
|
|
|
required String addressRefund,
|
|
|
|
required String refundExtraId,
|
2023-04-28 20:29:10 +00:00
|
|
|
Estimate? estimate,
|
2022-10-04 00:55:12 +00:00
|
|
|
required bool reversed,
|
2022-10-02 19:37:11 +00:00
|
|
|
});
|
2023-09-11 21:31:48 +00:00
|
|
|
|
2023-09-11 23:07:59 +00:00
|
|
|
/// List of exchanges which support Tor.
|
|
|
|
///
|
|
|
|
/// Add to this list when adding a new exchange which supports Tor.
|
|
|
|
static List<Exchange> get exchangesWithTorSupport => [
|
|
|
|
MajesticBankExchange.instance,
|
|
|
|
TrocadorExchange.instance,
|
|
|
|
];
|
|
|
|
|
|
|
|
/// List of exchange names which support Tor.
|
|
|
|
///
|
|
|
|
/// Convenience method for when you just want to check for a String
|
|
|
|
/// .exchangeName instead of Exchange instances. Shouldn't need to be updated
|
|
|
|
/// as long as the above List is updated.
|
|
|
|
static List<String> get exchangeNamesWithTorSupport =>
|
|
|
|
exchangesWithTorSupport.map((exchange) => exchange.name).toList();
|
|
|
|
// Instead of using this, you can do like:
|
2023-09-11 23:12:56 +00:00
|
|
|
// currencies.removeWhere((element) =>
|
|
|
|
// !Exchange.exchangesWithTorSupport.any((e) => e.name == element.exchangeName)
|
|
|
|
// );
|
|
|
|
// But this helper may be more readable.
|
2022-10-02 19:37:11 +00:00
|
|
|
}
|