2022-07-06 17:13:19 +00:00
|
|
|
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
|
|
|
import 'package:cake_wallet/ionia/ionia_service.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
2022-07-07 18:54:13 +00:00
|
|
|
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
2022-07-06 17:13:19 +00:00
|
|
|
|
|
|
|
part 'ionia_account_view_model.g.dart';
|
|
|
|
|
|
|
|
class IoniaAccountViewModel = IoniaAccountViewModelBase with _$IoniaAccountViewModel;
|
|
|
|
|
|
|
|
abstract class IoniaAccountViewModelBase with Store {
|
|
|
|
IoniaAccountViewModelBase({this.ioniaService}) {
|
|
|
|
email = '';
|
|
|
|
merchs = [];
|
2022-07-07 17:47:27 +00:00
|
|
|
ioniaService.getUserEmail().then((email) => this.email = email);
|
|
|
|
ioniaService.getCurrentUserGiftCardSummaries().then((merchs) => this.merchs = merchs);
|
2022-07-06 17:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final IoniaService ioniaService;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
String email;
|
|
|
|
|
|
|
|
@observable
|
2022-07-07 18:54:13 +00:00
|
|
|
List<IoniaGiftCard> merchs;
|
2022-07-06 17:13:19 +00:00
|
|
|
|
|
|
|
@computed
|
|
|
|
int get countOfMerch => merchs.where((merch) => merch.isActive).length;
|
|
|
|
|
2022-07-07 17:47:27 +00:00
|
|
|
@computed
|
2022-07-07 18:54:13 +00:00
|
|
|
List<IoniaGiftCard> get activeMechs => merchs.where((merch) => merch.isActive).toList();
|
2022-07-07 17:47:27 +00:00
|
|
|
|
|
|
|
@computed
|
2022-07-07 18:54:13 +00:00
|
|
|
List<IoniaGiftCard> get redeemedMerchs => merchs.where((merch) => !merch.isActive).toList();
|
2022-07-07 17:47:27 +00:00
|
|
|
|
2022-07-06 17:13:19 +00:00
|
|
|
@action
|
2022-07-07 17:47:27 +00:00
|
|
|
void logout() {
|
2022-07-06 17:13:19 +00:00
|
|
|
ioniaService.logout();
|
|
|
|
}
|
2022-07-07 17:47:27 +00:00
|
|
|
}
|