Merge pull request #732 from cake-tech/CW-247-Exchange-confirmation-screen-address-labels

CW-247 exchange confirmation screen address labels
This commit is contained in:
Omar Hatem
2023-01-30 21:24:32 +02:00
committed by GitHub
24 changed files with 91 additions and 39 deletions
@@ -143,6 +143,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final inputAddress = responseJSON['payinAddress'] as String;
final refundAddress = responseJSON['refundAddress'] as String;
final extraId = responseJSON['payinExtraId'] as String?;
final payoutAddress = responseJSON['payoutAddress'] as String;
return Trade(
id: id,
@@ -154,7 +155,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
extraId: extraId,
createdAt: DateTime.now(),
amount: responseJSON['fromAmount']?.toString() ?? _request.fromAmount,
state: TradeState.created);
state: TradeState.created,
payoutAddress: payoutAddress);
}
@override
@@ -192,6 +194,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final extraId = responseJSON['payinExtraId'] as String;
final outputTransaction = responseJSON['payoutHash'] as String;
final expiredAtRaw = responseJSON['validUntil'] as String;
final payoutAddress = responseJSON['payoutAddress'] as String;
final expiredAt = DateTime.tryParse(expiredAtRaw)?.toLocal();
return Trade(
@@ -204,7 +207,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
state: state,
extraId: extraId,
expiredAt: expiredAt,
outputTransaction: outputTransaction);
outputTransaction: outputTransaction,
payoutAddress: payoutAddress);
}
@override
@@ -150,6 +150,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
refundAddress: settleAddress,
state: TradeState.created,
amount: _request.depositAmount,
payoutAddress: settleAddress,
createdAt: DateTime.now(),
);
}
@@ -244,6 +245,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
final inputAddress = responseJSON['depositAddress']['address'] as String;
final expectedSendAmount = responseJSON['depositAmount'].toString();
final deposits = responseJSON['deposits'] as List?;
final settleAddress = responseJSON['settleAddress']['address'] as String;
TradeState? state;
String? status;
@@ -264,6 +266,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
amount: expectedSendAmount,
state: state,
expiredAt: expiredAt,
payoutAddress: settleAddress
);
}
@@ -108,6 +108,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
final id = responseJSON['id'] as String;
final inputAddress = responseJSON['address_from'] as String;
final payoutAddress = responseJSON['address_to'] as String;
final settleAddress = responseJSON['user_refund_address'] as String;
final extraId = responseJSON['extra_id_from'] as String?;
return Trade(
@@ -120,6 +121,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
extraId: extraId,
state: TradeState.created,
amount: _request.amount,
payoutAddress: payoutAddress,
createdAt: DateTime.now(),
);
}
@@ -189,6 +191,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
final expectedSendAmount = responseJSON['expected_amount'].toString();
final extraId = responseJSON['extra_id_from'] as String?;
final status = responseJSON['status'] as String;
final payoutAddress = responseJSON['address_to'] as String;
final state = TradeState.deserialize(raw: status);
return Trade(
@@ -200,6 +203,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
inputAddress: inputAddress,
amount: expectedSendAmount,
state: state,
payoutAddress: payoutAddress,
);
}
+5 -1
View File
@@ -21,7 +21,8 @@ class Trade extends HiveObject {
this.extraId,
this.outputTransaction,
this.refundAddress,
this.walletId}) {
this.walletId,
this.payoutAddress}) {
if (provider != null) {
providerRaw = provider.raw;
}
@@ -88,6 +89,9 @@ class Trade extends HiveObject {
@HiveField(12)
String? walletId;
@HiveField(13)
String? payoutAddress;
static Trade fromMap(Map<String, Object?> map) {
return Trade(
id: map['id'] as String,
@@ -18,19 +18,18 @@ import 'package:cake_wallet/generated/i18n.dart';
part 'exchange_trade_view_model.g.dart';
class ExchangeTradeViewModel = ExchangeTradeViewModelBase
with _$ExchangeTradeViewModel;
class ExchangeTradeViewModel = ExchangeTradeViewModelBase with _$ExchangeTradeViewModel;
abstract class ExchangeTradeViewModelBase with Store {
ExchangeTradeViewModelBase(
{required this.wallet,
required this.trades,
required this.tradesStore,
required this.sendViewModel})
: trade = tradesStore.trade!,
isSendable = tradesStore.trade!.from == wallet.currency ||
tradesStore.trade!.provider == ExchangeProviderDescription.xmrto,
items = ObservableList<ExchangeTradeItem>() {
required this.trades,
required this.tradesStore,
required this.sendViewModel})
: trade = tradesStore.trade!,
isSendable = tradesStore.trade!.from == wallet.currency ||
tradesStore.trade!.provider == ExchangeProviderDescription.xmrto,
items = ObservableList<ExchangeTradeItem>() {
switch (trade.provider) {
case ExchangeProviderDescription.xmrto:
_provider = XMRTOExchangeProvider();
@@ -67,22 +66,20 @@ abstract class ExchangeTradeViewModelBase with Store {
@computed
String get extraInfo => trade.from == CryptoCurrency.xlm
? '\n\n' + S.current.xlm_extra_info
: trade.from == CryptoCurrency.xrp
? '\n\n' + S.current.xrp_extra_info
: '';
? '\n\n' + S.current.xlm_extra_info
: trade.from == CryptoCurrency.xrp
? '\n\n' + S.current.xrp_extra_info
: '';
@computed
String get pendingTransactionFiatAmountValueFormatted =>
sendViewModel.isFiatDisabled
? '' : sendViewModel.pendingTransactionFiatAmount
+ ' ' + sendViewModel.fiat.title;
String get pendingTransactionFiatAmountValueFormatted => sendViewModel.isFiatDisabled
? ''
: sendViewModel.pendingTransactionFiatAmount + ' ' + sendViewModel.fiat.title;
@computed
String get pendingTransactionFeeFiatAmountFormatted =>
sendViewModel.isFiatDisabled
? '' : sendViewModel.pendingTransactionFeeFiatAmount
+ ' ' + sendViewModel.fiat.title;
String get pendingTransactionFeeFiatAmountFormatted => sendViewModel.isFiatDisabled
? ''
: sendViewModel.pendingTransactionFeeFiatAmount + ' ' + sendViewModel.fiat.title;
@observable
ObservableList<ExchangeTradeItem> items;
@@ -122,6 +119,8 @@ abstract class ExchangeTradeViewModelBase with Store {
}
void _updateItems() {
final tagFrom = trade.from.tag != null ? '${trade.from.tag}' + ' ' : '';
final tagTo = trade.to.tag != null ? '${trade.to.tag}' + ' ' : '';
items.clear();
items.add(ExchangeTradeItem(
title: "${trade.provider.title} ${S.current.id}", data: '${trade.id}', isCopied: true));
@@ -130,22 +129,22 @@ abstract class ExchangeTradeViewModelBase with Store {
final title = trade.from == CryptoCurrency.xrp
? S.current.destination_tag
: trade.from == CryptoCurrency.xlm
? S.current.memo
: S.current.extra_id;
? S.current.memo
: S.current.extra_id;
items.add(ExchangeTradeItem(
title: title, data: '${trade.extraId}', isCopied: false));
items.add(ExchangeTradeItem(title: title, data: '${trade.extraId}', isCopied: false));
}
items.addAll([
ExchangeTradeItem(title: S.current.amount, data: '${trade.amount}', isCopied: false),
ExchangeTradeItem(
title: S.current.amount, data: '${trade.amount}', isCopied: false),
ExchangeTradeItem(
title: S.current.status, data: '${trade.state}', isCopied: false),
ExchangeTradeItem(
title: S.current.widgets_address + ':',
title: S.current.send_to_this_address('${trade.from}', tagFrom) + ':',
data: trade.inputAddress ?? '',
isCopied: true),
ExchangeTradeItem(
title: S.current.arrive_in_this_address('${trade.to}', tagTo) + ':',
data: trade.payoutAddress ?? '',
isCopied: true),
]);
}
}