2020-12-18 12:42:53 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'package:cake_wallet/exchange/changenow/changenow_exchange_provider.dart';
|
|
|
|
import 'package:cake_wallet/exchange/exchange_provider.dart';
|
|
|
|
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
|
|
|
import 'package:cake_wallet/exchange/morphtoken/morphtoken_exchange_provider.dart';
|
2022-04-13 13:28:21 +00:00
|
|
|
import 'package:cake_wallet/exchange/sideshift/sideshift_exchange_provider.dart';
|
2022-08-31 15:34:07 +00:00
|
|
|
import 'package:cake_wallet/exchange/simpleswap/simpleswap_exchange_provider.dart';
|
2020-12-18 12:42:53 +00:00
|
|
|
import 'package:cake_wallet/exchange/trade.dart';
|
|
|
|
import 'package:cake_wallet/exchange/xmrto/xmrto_exchange_provider.dart';
|
2022-09-02 13:10:54 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
2020-12-18 12:42:53 +00:00
|
|
|
import 'package:cake_wallet/utils/date_formatter.dart';
|
2022-09-02 13:10:54 +00:00
|
|
|
import 'package:cake_wallet/utils/show_bar.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2020-12-18 12:42:53 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
2021-02-02 01:36:36 +00:00
|
|
|
import 'package:cake_wallet/src/screens/trade_details/track_trade_list_item.dart';
|
2022-09-02 13:10:54 +00:00
|
|
|
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';
|
2021-02-02 01:36:36 +00:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-12-18 12:42:53 +00:00
|
|
|
part 'trade_details_view_model.g.dart';
|
|
|
|
|
|
|
|
class TradeDetailsViewModel = TradeDetailsViewModelBase
|
|
|
|
with _$TradeDetailsViewModel;
|
|
|
|
|
|
|
|
abstract class TradeDetailsViewModelBase with Store {
|
2022-09-02 13:10:54 +00:00
|
|
|
TradeDetailsViewModelBase({Trade tradeForDetails, this.trades, this.settingsStore}) {
|
2020-12-18 12:42:53 +00:00
|
|
|
trade = tradeForDetails;
|
|
|
|
|
|
|
|
switch (trade.provider) {
|
|
|
|
case ExchangeProviderDescription.xmrto:
|
|
|
|
_provider = XMRTOExchangeProvider();
|
|
|
|
break;
|
|
|
|
case ExchangeProviderDescription.changeNow:
|
|
|
|
_provider = ChangeNowExchangeProvider();
|
|
|
|
break;
|
|
|
|
case ExchangeProviderDescription.morphToken:
|
|
|
|
_provider = MorphTokenExchangeProvider(trades: trades);
|
|
|
|
break;
|
2022-04-13 13:28:21 +00:00
|
|
|
case ExchangeProviderDescription.sideShift:
|
|
|
|
_provider = SideShiftExchangeProvider();
|
|
|
|
break;
|
2022-08-31 15:34:07 +00:00
|
|
|
case ExchangeProviderDescription.simpleSwap:
|
|
|
|
_provider = SimpleSwapExchangeProvider();
|
|
|
|
break;
|
2020-12-18 12:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
items = ObservableList<StandartListItem>();
|
|
|
|
|
|
|
|
_updateItems();
|
|
|
|
|
|
|
|
_updateTrade();
|
|
|
|
|
2021-04-15 17:10:23 +00:00
|
|
|
timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateTrade());
|
2020-12-18 12:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final Box<Trade> trades;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
Trade trade;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
ObservableList<StandartListItem> items;
|
|
|
|
|
|
|
|
ExchangeProvider _provider;
|
|
|
|
|
2021-04-15 17:10:23 +00:00
|
|
|
Timer timer;
|
2020-12-18 12:42:53 +00:00
|
|
|
|
2022-09-02 13:10:54 +00:00
|
|
|
final SettingsStore settingsStore;
|
|
|
|
|
2020-12-18 12:42:53 +00:00
|
|
|
@action
|
|
|
|
Future<void> _updateTrade() async {
|
|
|
|
try {
|
|
|
|
final updatedTrade = await _provider.findTradeById(id: trade.id);
|
|
|
|
|
|
|
|
if (updatedTrade.createdAt == null && trade.createdAt != null) {
|
|
|
|
updatedTrade.createdAt = trade.createdAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
trade = updatedTrade;
|
|
|
|
|
|
|
|
_updateItems();
|
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _updateItems() {
|
2022-09-02 13:10:54 +00:00
|
|
|
final dateFormat = DateFormatter.withCurrentLocal(reverse: true);
|
2020-12-18 12:42:53 +00:00
|
|
|
|
|
|
|
items?.clear();
|
|
|
|
|
2022-09-02 13:10:54 +00:00
|
|
|
items.add(
|
|
|
|
DetailsListStatusItem(
|
2020-12-18 12:42:53 +00:00
|
|
|
title: S.current.trade_details_state,
|
|
|
|
value: trade.state != null
|
|
|
|
? trade.state.toString()
|
|
|
|
: S.current.trade_details_fetching)
|
2022-09-02 13:10:54 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
items.add(TradeDetailsListCardItem.tradeDetails(
|
|
|
|
id: trade.id,
|
|
|
|
createdAt: dateFormat.format(trade.createdAt),
|
|
|
|
from: trade.from,
|
|
|
|
to: trade.to,
|
|
|
|
onTap: (BuildContext context) {
|
|
|
|
Clipboard.setData(ClipboardData(text: '${trade.id}'));
|
|
|
|
showBar<void>(context, S.of(context).copied_to_clipboard);
|
|
|
|
},
|
|
|
|
));
|
2020-12-18 12:42:53 +00:00
|
|
|
|
|
|
|
if (trade.provider != null) {
|
|
|
|
items.add(StandartListItem(
|
|
|
|
title: S.current.trade_details_provider,
|
|
|
|
value: trade.provider.toString()));
|
|
|
|
}
|
|
|
|
|
2021-02-09 15:50:41 +00:00
|
|
|
if (trade.provider == ExchangeProviderDescription.changeNow) {
|
2021-02-09 00:31:47 +00:00
|
|
|
final buildURL =
|
|
|
|
'https://changenow.io/exchange/txs/${trade.id.toString()}';
|
2021-02-02 01:36:36 +00:00
|
|
|
items.add(TrackTradeListItem(
|
2021-02-09 00:31:47 +00:00
|
|
|
title: 'Track',
|
|
|
|
value: buildURL,
|
2021-02-02 01:36:36 +00:00
|
|
|
onTap: () {
|
2021-02-09 00:31:47 +00:00
|
|
|
launch(buildURL);
|
2021-02-02 01:36:36 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-04-13 13:28:21 +00:00
|
|
|
if (trade.provider == ExchangeProviderDescription.sideShift) {
|
|
|
|
final buildURL = 'https://sideshift.ai/orders/${trade.id.toString()}';
|
|
|
|
items.add(TrackTradeListItem(
|
|
|
|
title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
|
|
|
|
}
|
|
|
|
|
2022-08-31 15:34:07 +00:00
|
|
|
if (trade.provider == ExchangeProviderDescription.simpleSwap) {
|
|
|
|
final buildURL = 'https://simpleswap.io/exchange?id=${trade.id.toString()}';
|
|
|
|
items.add(TrackTradeListItem(
|
|
|
|
title: 'Track', value: buildURL, onTap: () => launch(buildURL)));
|
|
|
|
}
|
|
|
|
|
2020-12-18 12:42:53 +00:00
|
|
|
if (trade.createdAt != null) {
|
|
|
|
items.add(StandartListItem(
|
|
|
|
title: S.current.trade_details_created_at,
|
|
|
|
value: dateFormat.format(trade.createdAt).toString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trade.from != null && trade.to != null) {
|
|
|
|
items.add(StandartListItem(
|
|
|
|
title: S.current.trade_details_pair,
|
|
|
|
value: '${trade.from.toString()} → ${trade.to.toString()}'));
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 01:36:36 +00:00
|
|
|
}
|