mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00: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:
parent
1b109ac702
commit
5c9f176d18
38 changed files with 174 additions and 122 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue