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 17:26:58 +00:00
|
|
|
|
|
|
|
import '../../../app_config.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 '../exchange.dart';
|
|
|
|
import '../exchange_response.dart';
|
|
|
|
import 'simpleswap_api.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
class SimpleSwapExchange extends Exchange {
|
2023-02-05 20:32:39 +00:00
|
|
|
SimpleSwapExchange._();
|
|
|
|
|
|
|
|
static SimpleSwapExchange? _instance;
|
|
|
|
static SimpleSwapExchange get instance =>
|
|
|
|
_instance ??= SimpleSwapExchange._();
|
|
|
|
|
2022-10-03 00:54:35 +00:00
|
|
|
static const exchangeName = "SimpleSwap";
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get name => exchangeName;
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
@override
|
|
|
|
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
|
|
|
}) async {
|
|
|
|
return await SimpleSwapAPI.instance.createNewExchange(
|
|
|
|
isFixedRate: fixedRate,
|
|
|
|
currencyFrom: from,
|
|
|
|
currencyTo: to,
|
|
|
|
addressTo: addressTo,
|
|
|
|
userRefundAddress: addressRefund,
|
|
|
|
userRefundExtraId: refundExtraId,
|
|
|
|
amount: amount.toString(),
|
2022-10-03 00:54:35 +00:00
|
|
|
extraIdTo: extraId,
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<ExchangeResponse<List<Currency>>> getAllCurrencies(
|
|
|
|
bool fixedRate,
|
|
|
|
) async {
|
|
|
|
final response =
|
|
|
|
await SimpleSwapAPI.instance.getAllCurrencies(fixedRate: fixedRate);
|
|
|
|
if (response.value != null) {
|
|
|
|
final List<Currency> currencies = response.value!
|
2023-02-05 20:32:39 +00:00
|
|
|
.map(
|
|
|
|
(e) => Currency(
|
|
|
|
exchangeName: exchangeName,
|
|
|
|
ticker: e.symbol,
|
|
|
|
name: e.name,
|
|
|
|
network: e.network,
|
|
|
|
image: e.image,
|
|
|
|
externalId: e.extraId,
|
|
|
|
isFiat: false,
|
2023-02-06 15:23:31 +00:00
|
|
|
rateType: fixedRate
|
|
|
|
? SupportedRateType.both
|
|
|
|
: SupportedRateType.estimated,
|
2023-02-05 20:32:39 +00:00
|
|
|
isAvailable: true,
|
2024-05-23 17:26:58 +00:00
|
|
|
isStackCoin: AppConfig.isStackCoin(e.symbol),
|
2023-02-28 20:27:42 +00:00
|
|
|
tokenContract: null,
|
2023-02-05 20:32:39 +00:00
|
|
|
),
|
|
|
|
)
|
2022-10-02 19:37:11 +00:00
|
|
|
.toList();
|
|
|
|
return ExchangeResponse<List<Currency>>(
|
|
|
|
value: currencies,
|
|
|
|
exception: response.exception,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExchangeResponse<List<Currency>>(
|
|
|
|
value: null,
|
|
|
|
exception: response.exception,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<ExchangeResponse<List<Pair>>> getAllPairs(bool fixedRate) async {
|
|
|
|
return await SimpleSwapAPI.instance.getAllPairs(isFixedRate: fixedRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
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
|
|
|
) async {
|
|
|
|
final response = await SimpleSwapAPI.instance.getEstimated(
|
|
|
|
isFixedRate: fixedRate,
|
|
|
|
currencyFrom: from,
|
|
|
|
currencyTo: to,
|
|
|
|
amount: amount.toString(),
|
|
|
|
);
|
2022-10-03 16:30:50 +00:00
|
|
|
if (response.exception != null) {
|
|
|
|
return ExchangeResponse(
|
|
|
|
exception: response.exception,
|
|
|
|
);
|
|
|
|
}
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
return ExchangeResponse(
|
2023-05-01 22:26:12 +00:00
|
|
|
value: [
|
|
|
|
Estimate(
|
|
|
|
estimatedAmount: Decimal.parse(response.value!),
|
|
|
|
fixedRate: fixedRate,
|
|
|
|
reversed: reversed,
|
|
|
|
exchangeProvider: SimpleSwapExchange.exchangeName,
|
|
|
|
),
|
|
|
|
],
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
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,
|
|
|
|
) async {
|
|
|
|
return await SimpleSwapAPI.instance.getRange(
|
|
|
|
isFixedRate: fixedRate,
|
|
|
|
currencyFrom: from,
|
|
|
|
currencyTo: to,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<ExchangeResponse<List<Pair>>> getPairsFor(
|
|
|
|
String currency,
|
|
|
|
bool fixedRate,
|
|
|
|
) async {
|
|
|
|
// return await SimpleSwapAPI.instance.ge
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<ExchangeResponse<Trade>> getTrade(String tradeId) async {
|
|
|
|
return await SimpleSwapAPI.instance.getExchange(exchangeId: tradeId);
|
|
|
|
}
|
|
|
|
|
2022-10-02 21:48:43 +00:00
|
|
|
@override
|
|
|
|
Future<ExchangeResponse<Trade>> updateTrade(Trade trade) async {
|
|
|
|
return await SimpleSwapAPI.instance.getExchange(
|
|
|
|
exchangeId: trade.tradeId,
|
|
|
|
oldTrade: trade,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
@override
|
|
|
|
Future<ExchangeResponse<List<Trade>>> getTrades() async {
|
|
|
|
// TODO: implement getTrades
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|
2023-02-13 15:05:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<ExchangeResponse<List<Currency>>> getPairedCurrencies(
|
2024-05-27 23:56:22 +00:00
|
|
|
String forCurrency,
|
|
|
|
bool fixedRate,
|
|
|
|
) {
|
2023-02-13 15:05:22 +00:00
|
|
|
// TODO: implement getPairedCurrencies
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|
2022-10-02 19:37:11 +00:00
|
|
|
}
|