2021-03-12 19:04:37 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'package:cake_wallet/entities/order.dart';
|
|
|
|
import 'package:cake_wallet/utils/date_formatter.dart';
|
2021-03-23 17:19:01 +00:00
|
|
|
import 'package:cake_wallet/view_model/wyre_view_model.dart';
|
2021-03-12 19:04:37 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/trade_details/track_trade_list_item.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
|
|
part 'order_details_view_model.g.dart';
|
|
|
|
|
|
|
|
class OrderDetailsViewModel = OrderDetailsViewModelBase
|
|
|
|
with _$OrderDetailsViewModel;
|
|
|
|
|
|
|
|
abstract class OrderDetailsViewModelBase with Store {
|
2021-03-23 17:19:01 +00:00
|
|
|
OrderDetailsViewModelBase({this.wyreViewModel, Order orderForDetails}) {
|
2021-03-12 19:04:37 +00:00
|
|
|
order = orderForDetails;
|
|
|
|
|
|
|
|
items = ObservableList<StandartListItem>();
|
|
|
|
|
|
|
|
_updateItems();
|
|
|
|
|
|
|
|
_updateOrder();
|
|
|
|
|
|
|
|
_timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateOrder());
|
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
|
|
|
Order order;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
ObservableList<StandartListItem> items;
|
|
|
|
|
2021-03-23 17:19:01 +00:00
|
|
|
WyreViewModel wyreViewModel;
|
|
|
|
|
2021-03-12 19:04:37 +00:00
|
|
|
Timer _timer;
|
|
|
|
|
|
|
|
@action
|
|
|
|
Future<void> _updateOrder() async {
|
|
|
|
try {
|
2021-03-23 17:19:01 +00:00
|
|
|
final updatedOrder =
|
|
|
|
await wyreViewModel.wyreService.findOrderById(order.id);
|
2021-03-12 19:04:37 +00:00
|
|
|
|
|
|
|
updatedOrder.receiveAddress = order.receiveAddress;
|
|
|
|
updatedOrder.walletId = order.walletId;
|
|
|
|
order = updatedOrder;
|
|
|
|
|
|
|
|
_updateItems();
|
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _updateItems() {
|
|
|
|
final dateFormat = DateFormatter.withCurrentLocal();
|
|
|
|
final buildURL =
|
2021-03-23 17:19:01 +00:00
|
|
|
wyreViewModel.trackUrl + '${order.transferId}';
|
2021-03-12 19:04:37 +00:00
|
|
|
|
|
|
|
items?.clear();
|
|
|
|
|
|
|
|
items.addAll([
|
|
|
|
StandartListItem(
|
|
|
|
title: 'Transfer ID',
|
|
|
|
value: order.transferId),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.trade_details_state,
|
|
|
|
value: order.state != null
|
|
|
|
? order.state.toString()
|
|
|
|
: S.current.trade_details_fetching),
|
|
|
|
TrackTradeListItem(
|
|
|
|
title: 'Track',
|
|
|
|
value: buildURL,
|
|
|
|
onTap: () {
|
|
|
|
launch(buildURL);
|
|
|
|
}),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.trade_details_created_at,
|
|
|
|
value: dateFormat.format(order.createdAt).toString()),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.trade_details_pair,
|
|
|
|
value: '${order.from} → ${order.to}')
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|