stack_wallet/lib/services/exchange/exchange.dart

84 lines
2.7 KiB
Dart
Raw Normal View History

2022-10-02 19:37:11 +00:00
import 'package:decimal/decimal.dart';
2022-10-03 16:30:50 +00:00
import 'package:stackwallet/models/exchange/response_objects/estimate.dart';
2022-10-02 19:37:11 +00:00
import 'package:stackwallet/models/exchange/response_objects/range.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
import 'package:stackwallet/models/isar/exchange_cache/pair.dart';
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
2022-10-02 19:37:11 +00:00
import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart';
import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
2023-04-28 20:31:26 +00:00
import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
2022-10-02 19:37:11 +00:00
abstract class Exchange {
static Exchange get defaultExchange => ChangeNowExchange.instance;
static Exchange fromName(String name) {
switch (name) {
case ChangeNowExchange.exchangeName:
return ChangeNowExchange.instance;
case SimpleSwapExchange.exchangeName:
return SimpleSwapExchange.instance;
case MajesticBankExchange.exchangeName:
return MajesticBankExchange.instance;
2023-04-28 20:31:26 +00:00
case TrocadorExchange.exchangeName:
return TrocadorExchange.instance;
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);
}
throw ArgumentError("Unknown exchange name");
}
}
String get name;
2022-10-02 19:37:11 +00:00
Future<ExchangeResponse<List<Currency>>> getAllCurrencies(bool fixedRate);
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,
);
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,
String? extraId,
2022-10-02 19:37:11 +00:00
required String addressRefund,
required String refundExtraId,
Estimate? estimate,
required bool reversed,
2022-10-02 19:37:11 +00:00
});
}