cake_wallet/lib/store/dashboard/orders_store.dart

45 lines
1.1 KiB
Dart
Raw Permalink Normal View History

import 'dart:async';
import 'package:cake_wallet/buy/order.dart';
import 'package:cake_wallet/view_model/dashboard/order_list_item.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/store/settings_store.dart';
part 'orders_store.g.dart';
class OrdersStore = OrdersStoreBase with _$OrdersStore;
abstract class OrdersStoreBase with Store {
2022-10-12 17:09:57 +00:00
OrdersStoreBase({required this.ordersSource,
required this.settingsStore})
: orders = <OrderListItem>[],
orderId = '' {
_onOrdersChanged =
ordersSource.watch().listen((_) async => await updateOrderList());
updateOrderList();
}
Box<Order> ordersSource;
2022-10-12 17:09:57 +00:00
SettingsStore settingsStore;
2022-10-12 17:09:57 +00:00
StreamSubscription<BoxEvent>? _onOrdersChanged;
@observable
List<OrderListItem> orders;
@observable
2022-10-12 17:09:57 +00:00
Order? order;
@observable
String orderId;
@action
void setOrder(Order order) => this.order = order;
@action
Future updateOrderList() async => orders =
ordersSource.values.map((order) => OrderListItem(
order: order,
settingsStore: settingsStore)).toList();
}