2021-03-12 19:04:37 +00:00
|
|
|
import 'dart:async';
|
2021-04-12 18:22:22 +00:00
|
|
|
import 'package:cake_wallet/buy/order.dart';
|
2021-03-12 19:04:37 +00:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/order_list_item.dart';
|
2024-11-07 14:46:08 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2021-03-12 19:04:37 +00:00
|
|
|
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 {
|
2024-11-07 14:46:08 +00:00
|
|
|
OrdersStoreBase({required this.ordersSource, required this.settingsStore})
|
|
|
|
: orders = <OrderListItem>[],
|
|
|
|
orderId = '' {
|
|
|
|
_onOrdersChanged = ordersSource.watch().listen((_) async => await updateOrderList());
|
2021-03-12 19:04:37 +00:00
|
|
|
updateOrderList();
|
|
|
|
}
|
|
|
|
|
|
|
|
Box<Order> ordersSource;
|
2022-10-12 17:09:57 +00:00
|
|
|
|
2021-03-12 19:04:37 +00:00
|
|
|
SettingsStore settingsStore;
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
StreamSubscription<BoxEvent>? _onOrdersChanged;
|
|
|
|
|
2021-03-12 19:04:37 +00:00
|
|
|
@observable
|
|
|
|
List<OrderListItem> orders;
|
|
|
|
|
|
|
|
@observable
|
2022-10-12 17:09:57 +00:00
|
|
|
Order? order;
|
2021-03-12 19:04:37 +00:00
|
|
|
|
2021-03-17 18:21:26 +00:00
|
|
|
@observable
|
|
|
|
String orderId;
|
|
|
|
|
2021-03-12 19:04:37 +00:00
|
|
|
@action
|
|
|
|
void setOrder(Order order) => this.order = order;
|
|
|
|
|
|
|
|
@action
|
2024-11-07 14:46:08 +00:00
|
|
|
Future updateOrderList() async => orders = ordersSource.values
|
|
|
|
.map((order) => OrderListItem(
|
|
|
|
order: order,
|
|
|
|
settingsStore: settingsStore,
|
|
|
|
key: ValueKey('order_list_item_${order.id}_key'),
|
|
|
|
))
|
|
|
|
.toList();
|
|
|
|
}
|