mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 03:29:36 +00:00
Cw 807 add extra fields for xrp and xlm exchanges (#1869)
Some checks are pending
Cache Dependencies / test (push) Waiting to run
Some checks are pending
Cache Dependencies / test (push) Waiting to run
* show extra id for xrp/xlm Stealth * extra id for xrp/xlm LetsExchange * extra id xrp/xml for Sideshift and Trocador * fix Exolix min amount issue * fix extra id ui
This commit is contained in:
parent
df6ea551aa
commit
489a409bea
11 changed files with 102 additions and 27 deletions
|
@ -60,15 +60,17 @@ class ExolixExchangeProvider extends ExchangeProvider {
|
|||
Future<bool> checkIsAvailable() async => true;
|
||||
|
||||
@override
|
||||
Future<Limits> fetchLimits(
|
||||
{required CryptoCurrency from,
|
||||
required CryptoCurrency to,
|
||||
required bool isFixedRateMode}) async {
|
||||
Future<Limits> fetchLimits({
|
||||
required CryptoCurrency from,
|
||||
required CryptoCurrency to,
|
||||
required bool isFixedRateMode,
|
||||
}) async {
|
||||
final params = <String, String>{
|
||||
'rateType': _getRateType(isFixedRateMode),
|
||||
'amount': '1',
|
||||
'apiToken': apiKey,
|
||||
};
|
||||
|
||||
if (isFixedRateMode) {
|
||||
params['coinFrom'] = _normalizeCurrency(to);
|
||||
params['coinTo'] = _normalizeCurrency(from);
|
||||
|
@ -80,14 +82,30 @@ class ExolixExchangeProvider extends ExchangeProvider {
|
|||
params['networkFrom'] = _networkFor(from);
|
||||
params['networkTo'] = _networkFor(to);
|
||||
}
|
||||
final uri = Uri.https(apiBaseUrl, ratePath, params);
|
||||
final response = await get(uri);
|
||||
|
||||
if (response.statusCode != 200)
|
||||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
// Maximum of 2 attempts to fetch limits
|
||||
for (int i = 0; i < 2; i++) {
|
||||
final uri = Uri.https(apiBaseUrl, ratePath, params);
|
||||
final response = await get(uri);
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
return Limits(min: responseJSON['minAmount'] as double?);
|
||||
if (response.statusCode == 200) {
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final minAmount = responseJSON['minAmount'];
|
||||
final maxAmount = responseJSON['maxAmount'];
|
||||
return Limits(min: _toDouble(minAmount), max: _toDouble(maxAmount));
|
||||
} else if (response.statusCode == 422) {
|
||||
final errorResponse = json.decode(response.body) as Map<String, dynamic>;
|
||||
if (errorResponse.containsKey('minAmount')) {
|
||||
params['amount'] = errorResponse['minAmount'].toString();
|
||||
continue;
|
||||
}
|
||||
throw Exception('Error 422: ${errorResponse['message'] ?? 'Unknown error'}');
|
||||
} else {
|
||||
throw Exception('Unexpected HTTP status: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
throw Exception('Failed to fetch limits after retrying.');
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -279,4 +297,15 @@ class ExolixExchangeProvider extends ExchangeProvider {
|
|||
|
||||
String _normalizeAddress(String address) =>
|
||||
address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
|
||||
|
||||
static double? _toDouble(dynamic value) {
|
||||
if (value is int) {
|
||||
return value.toDouble();
|
||||
} else if (value is double) {
|
||||
return value;
|
||||
} else if (value is String) {
|
||||
return double.tryParse(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,6 +168,7 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
|
|||
final status = responseJSON['status'] as String;
|
||||
final createdAtString = responseJSON['created_at'] as String;
|
||||
final expiredAtTimestamp = responseJSON['expired_at'] as int;
|
||||
final extraId = responseJSON['deposit_extra_id'] as String?;
|
||||
|
||||
final createdAt = DateTime.parse(createdAtString);
|
||||
final expiredAt = DateTime.fromMillisecondsSinceEpoch(expiredAtTimestamp * 1000);
|
||||
|
@ -199,6 +200,7 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
|
|||
state: TradeState.deserialize(raw: status),
|
||||
createdAt: createdAt,
|
||||
expiredAt: expiredAt,
|
||||
extraId: extraId,
|
||||
);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
|
@ -231,6 +233,7 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
|
|||
final status = responseJSON['status'] as String;
|
||||
final createdAtString = responseJSON['created_at'] as String;
|
||||
final expiredAtTimestamp = responseJSON['expired_at'] as int;
|
||||
final extraId = responseJSON['deposit_extra_id'] as String?;
|
||||
|
||||
final createdAt = DateTime.parse(createdAtString);
|
||||
final expiredAt = DateTime.fromMillisecondsSinceEpoch(expiredAtTimestamp * 1000);
|
||||
|
@ -249,6 +252,7 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
|
|||
createdAt: createdAt,
|
||||
expiredAt: expiredAt,
|
||||
isRefund: status == 'refund',
|
||||
extraId: extraId,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -203,6 +203,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
|
|||
final inputAddress = responseJSON['depositAddress'] as String;
|
||||
final settleAddress = responseJSON['settleAddress'] as String;
|
||||
final depositAmount = responseJSON['depositAmount'] as String?;
|
||||
final depositMemo = responseJSON['depositMemo'] as String?;
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
|
@ -217,6 +218,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
|
|||
payoutAddress: settleAddress,
|
||||
createdAt: DateTime.now(),
|
||||
isSendAll: isSendAll,
|
||||
extraId: depositMemo
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -251,6 +253,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
|
|||
final isVariable = (responseJSON['type'] as String) == 'variable';
|
||||
final expiredAtRaw = responseJSON['expiresAt'] as String;
|
||||
final expiredAt = isVariable ? null : DateTime.tryParse(expiredAtRaw)?.toLocal();
|
||||
final depositMemo = responseJSON['depositMemo'] as String?;
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
|
@ -261,7 +264,8 @@ class SideShiftExchangeProvider extends ExchangeProvider {
|
|||
amount: expectedSendAmount ?? '',
|
||||
state: TradeState.deserialize(raw: status ?? 'created'),
|
||||
expiredAt: expiredAt,
|
||||
payoutAddress: settleAddress);
|
||||
payoutAddress: settleAddress,
|
||||
extraId: depositMemo);
|
||||
}
|
||||
|
||||
Future<String> _createQuote(TradeRequest request) async {
|
||||
|
|
|
@ -154,6 +154,7 @@ class StealthExExchangeProvider extends ExchangeProvider {
|
|||
final receiveAmount = toDouble(withdrawal['amount']);
|
||||
final status = responseJSON['status'] as String;
|
||||
final createdAtString = responseJSON['created_at'] as String;
|
||||
final extraId = deposit['extra_id'] as String?;
|
||||
|
||||
final createdAt = DateTime.parse(createdAtString);
|
||||
final expiredAt = validUntil != null
|
||||
|
@ -188,6 +189,7 @@ class StealthExExchangeProvider extends ExchangeProvider {
|
|||
state: TradeState.deserialize(raw: status),
|
||||
createdAt: createdAt,
|
||||
expiredAt: expiredAt,
|
||||
extraId: extraId,
|
||||
);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
|
@ -220,6 +222,7 @@ class StealthExExchangeProvider extends ExchangeProvider {
|
|||
final status = responseJSON['status'] as String;
|
||||
final createdAtString = responseJSON['created_at'] as String;
|
||||
final createdAt = DateTime.parse(createdAtString);
|
||||
final extraId = deposit['extra_id'] as String?;
|
||||
|
||||
return Trade(
|
||||
id: respId,
|
||||
|
@ -234,6 +237,7 @@ class StealthExExchangeProvider extends ExchangeProvider {
|
|||
state: TradeState.deserialize(raw: status),
|
||||
createdAt: createdAt,
|
||||
isRefund: status == 'refunded',
|
||||
extraId: extraId,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,8 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
if (!isFixedRateMode) 'amount_from': request.fromAmount,
|
||||
if (isFixedRateMode) 'amount_to': request.toAmount,
|
||||
'address': request.toAddress,
|
||||
'refund': request.refundAddress
|
||||
'refund': request.refundAddress,
|
||||
'refund_memo' : '0',
|
||||
};
|
||||
|
||||
if (isFixedRateMode) {
|
||||
|
@ -262,6 +263,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
final password = responseJSON['password'] as String;
|
||||
final providerId = responseJSON['id_provider'] as String;
|
||||
final providerName = responseJSON['provider'] as String;
|
||||
final addressProviderMemo = responseJSON['address_provider_memo'] as String?;
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
|
@ -277,6 +279,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
password: password,
|
||||
providerId: providerId,
|
||||
providerName: providerName,
|
||||
extraId: addressProviderMemo,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@ class Trade extends HiveObject {
|
|||
isRefund: map['isRefund'] as bool?,
|
||||
isSendAll: map['isSendAll'] as bool?,
|
||||
router: map['router'] as String?,
|
||||
extraId: map['extra_id'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -162,6 +163,7 @@ class Trade extends HiveObject {
|
|||
'isRefund': isRefund,
|
||||
'isSendAll': isSendAll,
|
||||
'router': router,
|
||||
'extra_id': extraId,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ class TradeDetailsListCardItem extends StandartListItem {
|
|||
{required this.id,
|
||||
required this.createdAt,
|
||||
required this.pair,
|
||||
required this.onTap})
|
||||
required this.onTap,
|
||||
this.extraId})
|
||||
: super(title: '', value: '');
|
||||
|
||||
factory TradeDetailsListCardItem.tradeDetails(
|
||||
|
@ -16,9 +17,19 @@ class TradeDetailsListCardItem extends StandartListItem {
|
|||
required String createdAt,
|
||||
required CryptoCurrency from,
|
||||
required CryptoCurrency to,
|
||||
required void Function(BuildContext) onTap}) {
|
||||
required void Function(BuildContext) onTap,
|
||||
String? extraId}) {
|
||||
|
||||
|
||||
final extraIdTitle = from == CryptoCurrency.xrp
|
||||
? S.current.destination_tag
|
||||
: from == CryptoCurrency.xlm
|
||||
? S.current.memo
|
||||
: S.current.extra_id;
|
||||
|
||||
return TradeDetailsListCardItem(
|
||||
id: '${S.current.trade_details_id} ${formatAsText(id)}',
|
||||
extraId: extraId != null ? '$extraIdTitle $extraId' : null,
|
||||
createdAt: formatAsText(createdAt),
|
||||
pair: '${formatAsText(from)} → ${formatAsText(to)}',
|
||||
onTap: onTap);
|
||||
|
@ -27,6 +38,7 @@ class TradeDetailsListCardItem extends StandartListItem {
|
|||
final String id;
|
||||
final String createdAt;
|
||||
final String pair;
|
||||
final String? extraId;
|
||||
final void Function(BuildContext) onTap;
|
||||
|
||||
static String formatAsText<T>(T value) => value?.toString() ?? '';
|
||||
|
|
|
@ -69,6 +69,7 @@ class TradeDetailsPageBodyState extends State<TradeDetailsPageBody> {
|
|||
if (item is TradeDetailsListCardItem)
|
||||
return TradeDetailsStandardListCard(
|
||||
id: item.id,
|
||||
extraId: item.extraId,
|
||||
create: item.createdAt,
|
||||
pair: item.pair,
|
||||
currentTheme: tradeDetailsViewModel.settingsStore.currentTheme.type,
|
||||
|
|
|
@ -6,12 +6,14 @@ import 'package:cake_wallet/themes/theme_base.dart';
|
|||
class TradeDetailsStandardListCard extends StatelessWidget {
|
||||
TradeDetailsStandardListCard(
|
||||
{required this.id,
|
||||
this.extraId,
|
||||
required this.create,
|
||||
required this.pair,
|
||||
required this.onTap,
|
||||
required this.currentTheme});
|
||||
|
||||
final String id;
|
||||
final String? extraId;
|
||||
final String create;
|
||||
final String pair;
|
||||
final ThemeType currentTheme;
|
||||
|
@ -57,6 +59,16 @@ class TradeDetailsStandardListCard extends StatelessWidget {
|
|||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
if (extraId != null && extraId!.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Text(extraId!,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontFamily: 'Lato',
|
||||
fontWeight: FontWeight.w400,
|
||||
color: textColor)),
|
||||
),
|
||||
Text(create,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
|
|
|
@ -146,7 +146,7 @@ abstract class ExchangeTradeViewModelBase with Store {
|
|||
|
||||
void _updateItems() {
|
||||
final tagFrom =
|
||||
tradesStore.trade!.from.tag != null ? '${tradesStore.trade!.from.tag}' + ' ' : '';
|
||||
tradesStore.trade!.from.tag != null ? '${tradesStore.trade!.from.tag}' + ' ' : '';
|
||||
final tagTo = tradesStore.trade!.to.tag != null ? '${tradesStore.trade!.to.tag}' + ' ' : '';
|
||||
items.clear();
|
||||
|
||||
|
@ -159,16 +159,6 @@ abstract class ExchangeTradeViewModelBase with Store {
|
|||
),
|
||||
);
|
||||
|
||||
if (trade.extraId != null) {
|
||||
final title = trade.from == CryptoCurrency.xrp
|
||||
? S.current.destination_tag
|
||||
: trade.from == CryptoCurrency.xlm
|
||||
? S.current.memo
|
||||
: S.current.extra_id;
|
||||
|
||||
items.add(ExchangeTradeItem(title: title, data: '${trade.extraId}', isCopied: false));
|
||||
}
|
||||
|
||||
items.addAll([
|
||||
ExchangeTradeItem(
|
||||
title: S.current.amount,
|
||||
|
@ -176,7 +166,7 @@ abstract class ExchangeTradeViewModelBase with Store {
|
|||
isCopied: true,
|
||||
),
|
||||
ExchangeTradeItem(
|
||||
title: S.current.estimated_receive_amount +':',
|
||||
title: S.current.estimated_receive_amount + ':',
|
||||
data: '${tradesStore.trade?.receiveAmount} ${trade.to}',
|
||||
isCopied: true,
|
||||
),
|
||||
|
@ -185,12 +175,25 @@ abstract class ExchangeTradeViewModelBase with Store {
|
|||
data: trade.inputAddress ?? '',
|
||||
isCopied: true,
|
||||
),
|
||||
]);
|
||||
|
||||
if (trade.extraId != null) {
|
||||
final title = trade.from == CryptoCurrency.xrp
|
||||
? S.current.destination_tag
|
||||
: trade.from == CryptoCurrency.xlm
|
||||
? S.current.memo
|
||||
: S.current.extra_id;
|
||||
|
||||
items.add(ExchangeTradeItem(title: title, data: '${trade.extraId}', isCopied: true));
|
||||
}
|
||||
|
||||
items.add(
|
||||
ExchangeTradeItem(
|
||||
title: S.current.arrive_in_this_address('${tradesStore.trade!.to}', tagTo) + ':',
|
||||
data: trade.payoutAddress ?? '',
|
||||
isCopied: true,
|
||||
),
|
||||
]);
|
||||
);
|
||||
}
|
||||
|
||||
static bool _checkIfCanSend(TradesStore tradesStore, WalletBase wallet) {
|
||||
|
|
|
@ -153,6 +153,7 @@ abstract class TradeDetailsViewModelBase with Store {
|
|||
|
||||
items.add(TradeDetailsListCardItem.tradeDetails(
|
||||
id: trade.id,
|
||||
extraId: trade.extraId,
|
||||
createdAt: trade.createdAt != null ? dateFormat.format(trade.createdAt!) : '',
|
||||
from: trade.from,
|
||||
to: trade.to,
|
||||
|
|
Loading…
Reference in a new issue