mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-01 12:04:21 +01:00
CW-674: Enhance Exchange Flow - Add estimated receive amount and amount currency to Confirm Sending Details Page (#1547)
* fix: Improve exchange flow by adding a timeout to the call to fetch rate from providers * fix: Adjust time limit for fetching rate to 7 seconds and add timelimit to fetching limits * fix: Make fetch limits a Future.wait * feat: Add currency for amount and estimated receive amount to confirm sending page for exchange * fix: Remove unneeded code * fix: Modify receive amount to reflect value coming from the individual exchange providers if available and ensure receiveAmount is calculated based on selected exchange provider's rate
This commit is contained in:
@@ -391,7 +391,14 @@ Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) async {
|
||||
}
|
||||
|
||||
return Trade(
|
||||
id: tradeId, provider: provider!, from: from, to: to, createdAt: date, amount: '');
|
||||
id: tradeId,
|
||||
provider: provider!,
|
||||
from: from,
|
||||
to: to,
|
||||
createdAt: date,
|
||||
amount: '',
|
||||
receiveAmount: '',
|
||||
);
|
||||
});
|
||||
await tradeSource.addAll(trades);
|
||||
await prefs.setBool('ios_migration_trade_list_completed', true);
|
||||
|
||||
@@ -194,20 +194,24 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
||||
final refundAddress = responseJSON['refundAddress'] as String;
|
||||
final extraId = responseJSON['payinExtraId'] as String?;
|
||||
final payoutAddress = responseJSON['payoutAddress'] as String;
|
||||
final fromAmount = responseJSON['fromAmount']?.toString();
|
||||
final toAmount = responseJSON['toAmount']?.toString();
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
extraId: extraId,
|
||||
createdAt: DateTime.now(),
|
||||
amount: responseJSON['fromAmount']?.toString() ?? request.fromAmount,
|
||||
state: TradeState.created,
|
||||
payoutAddress: payoutAddress,
|
||||
isSendAll: isSendAll);
|
||||
id: id,
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
extraId: extraId,
|
||||
createdAt: DateTime.now(),
|
||||
amount: fromAmount ?? request.fromAmount,
|
||||
receiveAmount: toAmount ?? request.toAmount,
|
||||
state: TradeState.created,
|
||||
payoutAddress: payoutAddress,
|
||||
isSendAll: isSendAll,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -172,20 +172,23 @@ class ExolixExchangeProvider extends ExchangeProvider {
|
||||
final extraId = responseJSON['depositExtraId'] as String?;
|
||||
final payoutAddress = responseJSON['withdrawalAddress'] as String;
|
||||
final amount = responseJSON['amount'].toString();
|
||||
final receiveAmount = responseJSON['amountTo']?.toString();
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
extraId: extraId,
|
||||
createdAt: DateTime.now(),
|
||||
amount: amount,
|
||||
state: TradeState.created,
|
||||
payoutAddress: payoutAddress,
|
||||
isSendAll: isSendAll);
|
||||
id: id,
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
extraId: extraId,
|
||||
createdAt: DateTime.now(),
|
||||
amount: amount,
|
||||
receiveAmount:receiveAmount ?? request.toAmount,
|
||||
state: TradeState.created,
|
||||
payoutAddress: payoutAddress,
|
||||
isSendAll: isSendAll,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -162,11 +162,13 @@ class QuantexExchangeProvider extends ExchangeProvider {
|
||||
throw Exception('Unexpected http status: ${response.statusCode}');
|
||||
|
||||
final responseData = responseBody['data'] as Map<String, dynamic>;
|
||||
final receiveAmount = responseData["amount_receive"]?.toString();
|
||||
|
||||
return Trade(
|
||||
id: responseData["order_id"] as String,
|
||||
inputAddress: responseData["server_address"] as String,
|
||||
amount: request.fromAmount,
|
||||
receiveAmount: receiveAmount ?? request.toAmount,
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
|
||||
@@ -213,6 +213,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
|
||||
refundAddress: settleAddress,
|
||||
state: TradeState.created,
|
||||
amount: depositAmount ?? request.fromAmount,
|
||||
receiveAmount: request.toAmount,
|
||||
payoutAddress: settleAddress,
|
||||
createdAt: DateTime.now(),
|
||||
isSendAll: isSendAll,
|
||||
|
||||
@@ -153,6 +153,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
|
||||
final payoutAddress = responseJSON['address_to'] as String;
|
||||
final settleAddress = responseJSON['user_refund_address'] as String;
|
||||
final extraId = responseJSON['extra_id_from'] as String?;
|
||||
final receiveAmount = responseJSON['amount_to'] as String?;
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
@@ -164,6 +165,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
|
||||
extraId: extraId,
|
||||
state: TradeState.created,
|
||||
amount: request.fromAmount,
|
||||
receiveAmount: receiveAmount ?? request.toAmount,
|
||||
payoutAddress: payoutAddress,
|
||||
createdAt: DateTime.now(),
|
||||
isSendAll: isSendAll,
|
||||
|
||||
@@ -40,7 +40,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
|
||||
static const _txInfoPath = '/thorchain/tx/status/';
|
||||
static const _affiliateName = 'cakewallet';
|
||||
static const _affiliateBps = '175';
|
||||
static const _nameLookUpPath= 'v2/thorname/lookup/';
|
||||
static const _nameLookUpPath = 'v2/thorname/lookup/';
|
||||
|
||||
final Box<Trade> tradesStore;
|
||||
|
||||
@@ -137,19 +137,27 @@ class ThorChainExchangeProvider extends ExchangeProvider {
|
||||
|
||||
final inputAddress = responseJSON['inbound_address'] as String?;
|
||||
final memo = responseJSON['memo'] as String?;
|
||||
final directAmountOutResponse = responseJSON['expected_amount_out'] as String?;
|
||||
|
||||
String? receiveAmount;
|
||||
if (directAmountOutResponse != null) {
|
||||
receiveAmount = _thorChainAmountToDouble(directAmountOutResponse).toString();
|
||||
}
|
||||
|
||||
return Trade(
|
||||
id: '',
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
createdAt: DateTime.now(),
|
||||
amount: request.fromAmount,
|
||||
state: TradeState.notFound,
|
||||
payoutAddress: request.toAddress,
|
||||
memo: memo,
|
||||
isSendAll: isSendAll);
|
||||
id: '',
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
createdAt: DateTime.now(),
|
||||
amount: request.fromAmount,
|
||||
receiveAmount: receiveAmount ?? request.toAmount,
|
||||
state: TradeState.notFound,
|
||||
payoutAddress: request.toAddress,
|
||||
memo: memo,
|
||||
isSendAll: isSendAll,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -234,7 +242,6 @@ class ThorChainExchangeProvider extends ExchangeProvider {
|
||||
return chainToAddressMap;
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, dynamic>> _getSwapQuote(Map<String, String> params) async {
|
||||
Uri uri = Uri.https(_baseNodeURL, _quotePath, params);
|
||||
|
||||
|
||||
@@ -224,22 +224,26 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
||||
final password = responseJSON['password'] as String;
|
||||
final providerId = responseJSON['id_provider'] as String;
|
||||
final providerName = responseJSON['provider'] as String;
|
||||
final amount = responseJSON['amount_from']?.toString();
|
||||
final receiveAmount = responseJSON['amount_to']?.toString();
|
||||
|
||||
return Trade(
|
||||
id: id,
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
state: TradeState.deserialize(raw: status),
|
||||
password: password,
|
||||
providerId: providerId,
|
||||
providerName: providerName,
|
||||
createdAt: DateTime.tryParse(date)?.toLocal(),
|
||||
amount: responseJSON['amount_from']?.toString() ?? request.fromAmount,
|
||||
payoutAddress: payoutAddress,
|
||||
isSendAll: isSendAll);
|
||||
id: id,
|
||||
from: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
inputAddress: inputAddress,
|
||||
refundAddress: refundAddress,
|
||||
state: TradeState.deserialize(raw: status),
|
||||
password: password,
|
||||
providerId: providerId,
|
||||
providerName: providerName,
|
||||
createdAt: DateTime.tryParse(date)?.toLocal(),
|
||||
amount: amount ?? request.fromAmount,
|
||||
receiveAmount: receiveAmount ?? request.toAmount,
|
||||
payoutAddress: payoutAddress,
|
||||
isSendAll: isSendAll,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
+11
-2
@@ -13,6 +13,7 @@ class Trade extends HiveObject {
|
||||
CryptoCurrency? from,
|
||||
CryptoCurrency? to,
|
||||
TradeState? state,
|
||||
this.receiveAmount,
|
||||
this.createdAt,
|
||||
this.expiredAt,
|
||||
this.inputAddress,
|
||||
@@ -122,6 +123,9 @@ class Trade extends HiveObject {
|
||||
@HiveField(22)
|
||||
String? router;
|
||||
|
||||
@HiveField(23, defaultValue: '')
|
||||
String? receiveAmount;
|
||||
|
||||
static Trade fromMap(Map<String, Object?> map) {
|
||||
return Trade(
|
||||
id: map['id'] as String,
|
||||
@@ -131,6 +135,7 @@ class Trade extends HiveObject {
|
||||
createdAt:
|
||||
map['date'] != null ? DateTime.fromMillisecondsSinceEpoch(map['date'] as int) : null,
|
||||
amount: map['amount'] as String,
|
||||
receiveAmount: map['receive_amount'] as String?,
|
||||
walletId: map['wallet_id'] as String,
|
||||
fromWalletAddress: map['from_wallet_address'] as String?,
|
||||
memo: map['memo'] as String?,
|
||||
@@ -149,6 +154,7 @@ class Trade extends HiveObject {
|
||||
'output': to.serialize(),
|
||||
'date': createdAt != null ? createdAt!.millisecondsSinceEpoch : null,
|
||||
'amount': amount,
|
||||
'receive_amount': receiveAmount,
|
||||
'wallet_id': walletId,
|
||||
'from_wallet_address': fromWalletAddress,
|
||||
'memo': memo,
|
||||
@@ -179,6 +185,7 @@ class TradeAdapter extends TypeAdapter<Trade> {
|
||||
return Trade(
|
||||
id: fields[0] == null ? '' : fields[0] as String,
|
||||
amount: fields[7] == null ? '' : fields[7] as String,
|
||||
receiveAmount: fields[23] as String?,
|
||||
createdAt: fields[5] as DateTime?,
|
||||
expiredAt: fields[6] as DateTime?,
|
||||
inputAddress: fields[8] as String?,
|
||||
@@ -206,7 +213,7 @@ class TradeAdapter extends TypeAdapter<Trade> {
|
||||
@override
|
||||
void write(BinaryWriter writer, Trade obj) {
|
||||
writer
|
||||
..writeByte(23)
|
||||
..writeByte(24)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
@@ -252,7 +259,9 @@ class TradeAdapter extends TypeAdapter<Trade> {
|
||||
..writeByte(21)
|
||||
..write(obj.isSendAll)
|
||||
..writeByte(22)
|
||||
..write(obj.router);
|
||||
..write(obj.router)
|
||||
..writeByte(23)
|
||||
..write(obj.receiveAmount);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -147,8 +147,13 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
items.clear();
|
||||
|
||||
if (trade.provider != ExchangeProviderDescription.thorChain)
|
||||
items.add(ExchangeTradeItem(
|
||||
title: "${trade.provider.title} ${S.current.id}", data: '${trade.id}', isCopied: true));
|
||||
items.add(
|
||||
ExchangeTradeItem(
|
||||
title: "${trade.provider.title} ${S.current.id}",
|
||||
data: '${trade.id}',
|
||||
isCopied: true,
|
||||
),
|
||||
);
|
||||
|
||||
if (trade.extraId != null) {
|
||||
final title = trade.from == CryptoCurrency.xrp
|
||||
@@ -161,15 +166,26 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
}
|
||||
|
||||
items.addAll([
|
||||
ExchangeTradeItem(title: S.current.amount, data: '${trade.amount}', isCopied: true),
|
||||
ExchangeTradeItem(
|
||||
title: S.current.send_to_this_address('${tradesStore.trade!.from}', tagFrom) + ':',
|
||||
data: trade.inputAddress ?? '',
|
||||
isCopied: true),
|
||||
title: S.current.amount,
|
||||
data: '${trade.amount} ${trade.from}',
|
||||
isCopied: true,
|
||||
),
|
||||
ExchangeTradeItem(
|
||||
title: S.current.arrive_in_this_address('${tradesStore.trade!.to}', tagTo) + ':',
|
||||
data: trade.payoutAddress ?? '',
|
||||
isCopied: true),
|
||||
title: S.current.estimated_receive_amount +':',
|
||||
data: '${tradesStore.trade?.receiveAmount} ${trade.to}',
|
||||
isCopied: true,
|
||||
),
|
||||
ExchangeTradeItem(
|
||||
title: S.current.send_to_this_address('${tradesStore.trade!.from}', tagFrom) + ':',
|
||||
data: trade.inputAddress ?? '',
|
||||
isCopied: true,
|
||||
),
|
||||
ExchangeTradeItem(
|
||||
title: S.current.arrive_in_this_address('${tradesStore.trade!.to}', tagTo) + ':',
|
||||
data: trade.payoutAddress ?? '',
|
||||
isCopied: true,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -450,19 +450,21 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
double? highestMax = 0.0;
|
||||
|
||||
try {
|
||||
final result = await Future.wait(selectedProviders
|
||||
.where((element) => providersForCurrentPair().contains(provider))
|
||||
.map((provider) => provider
|
||||
.fetchLimits(
|
||||
from: from,
|
||||
to: to,
|
||||
isFixedRateMode: isFixedRateMode,
|
||||
)
|
||||
.onError((error, stackTrace) => Limits(max: 0.0, min: double.maxFinite))
|
||||
.timeout(
|
||||
Duration(seconds: 7),
|
||||
onTimeout: () => Limits(max: 0.0, min: double.maxFinite),
|
||||
)));
|
||||
final result = await Future.wait(
|
||||
selectedProviders.where((provider) => providersForCurrentPair().contains(provider)).map(
|
||||
(provider) => provider
|
||||
.fetchLimits(
|
||||
from: from,
|
||||
to: to,
|
||||
isFixedRateMode: isFixedRateMode,
|
||||
)
|
||||
.onError((error, stackTrace) => Limits(max: 0.0, min: double.maxFinite))
|
||||
.timeout(
|
||||
Duration(seconds: 7),
|
||||
onTimeout: () => Limits(max: 0.0, min: double.maxFinite),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
result.forEach((tempLimits) {
|
||||
if (lowestMin != null && (tempLimits.min ?? -1) < lowestMin!) {
|
||||
@@ -506,17 +508,24 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
}
|
||||
|
||||
try {
|
||||
for (var provider in _sortedAvailableProviders.values) {
|
||||
for (var i = 0; i < _sortedAvailableProviders.values.length; i++) {
|
||||
final provider = _sortedAvailableProviders.values.toList()[i];
|
||||
final providerRate = _sortedAvailableProviders.keys.toList()[i];
|
||||
|
||||
if (!(await provider.checkIsAvailable())) continue;
|
||||
|
||||
_bestRate = providerRate;
|
||||
await changeDepositAmount(amount: depositAmount);
|
||||
|
||||
final request = TradeRequest(
|
||||
fromCurrency: depositCurrency,
|
||||
toCurrency: receiveCurrency,
|
||||
fromAmount: depositAmount.replaceAll(',', '.'),
|
||||
toAmount: receiveAmount.replaceAll(',', '.'),
|
||||
refundAddress: depositAddress,
|
||||
toAddress: receiveAddress,
|
||||
isFixedRate: isFixedRateMode);
|
||||
fromCurrency: depositCurrency,
|
||||
toCurrency: receiveCurrency,
|
||||
fromAmount: depositAmount.replaceAll(',', '.'),
|
||||
toAmount: receiveAmount.replaceAll(',', '.'),
|
||||
refundAddress: depositAddress,
|
||||
toAddress: receiveAddress,
|
||||
isFixedRate: isFixedRateMode,
|
||||
);
|
||||
|
||||
var amount = isFixedRateMode ? receiveAmount : depositAmount;
|
||||
amount = amount.replaceAll(',', '.');
|
||||
|
||||
Reference in New Issue
Block a user