2022-09-01 16:14:01 +00:00
|
|
|
import 'package:cake_wallet/ionia/ionia_create_state.dart';
|
2022-07-28 17:03:16 +00:00
|
|
|
import 'package:cake_wallet/ionia/ionia_service.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
|
|
|
|
|
|
|
part 'ionia_account_view_model.g.dart';
|
|
|
|
|
|
|
|
class IoniaAccountViewModel = IoniaAccountViewModelBase with _$IoniaAccountViewModel;
|
|
|
|
|
|
|
|
abstract class IoniaAccountViewModelBase with Store {
|
|
|
|
IoniaAccountViewModelBase({this.ioniaService}) {
|
|
|
|
email = '';
|
|
|
|
giftCards = [];
|
|
|
|
ioniaService.getUserEmail().then((email) => this.email = email);
|
|
|
|
updateUserGiftCards();
|
|
|
|
}
|
|
|
|
|
|
|
|
final IoniaService ioniaService;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
String email;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
List<IoniaGiftCard> giftCards;
|
|
|
|
|
2022-09-01 16:14:01 +00:00
|
|
|
@observable
|
|
|
|
IoniaMerchantState merchantState;
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@computed
|
|
|
|
int get countOfMerch => giftCards.where((giftCard) => !giftCard.isEmpty).length;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
List<IoniaGiftCard> get activeMechs => giftCards.where((giftCard) => !giftCard.isEmpty).toList();
|
|
|
|
|
|
|
|
@computed
|
|
|
|
List<IoniaGiftCard> get redeemedMerchs => giftCards.where((giftCard) => giftCard.isEmpty).toList();
|
|
|
|
|
|
|
|
@action
|
|
|
|
void logout() {
|
|
|
|
ioniaService.logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
Future<void> updateUserGiftCards() async {
|
2022-09-01 16:14:01 +00:00
|
|
|
merchantState = IoniaLoadingMerchantState();
|
2022-07-28 17:03:16 +00:00
|
|
|
giftCards = await ioniaService.getCurrentUserGiftCardSummaries();
|
2022-09-01 16:14:01 +00:00
|
|
|
merchantState = IoniaLoadedMerchantState();
|
2022-07-28 17:03:16 +00:00
|
|
|
}
|
|
|
|
}
|