2021-03-23 17:19:01 +00:00
|
|
|
import 'package:cake_wallet/entities/wyre_service.dart';
|
2021-03-23 11:05:01 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:cake_wallet/entities/order.dart';
|
|
|
|
import 'package:cake_wallet/store/dashboard/orders_store.dart';
|
2021-03-23 17:19:01 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2021-03-23 11:05:01 +00:00
|
|
|
|
2021-03-23 17:19:01 +00:00
|
|
|
part 'wyre_view_model.g.dart';
|
|
|
|
|
|
|
|
class WyreViewModel = WyreViewModelBase with _$WyreViewModel;
|
|
|
|
|
|
|
|
abstract class WyreViewModelBase with Store {
|
|
|
|
WyreViewModelBase(this.ordersSource, this.ordersStore,
|
2021-03-31 17:02:44 +00:00
|
|
|
{@required this.wyreService});
|
2021-03-23 17:19:01 +00:00
|
|
|
|
|
|
|
Future<String> get wyreUrl => wyreService.getWyreUrl();
|
|
|
|
|
|
|
|
String get trackUrl => wyreService.trackUrl;
|
2021-03-23 11:05:01 +00:00
|
|
|
|
|
|
|
final Box<Order> ordersSource;
|
|
|
|
final OrdersStore ordersStore;
|
|
|
|
|
2021-03-23 18:57:20 +00:00
|
|
|
final WyreService wyreService;
|
2021-03-23 11:05:01 +00:00
|
|
|
|
2021-03-23 17:19:01 +00:00
|
|
|
Future<void> saveOrder(String orderId) async {
|
|
|
|
try {
|
|
|
|
final order = await wyreService.findOrderById(orderId);
|
|
|
|
await ordersSource.add(order);
|
|
|
|
ordersStore.setOrder(order);
|
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
2021-03-23 11:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-23 18:57:20 +00:00
|
|
|
}
|