Fix update gift cards list.

This commit is contained in:
M 2022-07-14 19:59:34 +01:00
parent b9cc776614
commit ce479849ea
4 changed files with 35 additions and 15 deletions

View file

@ -1,3 +1,5 @@
import 'dart:ffi';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/routes.dart';
@ -104,11 +106,23 @@ class _IoniaCardTabsState extends State<_IoniaCardTabs> with SingleTickerProvide
_IoniaCardListView(
emptyText: S.of(context).gift_card_balance_note,
merchList: viewModel.activeMechs,
),
onTap: (giftCard) {
Navigator.pushNamed(
context,
Routes.ioniaGiftCardDetailPage,
arguments: [giftCard])
.then((_) => viewModel.updateUserGiftCards());
}),
_IoniaCardListView(
emptyText: S.of(context).gift_card_redeemed_note,
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,
@required this.emptyText,
@required this.merchList,
@required this.onTap,
}) : super(key: key);
final String emptyText;
final List<IoniaGiftCard> merchList;
final void Function(IoniaGiftCard giftCard) onTap;
@override
Widget build(BuildContext context) {
@ -148,11 +164,7 @@ class _IoniaCardListView extends StatelessWidget {
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: CardItem(
onTap: () => Navigator.pushNamed(
context,
Routes.ioniaGiftCardDetailPage,
arguments: [merchant],
),
onTap: () => onTap?.call(merchant),
title: merchant.legalName,
backgroundColor: Theme.of(context).accentTextTheme.display4.backgroundColor.withOpacity(0.1),
discount: 0,

View file

@ -47,7 +47,10 @@ class IoniaAccountPage extends BasePage {
),
)),
InkWell(
onTap: () => Navigator.pushNamed(context, Routes.ioniaAccountCardsPage),
onTap: () {
Navigator.pushNamed(context, Routes.ioniaAccountCardsPage)
.then((_) => ioniaAccountViewModel.updateUserGiftCards());
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(

View file

@ -10,9 +10,9 @@ class IoniaAccountViewModel = IoniaAccountViewModelBase with _$IoniaAccountViewM
abstract class IoniaAccountViewModelBase with Store {
IoniaAccountViewModelBase({this.ioniaService}) {
email = '';
merchs = [];
giftCards = [];
ioniaService.getUserEmail().then((email) => this.email = email);
ioniaService.getCurrentUserGiftCardSummaries().then((merchs) => this.merchs = merchs);
updateUserGiftCards();
}
final IoniaService ioniaService;
@ -21,19 +21,24 @@ abstract class IoniaAccountViewModelBase with Store {
String email;
@observable
List<IoniaGiftCard> merchs;
List<IoniaGiftCard> giftCards;
@computed
int get countOfMerch => merchs.where((merch) => !merch.isEmpty).length;
int get countOfMerch => giftCards.where((giftCard) => !giftCard.isEmpty).length;
@computed
List<IoniaGiftCard> get activeMechs => merchs.where((merch) => !merch.isEmpty).toList();
List<IoniaGiftCard> get activeMechs => giftCards.where((giftCard) => !giftCard.isEmpty).toList();
@computed
List<IoniaGiftCard> get redeemedMerchs => merchs.where((merch) => merch.isEmpty).toList();
List<IoniaGiftCard> get redeemedMerchs => giftCards.where((giftCard) => giftCard.isEmpty).toList();
@action
void logout() {
ioniaService.logout();
}
@action
Future<void> updateUserGiftCards() async {
giftCards = await ioniaService.getCurrentUserGiftCardSummaries();
}
}

View file

@ -24,7 +24,7 @@ abstract class IoniaGiftCardDetailsViewModelBase with Store {
@action
Future<void> redeem() async {
try {
redeemState = InitialExecutionState();
redeemState = IsExecutingState();
await ioniaService.redeem(giftCard);
giftCard = await ioniaService.getGiftCard(id: giftCard.id);
redeemState = ExecutedSuccessfullyState();