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_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,

View file

@ -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(

View file

@ -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.isEmpty).length; int get countOfMerch => giftCards.where((giftCard) => !giftCard.isEmpty).length;
@computed @computed
List<IoniaGiftCard> get activeMechs => merchs.where((merch) => !merch.isEmpty).toList(); List<IoniaGiftCard> get activeMechs => giftCards.where((giftCard) => !giftCard.isEmpty).toList();
@computed @computed
List<IoniaGiftCard> get redeemedMerchs => merchs.where((merch) => merch.isEmpty).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();
}
} }

View file

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