mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
Merge branch 'ionia' of https://github.com/cake-tech/cake_wallet into CW-127-add-localization-for-ionia
This commit is contained in:
commit
1c2d35aafc
10 changed files with 236 additions and 35 deletions
|
@ -145,6 +145,7 @@ import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||||
import 'package:cake_wallet/src/screens/dashboard/widgets/address_page.dart';
|
import 'package:cake_wallet/src/screens/dashboard/widgets/address_page.dart';
|
||||||
import 'package:cake_wallet/ionia/ionia_token_service.dart';
|
import 'package:cake_wallet/ionia/ionia_token_service.dart';
|
||||||
import 'package:cake_wallet/anypay/anypay_api.dart';
|
import 'package:cake_wallet/anypay/anypay_api.dart';
|
||||||
|
import 'package:cake_wallet/view_model/ionia/ionia_gift_card_details_view_model.dart';
|
||||||
|
|
||||||
final getIt = GetIt.instance;
|
final getIt = GetIt.instance;
|
||||||
|
|
||||||
|
@ -713,8 +714,14 @@ Future setup(
|
||||||
return IoniaBuyGiftCardDetailPage(getIt.get<IoniaMerchPurchaseViewModel>(param1: amount, param2: merchant));
|
return IoniaBuyGiftCardDetailPage(getIt.get<IoniaMerchPurchaseViewModel>(param1: amount, param2: merchant));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
getIt.registerFactoryParam<IoniaGiftCardDetailsViewModel, IoniaGiftCard, void>((IoniaGiftCard giftCard, _) {
|
||||||
|
return IoniaGiftCardDetailsViewModel(
|
||||||
|
ioniaService: getIt.get<IoniaService>(),
|
||||||
|
giftCard: giftCard);
|
||||||
|
});
|
||||||
|
|
||||||
getIt.registerFactoryParam<IoniaGiftCardDetailPage, IoniaGiftCard, void>((IoniaGiftCard giftCard, _) {
|
getIt.registerFactoryParam<IoniaGiftCardDetailPage, IoniaGiftCard, void>((IoniaGiftCard giftCard, _) {
|
||||||
return IoniaGiftCardDetailPage(giftCard);
|
return IoniaGiftCardDetailPage(getIt.get<IoniaGiftCardDetailsViewModel>(param1: giftCard));
|
||||||
});
|
});
|
||||||
|
|
||||||
getIt.registerFactoryParam<IoniaCustomTipPage, List, void>((List args, _) {
|
getIt.registerFactoryParam<IoniaCustomTipPage, List, void>((List args, _) {
|
||||||
|
|
|
@ -19,6 +19,8 @@ class IoniaApi {
|
||||||
static final getMerchantsByFilterUrl = Uri.https(baseUri, '/$pathPrefix/GetMerchantsByFilter');
|
static final getMerchantsByFilterUrl = Uri.https(baseUri, '/$pathPrefix/GetMerchantsByFilter');
|
||||||
static final getPurchaseMerchantsUrl = Uri.https(baseUri, '/$pathPrefix/PurchaseGiftCard');
|
static final getPurchaseMerchantsUrl = Uri.https(baseUri, '/$pathPrefix/PurchaseGiftCard');
|
||||||
static final getCurrentUserGiftCardSummariesUrl = Uri.https(baseUri, '/$pathPrefix/GetCurrentUserGiftCardSummaries');
|
static final getCurrentUserGiftCardSummariesUrl = Uri.https(baseUri, '/$pathPrefix/GetCurrentUserGiftCardSummaries');
|
||||||
|
static final changeGiftCardUrl = Uri.https(baseUri, '/$pathPrefix/ChargeGiftCard');
|
||||||
|
static final getGiftCardUrl = Uri.https(baseUri, '/$pathPrefix/GetGiftCard');
|
||||||
|
|
||||||
// Create user
|
// Create user
|
||||||
|
|
||||||
|
@ -274,4 +276,83 @@ class IoniaApi {
|
||||||
return IoniaGiftCard.fromJsonMap(element);
|
return IoniaGiftCard.fromJsonMap(element);
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Charge Gift Card
|
||||||
|
|
||||||
|
Future<void> chargeGiftCard({
|
||||||
|
@required String username,
|
||||||
|
@required String password,
|
||||||
|
@required String clientId,
|
||||||
|
@required int giftCardId,
|
||||||
|
@required double amount}) async {
|
||||||
|
final headers = <String, String>{
|
||||||
|
'clientId': clientId,
|
||||||
|
'username': username,
|
||||||
|
'password': password,
|
||||||
|
'Content-Type': 'application/json'};
|
||||||
|
final body = <String, dynamic>{
|
||||||
|
'Id': giftCardId,
|
||||||
|
'Amount': amount};
|
||||||
|
final response = await post(
|
||||||
|
changeGiftCardUrl,
|
||||||
|
headers: headers,
|
||||||
|
body: json.encode(body));
|
||||||
|
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
throw Exception('Failed to update Gift Card with ID ${giftCardId};Incorrect response status: ${response.statusCode};');
|
||||||
|
}
|
||||||
|
|
||||||
|
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
|
||||||
|
final isSuccessful = decodedBody['Successful'] as bool ?? false;
|
||||||
|
|
||||||
|
if (!isSuccessful) {
|
||||||
|
final data = decodedBody['Data'] as Map<String, dynamic>;
|
||||||
|
final msg = data['Message'] as String ?? '';
|
||||||
|
|
||||||
|
if (msg.isNotEmpty) {
|
||||||
|
throw Exception(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Exception('Failed to update Gift Card with ID ${giftCardId};');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Gift Card
|
||||||
|
|
||||||
|
Future<IoniaGiftCard> getGiftCard({
|
||||||
|
@required String username,
|
||||||
|
@required String password,
|
||||||
|
@required String clientId,
|
||||||
|
@required int id}) async {
|
||||||
|
final headers = <String, String>{
|
||||||
|
'clientId': clientId,
|
||||||
|
'username': username,
|
||||||
|
'password': password,
|
||||||
|
'Content-Type': 'application/json'};
|
||||||
|
final body = <String, dynamic>{'Id': id};
|
||||||
|
final response = await post(
|
||||||
|
getGiftCardUrl,
|
||||||
|
headers: headers,
|
||||||
|
body: json.encode(body));
|
||||||
|
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
throw Exception('Failed to get Gift Card with ID ${id};Incorrect response status: ${response.statusCode};');
|
||||||
|
}
|
||||||
|
|
||||||
|
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
|
||||||
|
final isSuccessful = decodedBody['Successful'] as bool ?? false;
|
||||||
|
|
||||||
|
if (!isSuccessful) {
|
||||||
|
final msg = decodedBody['ErrorMessage'] as String ?? '';
|
||||||
|
|
||||||
|
if (msg.isNotEmpty) {
|
||||||
|
throw Exception(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Exception('Failed to get Gift Card with ID ${id};');
|
||||||
|
}
|
||||||
|
|
||||||
|
final data = decodedBody['Data'] as Map<String, dynamic>;
|
||||||
|
return IoniaGiftCard.fromJsonMap(data);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ class IoniaGiftCard {
|
||||||
systemName: element['SystemName'] as String,
|
systemName: element['SystemName'] as String,
|
||||||
barcodeUrl: element['BarcodeUrl'] as String,
|
barcodeUrl: element['BarcodeUrl'] as String,
|
||||||
cardNumber: element['CardNumber'] as String,
|
cardNumber: element['CardNumber'] as String,
|
||||||
|
cardPin: element['CardPin'] as String,
|
||||||
tip: element['Tip'] as double,
|
tip: element['Tip'] as double,
|
||||||
purchaseAmount: element['PurchaseAmount'] as double,
|
purchaseAmount: element['PurchaseAmount'] as double,
|
||||||
actualAmount: element['ActualAmount'] as double,
|
actualAmount: element['ActualAmount'] as double,
|
||||||
|
|
|
@ -120,4 +120,33 @@ class IoniaService {
|
||||||
final password = await secureStorage.read(key: ioniaPasswordStorageKey);
|
final password = await secureStorage.read(key: ioniaPasswordStorageKey);
|
||||||
return ioniaApi.getCurrentUserGiftCardSummaries(username: username, password: password, clientId: clientId);
|
return ioniaApi.getCurrentUserGiftCardSummaries(username: username, password: password, clientId: clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Charge Gift Card
|
||||||
|
|
||||||
|
Future<void> chargeGiftCard({
|
||||||
|
@required int giftCardId,
|
||||||
|
@required double amount}) async {
|
||||||
|
final username = await secureStorage.read(key: ioniaUsernameStorageKey);
|
||||||
|
final password = await secureStorage.read(key: ioniaPasswordStorageKey);
|
||||||
|
await ioniaApi.chargeGiftCard(
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
clientId: clientId,
|
||||||
|
giftCardId: giftCardId,
|
||||||
|
amount: amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redeem
|
||||||
|
|
||||||
|
Future<void> redeem(IoniaGiftCard giftCard) async {
|
||||||
|
await chargeGiftCard(giftCardId: giftCard.id, amount: giftCard.remainingAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Gift Card
|
||||||
|
|
||||||
|
Future<IoniaGiftCard> getGiftCard({@required int id}) async {
|
||||||
|
final username = await secureStorage.read(key: ioniaUsernameStorageKey);
|
||||||
|
final password = await secureStorage.read(key: ioniaPasswordStorageKey);
|
||||||
|
return ioniaApi.getGiftCard(username: username, password: password, clientId: clientId,id: id);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -143,5 +143,6 @@ class IoniaVerifyIoniaOtp extends BasePage {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onOtpSuccessful(BuildContext context) =>
|
void _onOtpSuccessful(BuildContext context) =>
|
||||||
Navigator.pushNamedAndRemoveUntil(context, Routes.ioniaManageCardsPage, ModalRoute.withName(Routes.dashboard));
|
Navigator.of(context)
|
||||||
|
.pushNamedAndRemoveUntil(Routes.ioniaManageCardsPage, (route) => route.isFirst);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||||
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
||||||
import 'package:cake_wallet/routes.dart';
|
import 'package:cake_wallet/routes.dart';
|
||||||
|
@ -104,11 +106,23 @@ class _IoniaCardTabsState extends State<_IoniaCardTabs> with SingleTickerProvide
|
||||||
_IoniaCardListView(
|
_IoniaCardListView(
|
||||||
emptyText: S.of(context).gift_card_balance_note,
|
emptyText: S.of(context).gift_card_balance_note,
|
||||||
merchList: viewModel.activeMechs,
|
merchList: viewModel.activeMechs,
|
||||||
),
|
onTap: (giftCard) {
|
||||||
|
Navigator.pushNamed(
|
||||||
|
context,
|
||||||
|
Routes.ioniaGiftCardDetailPage,
|
||||||
|
arguments: [giftCard])
|
||||||
|
.then((_) => viewModel.updateUserGiftCards());
|
||||||
|
}),
|
||||||
_IoniaCardListView(
|
_IoniaCardListView(
|
||||||
emptyText: S.of(context).gift_card_redeemed_note,
|
emptyText: S.of(context).gift_card_redeemed_note,
|
||||||
merchList: viewModel.redeemedMerchs,
|
merchList: viewModel.redeemedMerchs,
|
||||||
),
|
onTap: (giftCard) {
|
||||||
|
Navigator.pushNamed(
|
||||||
|
context,
|
||||||
|
Routes.ioniaGiftCardDetailPage,
|
||||||
|
arguments: [giftCard])
|
||||||
|
.then((_) => viewModel.updateUserGiftCards());
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
@ -124,10 +138,12 @@ class _IoniaCardListView extends StatelessWidget {
|
||||||
Key key,
|
Key key,
|
||||||
@required this.emptyText,
|
@required this.emptyText,
|
||||||
@required this.merchList,
|
@required this.merchList,
|
||||||
|
@required this.onTap,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final String emptyText;
|
final String emptyText;
|
||||||
final List<IoniaGiftCard> merchList;
|
final List<IoniaGiftCard> merchList;
|
||||||
|
final void Function(IoniaGiftCard giftCard) onTap;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -148,11 +164,7 @@ class _IoniaCardListView extends StatelessWidget {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 16),
|
padding: const EdgeInsets.only(bottom: 16),
|
||||||
child: CardItem(
|
child: CardItem(
|
||||||
onTap: () => Navigator.pushNamed(
|
onTap: () => onTap?.call(merchant),
|
||||||
context,
|
|
||||||
Routes.ioniaGiftCardDetailPage,
|
|
||||||
arguments: [merchant],
|
|
||||||
),
|
|
||||||
title: merchant.legalName,
|
title: merchant.legalName,
|
||||||
backgroundColor: Theme.of(context).accentTextTheme.display4.backgroundColor.withOpacity(0.1),
|
backgroundColor: Theme.of(context).accentTextTheme.display4.backgroundColor.withOpacity(0.1),
|
||||||
discount: 0,
|
discount: 0,
|
||||||
|
|
|
@ -47,7 +47,10 @@ class IoniaAccountPage extends BasePage {
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () => Navigator.pushNamed(context, Routes.ioniaAccountCardsPage),
|
onTap: () {
|
||||||
|
Navigator.pushNamed(context, Routes.ioniaAccountCardsPage)
|
||||||
|
.then((_) => ioniaAccountViewModel.updateUserGiftCards());
|
||||||
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
|
import 'package:cake_wallet/core/execution_state.dart';
|
||||||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||||
import 'package:cake_wallet/src/screens/ionia/widgets/ionia_tile.dart';
|
import 'package:cake_wallet/src/screens/ionia/widgets/ionia_tile.dart';
|
||||||
import 'package:cake_wallet/src/screens/ionia/widgets/text_icon_button.dart';
|
import 'package:cake_wallet/src/screens/ionia/widgets/text_icon_button.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_background.dart';
|
import 'package:cake_wallet/src/widgets/alert_background.dart';
|
||||||
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||||
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
||||||
import 'package:cake_wallet/typography.dart';
|
import 'package:cake_wallet/typography.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
|
import 'package:cake_wallet/view_model/ionia/ionia_gift_card_details_view_model.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/src/widgets/framework.dart';
|
import 'package:flutter/src/widgets/framework.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
|
||||||
class IoniaGiftCardDetailPage extends BasePage {
|
class IoniaGiftCardDetailPage extends BasePage {
|
||||||
IoniaGiftCardDetailPage(this.merchant);
|
IoniaGiftCardDetailPage(this.viewModel);
|
||||||
|
|
||||||
final IoniaGiftCard merchant;
|
final IoniaGiftCardDetailsViewModel viewModel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget leading(BuildContext context) {
|
Widget leading(BuildContext context) {
|
||||||
|
@ -48,56 +53,78 @@ class IoniaGiftCardDetailPage extends BasePage {
|
||||||
@override
|
@override
|
||||||
Widget middle(BuildContext context) {
|
Widget middle(BuildContext context) {
|
||||||
return Text(
|
return Text(
|
||||||
merchant.legalName,
|
viewModel.giftCard.legalName,
|
||||||
style: textLargeSemiBold(color: Theme.of(context).accentTextTheme.display4.backgroundColor),
|
style: textLargeSemiBold(color: Theme.of(context).accentTextTheme.display4.backgroundColor),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) {
|
Widget body(BuildContext context) {
|
||||||
|
reaction((_) => viewModel.redeemState, (ExecutionState state) {
|
||||||
|
if (state is FailureState) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
showPopUp<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertWithOneAction(
|
||||||
|
alertTitle: S.of(context).error,
|
||||||
|
alertContent: state.error,
|
||||||
|
buttonText: S.of(context).ok,
|
||||||
|
buttonAction: () => Navigator.of(context).pop());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return ScrollableWithBottomSection(
|
return ScrollableWithBottomSection(
|
||||||
contentPadding: EdgeInsets.all(24),
|
contentPadding: EdgeInsets.all(24),
|
||||||
content: Column(
|
content: Column(
|
||||||
children: [
|
children: [
|
||||||
if (merchant.barcodeUrl != null && merchant.barcodeUrl.isNotEmpty)
|
if (viewModel.giftCard.barcodeUrl != null && viewModel.giftCard.barcodeUrl.isNotEmpty)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 24.0,
|
horizontal: 24.0,
|
||||||
vertical: 24,
|
vertical: 24,
|
||||||
),
|
),
|
||||||
child: SizedBox(height: 96, width: double.infinity, child: Image.network(merchant.barcodeUrl)),
|
child: SizedBox(height: 96, width: double.infinity, child: Image.network(viewModel.giftCard.barcodeUrl)),
|
||||||
),
|
),
|
||||||
SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
IoniaTile(
|
IoniaTile(
|
||||||
title: S.of(context).gift_card_number,
|
title: S.of(context).gift_card_number,
|
||||||
subTitle: merchant.cardNumber,
|
subTitle: viewModel.giftCard.cardNumber,
|
||||||
),
|
),
|
||||||
Divider(height: 30),
|
Divider(height: 30),
|
||||||
IoniaTile(
|
IoniaTile(
|
||||||
title: S.of(context).pin_number,
|
title: S.of(context).pin_number,
|
||||||
subTitle: merchant.cardPin ?? '',
|
subTitle: viewModel.giftCard.cardPin ?? '',
|
||||||
),
|
),
|
||||||
Divider(height: 30),
|
Divider(height: 30),
|
||||||
|
Observer(builder: (_) =>
|
||||||
IoniaTile(
|
IoniaTile(
|
||||||
title: S.of(context).amount,
|
title: S.of(context).amount,
|
||||||
subTitle: merchant.remainingAmount.toString() ?? '0',
|
subTitle: viewModel.giftCard.remainingAmount.toString() ?? '0',
|
||||||
),
|
)),
|
||||||
Divider(height: 50),
|
Divider(height: 50),
|
||||||
TextIconButton(
|
TextIconButton(
|
||||||
label: S.of(context).how_to_use_card,
|
label: S.of(context).how_to_use_card,
|
||||||
onTap: () => _showHowToUseCard(context, merchant),
|
onTap: () => _showHowToUseCard(context, viewModel.giftCard),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
bottomSection: Padding(
|
bottomSection: Padding(
|
||||||
padding: EdgeInsets.only(bottom: 12),
|
padding: EdgeInsets.only(bottom: 12),
|
||||||
child: LoadingPrimaryButton(
|
child: Observer(builder: (_) {
|
||||||
isLoading: false,
|
if (!viewModel.giftCard.isEmpty) {
|
||||||
onPressed: () {},
|
return LoadingPrimaryButton(
|
||||||
|
isLoading: viewModel.redeemState is IsExecutingState,
|
||||||
|
onPressed: () => viewModel.redeem(),
|
||||||
text: S.of(context).mark_as_redeemed,
|
text: S.of(context).mark_as_redeemed,
|
||||||
color: Theme.of(context).accentTextTheme.body2.color,
|
color: Theme.of(context).accentTextTheme.body2.color,
|
||||||
textColor: Colors.white,
|
textColor: Colors.white);
|
||||||
)),
|
}
|
||||||
|
|
||||||
|
return Container();
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ class IoniaAccountViewModel = IoniaAccountViewModelBase with _$IoniaAccountViewM
|
||||||
abstract class IoniaAccountViewModelBase with Store {
|
abstract class IoniaAccountViewModelBase with Store {
|
||||||
IoniaAccountViewModelBase({this.ioniaService}) {
|
IoniaAccountViewModelBase({this.ioniaService}) {
|
||||||
email = '';
|
email = '';
|
||||||
merchs = [];
|
giftCards = [];
|
||||||
ioniaService.getUserEmail().then((email) => this.email = email);
|
ioniaService.getUserEmail().then((email) => this.email = email);
|
||||||
ioniaService.getCurrentUserGiftCardSummaries().then((merchs) => this.merchs = merchs);
|
updateUserGiftCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
final IoniaService ioniaService;
|
final IoniaService ioniaService;
|
||||||
|
@ -21,19 +21,24 @@ abstract class IoniaAccountViewModelBase with Store {
|
||||||
String email;
|
String email;
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
List<IoniaGiftCard> merchs;
|
List<IoniaGiftCard> giftCards;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
int get countOfMerch => merchs.where((merch) => merch.isActive).length;
|
int get countOfMerch => giftCards.where((giftCard) => !giftCard.isEmpty).length;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
List<IoniaGiftCard> get activeMechs => merchs.where((merch) => merch.isActive).toList();
|
List<IoniaGiftCard> get activeMechs => giftCards.where((giftCard) => !giftCard.isEmpty).toList();
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
List<IoniaGiftCard> get redeemedMerchs => merchs.where((merch) => !merch.isActive).toList();
|
List<IoniaGiftCard> get redeemedMerchs => giftCards.where((giftCard) => giftCard.isEmpty).toList();
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void logout() {
|
void logout() {
|
||||||
ioniaService.logout();
|
ioniaService.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
Future<void> updateUserGiftCards() async {
|
||||||
|
giftCards = await ioniaService.getCurrentUserGiftCardSummaries();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
35
lib/view_model/ionia/ionia_gift_card_details_view_model.dart
Normal file
35
lib/view_model/ionia/ionia_gift_card_details_view_model.dart
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import 'package:cake_wallet/core/execution_state.dart';
|
||||||
|
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||||
|
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
|
||||||
|
part 'ionia_gift_card_details_view_model.g.dart';
|
||||||
|
|
||||||
|
class IoniaGiftCardDetailsViewModel = IoniaGiftCardDetailsViewModelBase with _$IoniaGiftCardDetailsViewModel;
|
||||||
|
|
||||||
|
abstract class IoniaGiftCardDetailsViewModelBase with Store {
|
||||||
|
|
||||||
|
IoniaGiftCardDetailsViewModelBase({this.ioniaService, this.giftCard}) {
|
||||||
|
redeemState = InitialExecutionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
final IoniaService ioniaService;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
IoniaGiftCard giftCard;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
ExecutionState redeemState;
|
||||||
|
|
||||||
|
@action
|
||||||
|
Future<void> redeem() async {
|
||||||
|
try {
|
||||||
|
redeemState = IsExecutingState();
|
||||||
|
await ioniaService.redeem(giftCard);
|
||||||
|
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
|
||||||
|
redeemState = ExecutedSuccessfullyState();
|
||||||
|
} catch(e) {
|
||||||
|
redeemState = FailureState(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue