From f1904077d2fe96ff061c214d69af1e19a6942673 Mon Sep 17 00:00:00 2001 From: Serhii Date: Wed, 14 Jun 2023 23:55:49 +0300 Subject: [PATCH] CW-395-Trade-ID-status-not-updating-in-trade-details-screen (#957) * fix ChangeNow trade status * formatting * fix hive saving * Revert SideShift changes This reverts commit --- .../changenow/changenow_exchange_provider.dart | 8 ++++---- lib/view_model/trade_details_view_model.dart | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/exchange/changenow/changenow_exchange_provider.dart b/lib/exchange/changenow/changenow_exchange_provider.dart index 89d32fa09..b37a513ac 100644 --- a/lib/exchange/changenow/changenow_exchange_provider.dart +++ b/lib/exchange/changenow/changenow_exchange_provider.dart @@ -192,11 +192,11 @@ class ChangeNowExchangeProvider extends ExchangeProvider { final expectedSendAmount = responseJSON['expectedAmountFrom'].toString(); final status = responseJSON['status'] as String; final state = TradeState.deserialize(raw: status); - final extraId = responseJSON['payinExtraId'] as String; - final outputTransaction = responseJSON['payoutHash'] as String; - final expiredAtRaw = responseJSON['validUntil'] as String; + 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(); + final expiredAt = DateTime.tryParse(expiredAtRaw ?? '')?.toLocal(); return Trade( id: id, diff --git a/lib/view_model/trade_details_view_model.dart b/lib/view_model/trade_details_view_model.dart index e32e36887..1e8a90c6f 100644 --- a/lib/view_model/trade_details_view_model.dart +++ b/lib/view_model/trade_details_view_model.dart @@ -21,6 +21,7 @@ import 'package:cake_wallet/src/screens/trade_details/track_trade_list_item.dart import 'package:cake_wallet/src/screens/trade_details/trade_details_list_card.dart'; import 'package:cake_wallet/src/screens/trade_details/trade_details_status_item.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:collection/collection.dart'; part 'trade_details_view_model.g.dart'; @@ -32,7 +33,8 @@ abstract class TradeDetailsViewModelBase with Store { required this.trades, required this.settingsStore, }) : items = ObservableList(), - trade = tradeForDetails { + trade = trades.values.firstWhereOrNull((element) => element.id == tradeForDetails.id) ?? + tradeForDetails { switch (trade.provider) { case ExchangeProviderDescription.xmrto: _provider = XMRTOExchangeProvider(); @@ -54,8 +56,6 @@ abstract class TradeDetailsViewModelBase with Store { break; } - items = ObservableList(); - _updateItems(); _updateTrade(); @@ -85,6 +85,12 @@ abstract class TradeDetailsViewModelBase with Store { if (updatedTrade.createdAt == null && trade.createdAt != null) { updatedTrade.createdAt = trade.createdAt; } + Trade? foundElement = trades.values.firstWhereOrNull((element) => element.id == trade.id); + if (foundElement != null) { + final editedTrade = trades.get(foundElement.key); + editedTrade?.stateRaw = updatedTrade.stateRaw; + editedTrade?.save(); + } trade = updatedTrade; @@ -154,8 +160,9 @@ abstract class TradeDetailsViewModelBase with Store { } void _launchUrl(String url) { + final uri = Uri.parse(url); try { - launch(url); + launchUrl(uri); } catch (e) {} } }