mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-03 12:24:19 +01:00
Migrate to new Chainflip endpoints (#2386)
* feat: migrate to new chainflip endpoints * chore: remove debug comments
This commit is contained in:
@@ -37,7 +37,7 @@ class ChainflipExchangeProvider extends ExchangeProvider {
|
|||||||
|
|
||||||
static const _baseURL = 'chainflip-broker.io';
|
static const _baseURL = 'chainflip-broker.io';
|
||||||
static const _assetsPath = '/assets';
|
static const _assetsPath = '/assets';
|
||||||
static const _quotePath = '/quote-native';
|
static const _quotePath = '/quotes-native';
|
||||||
static const _swapPath = '/swap';
|
static const _swapPath = '/swap';
|
||||||
static const _txInfoPath = '/status-by-deposit-channel';
|
static const _txInfoPath = '/status-by-deposit-channel';
|
||||||
static const _affiliateBps = secrets.chainflipAffiliateFee;
|
static const _affiliateBps = secrets.chainflipAffiliateFee;
|
||||||
@@ -145,6 +145,13 @@ class ChainflipExchangeProvider extends ExchangeProvider {
|
|||||||
'retryDurationInBlocks': '150'
|
'retryDurationInBlocks': '150'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (quoteResponse.containsKey('numberOfChunks') && quoteResponse.containsKey('chunkIntervalBlocks')) {
|
||||||
|
swapParams.addAll({
|
||||||
|
'numberOfChunks': quoteResponse['numberOfChunks'].toString(),
|
||||||
|
'chunkIntervalBlocks': quoteResponse['chunkIntervalBlocks'].toString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
final swapResponse = await _openDepositChannel(swapParams);
|
final swapResponse = await _openDepositChannel(swapParams);
|
||||||
|
|
||||||
final id = '${swapResponse['issuedBlock']}-${swapResponse['network'].toString().toUpperCase()}-${swapResponse['channelId']}';
|
final id = '${swapResponse['issuedBlock']}-${swapResponse['network'].toString().toUpperCase()}-${swapResponse['channelId']}';
|
||||||
@@ -266,9 +273,6 @@ class ChainflipExchangeProvider extends ExchangeProvider {
|
|||||||
Future<Map<String, dynamic>> _getAssets() async =>
|
Future<Map<String, dynamic>> _getAssets() async =>
|
||||||
_getRequest(_assetsPath, {});
|
_getRequest(_assetsPath, {});
|
||||||
|
|
||||||
Future<Map<String, dynamic>> _getSwapQuote(Map<String, String> params) async =>
|
|
||||||
_getRequest(_quotePath, params);
|
|
||||||
|
|
||||||
Future<Map<String, dynamic>> _openDepositChannel(Map<String, String> params) async =>
|
Future<Map<String, dynamic>> _openDepositChannel(Map<String, String> params) async =>
|
||||||
_getRequest(_swapPath, params);
|
_getRequest(_swapPath, params);
|
||||||
|
|
||||||
@@ -277,7 +281,6 @@ class ChainflipExchangeProvider extends ExchangeProvider {
|
|||||||
|
|
||||||
final response = await ProxyWrapper().get(clearnetUri: uri);
|
final response = await ProxyWrapper().get(clearnetUri: uri);
|
||||||
|
|
||||||
|
|
||||||
if ((response.statusCode != 200) || (response.body.contains('error'))) {
|
if ((response.statusCode != 200) || (response.body.contains('error'))) {
|
||||||
throw Exception('Unexpected response: ${response.statusCode} / ${uri.toString()} / ${response.body}');
|
throw Exception('Unexpected response: ${response.statusCode} / ${uri.toString()} / ${response.body}');
|
||||||
}
|
}
|
||||||
@@ -285,12 +288,32 @@ class ChainflipExchangeProvider extends ExchangeProvider {
|
|||||||
return json.decode(response.body) as Map<String, dynamic>;
|
return json.decode(response.body) as Map<String, dynamic>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> _getSwapQuote(Map<String, String> params) async {
|
||||||
|
final uri = Uri.https(_baseURL, _quotePath, params);
|
||||||
|
|
||||||
|
final response = await ProxyWrapper().get(clearnetUri: uri);
|
||||||
|
|
||||||
|
if ((response.statusCode != 200) || (response.body.contains('error'))) {
|
||||||
|
throw Exception('Unexpected response: ${response.statusCode} / ${uri.toString()} / ${response.body}');
|
||||||
|
}
|
||||||
|
|
||||||
|
final quotes = json.decode(response.body) as List<dynamic>;
|
||||||
|
|
||||||
|
Map<String, dynamic> highestQuote = quotes.reduce((current, next) {
|
||||||
|
double currentAmount = current['egressAmount'];
|
||||||
|
double nextAmount = next['egressAmount'];
|
||||||
|
|
||||||
|
return currentAmount > nextAmount ? current : next;
|
||||||
|
});
|
||||||
|
|
||||||
|
return highestQuote;
|
||||||
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>?> _getStatus(Map<String, String> params) async {
|
Future<Map<String, dynamic>?> _getStatus(Map<String, String> params) async {
|
||||||
final uri = Uri.https(_baseURL, _txInfoPath, params);
|
final uri = Uri.https(_baseURL, _txInfoPath, params);
|
||||||
|
|
||||||
final response = await ProxyWrapper().get(clearnetUri: uri);
|
final response = await ProxyWrapper().get(clearnetUri: uri);
|
||||||
|
|
||||||
|
|
||||||
if (response.statusCode == 404) return null;
|
if (response.statusCode == 404) return null;
|
||||||
|
|
||||||
if ((response.statusCode != 200) || (response.body.contains('error'))) {
|
if ((response.statusCode != 200) || (response.body.contains('error'))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user