2020-07-23 12:20:52 +00:00
|
|
|
import 'dart:async';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/exchange/trade.dart';
|
2020-07-23 12:20:52 +00:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
2024-11-07 14:46:08 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-07-23 12:20:52 +00:00
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
|
|
|
|
part 'trades_store.g.dart';
|
|
|
|
|
|
|
|
class TradesStore = TradesStoreBase with _$TradesStore;
|
|
|
|
|
|
|
|
abstract class TradesStoreBase with Store {
|
2022-10-12 17:09:57 +00:00
|
|
|
TradesStoreBase({required this.tradesSource, required this.settingsStore})
|
2024-11-07 14:46:08 +00:00
|
|
|
: trades = <TradeListItem>[] {
|
|
|
|
_onTradesChanged = tradesSource.watch().listen((_) async => await updateTradeList());
|
2020-07-23 12:20:52 +00:00
|
|
|
updateTradeList();
|
|
|
|
}
|
|
|
|
|
|
|
|
Box<Trade> tradesSource;
|
2022-10-12 17:09:57 +00:00
|
|
|
StreamSubscription<BoxEvent>? _onTradesChanged;
|
2020-07-23 12:20:52 +00:00
|
|
|
SettingsStore settingsStore;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
List<TradeListItem> trades;
|
|
|
|
|
2020-08-26 17:31:23 +00:00
|
|
|
@observable
|
2022-10-12 17:09:57 +00:00
|
|
|
Trade? trade;
|
2020-08-26 17:31:23 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
void setTrade(Trade trade) => this.trade = trade;
|
|
|
|
|
2020-07-23 12:20:52 +00:00
|
|
|
@action
|
2024-11-07 14:46:08 +00:00
|
|
|
Future<void> updateTradeList() async => trades = tradesSource.values
|
|
|
|
.map((trade) => TradeListItem(
|
|
|
|
trade: trade,
|
|
|
|
settingsStore: settingsStore,
|
|
|
|
key: ValueKey('trade_list_item_${trade.id}_key'),
|
|
|
|
))
|
|
|
|
.toList();
|
|
|
|
}
|