Fix ionia loading states (#493)

This commit is contained in:
Godwin Asuquo 2022-09-01 19:14:01 +03:00 committed by GitHub
parent c50eeee58b
commit a745319ffa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 5 deletions

View file

@ -56,3 +56,11 @@ class IoniaCardSuccess extends IoniaFetchCardState {
final IoniaVirtualCard card;
}
abstract class IoniaMerchantState {}
class IoniaLoadingMerchantState extends IoniaMerchantState {}
class IoniaLoadedMerchantState extends IoniaMerchantState {}

View file

@ -1,7 +1,6 @@
import 'dart:ffi';
import 'package:cake_wallet/ionia/ionia_create_state.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/screens/ionia/widgets/card_item.dart';
@ -106,6 +105,7 @@ class _IoniaCardTabsState extends State<_IoniaCardTabs> with SingleTickerProvide
_IoniaCardListView(
emptyText: S.of(context).gift_card_balance_note,
merchList: viewModel.activeMechs,
isLoading: viewModel.merchantState is IoniaLoadingMerchantState,
onTap: (giftCard) {
Navigator.pushNamed(
context,
@ -116,6 +116,7 @@ class _IoniaCardTabsState extends State<_IoniaCardTabs> with SingleTickerProvide
_IoniaCardListView(
emptyText: S.of(context).gift_card_redeemed_note,
merchList: viewModel.redeemedMerchs,
isLoading: viewModel.merchantState is IoniaLoadingMerchantState,
onTap: (giftCard) {
Navigator.pushNamed(
context,
@ -139,14 +140,24 @@ class _IoniaCardListView extends StatelessWidget {
@required this.emptyText,
@required this.merchList,
@required this.onTap,
this.isLoading = false,
}) : super(key: key);
final String emptyText;
final List<IoniaGiftCard> merchList;
final void Function(IoniaGiftCard giftCard) onTap;
final bool isLoading;
@override
Widget build(BuildContext context) {
if(isLoading){
return Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).accentTextTheme.display3.backgroundColor,
valueColor: AlwaysStoppedAnimation<Color>(Theme.of(context).primaryTextTheme.body1.color),
),
);
}
return merchList.isEmpty
? Center(
child: Text(

View file

@ -1,5 +1,6 @@
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/ionia/ionia_category.dart';
import 'package:cake_wallet/ionia/ionia_create_state.dart';
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
@ -208,7 +209,10 @@ class _IoniaManageCardsPageBodyState extends State<IoniaManageCardsPageBody> {
@override
Widget build(BuildContext context) {
return Observer(
builder: (_) => Stack(children: [
builder: (_) {
final merchantState = widget.cardsListViewModel.merchantState;
if (merchantState is IoniaLoadedMerchantState) {
return Stack(children: [
ListView.separated(
padding: EdgeInsets.only(left: 2, right: 22),
controller: _scrollController,
@ -241,7 +245,15 @@ class _IoniaManageCardsPageBodyState extends State<IoniaManageCardsPageBody> {
fromTop: widget.cardsListViewModel.scrollOffsetFromTop,
)
: Offstage()
]),
]);
}
return Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).accentTextTheme.display3.backgroundColor,
valueColor: AlwaysStoppedAnimation<Color>(Theme.of(context).primaryTextTheme.body1.color),
),
);
}
);
}
}

View file

@ -1,4 +1,4 @@
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/ionia/ionia_create_state.dart';
import 'package:cake_wallet/ionia/ionia_service.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
@ -23,6 +23,9 @@ abstract class IoniaAccountViewModelBase with Store {
@observable
List<IoniaGiftCard> giftCards;
@observable
IoniaMerchantState merchantState;
@computed
int get countOfMerch => giftCards.where((giftCard) => !giftCard.isEmpty).length;
@ -39,6 +42,8 @@ abstract class IoniaAccountViewModelBase with Store {
@action
Future<void> updateUserGiftCards() async {
merchantState = IoniaLoadingMerchantState();
giftCards = await ioniaService.getCurrentUserGiftCardSummaries();
merchantState = IoniaLoadedMerchantState();
}
}

View file

@ -39,6 +39,9 @@ abstract class IoniaGiftCardsListViewModelBase with Store {
@observable
IoniaFetchCardState cardState;
@observable
IoniaMerchantState merchantState;
@observable
List<IoniaMerchant> ioniaMerchants;
@ -86,10 +89,13 @@ abstract class IoniaGiftCardsListViewModelBase with Store {
}
void _getMerchants() {
merchantState = IoniaLoadingMerchantState();
ioniaService.getMerchantsByFilter(categories: selectedFilters).then((value) {
value.sort((a, b) => a.legalName.toLowerCase().compareTo(b.legalName.toLowerCase()));
ioniaMerchants = ioniaMerchantList = value;
merchantState = IoniaLoadedMerchantState();
});
}
@action