diff --git a/lib/di.dart b/lib/di.dart index 8805a0162..5a4fe165f 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -3,6 +3,7 @@ import 'package:cake_wallet/entities/parse_address_from_domain.dart'; import 'package:cake_wallet/entities/wake_lock.dart'; import 'package:cake_wallet/ionia/ionia_service.dart'; import 'package:cake_wallet/ionia/ionia_api.dart'; +import 'package:cake_wallet/ionia/ionia_merchant.dart'; import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/haven/haven.dart'; import 'package:cake_wallet/haven/haven.dart'; @@ -652,8 +653,9 @@ Future setup( getIt.registerFactory( () => IoniaService(getIt.get(), getIt.get())); - - getIt.registerFactory(() => IoniaViewModel(ioniaService: getIt.get())); + + getIt.registerFactory( + () => IoniaViewModel(ioniaService: getIt.get(), ioniaMerchantService: getIt.get())); getIt.registerFactory(() => IoniaCreateAccountPage(getIt.get())); @@ -668,9 +670,17 @@ Future setup( getIt.registerFactory(() => IoniaWelcomePage(getIt.get())); - getIt.registerFactory(() => IoniaBuyGiftCardPage()); + getIt.registerFactoryParam((List args, _) { + final merchant = args.first as IoniaMerchant; - getIt.registerFactory(() => IoniaBuyGiftCardDetailPage()); + return IoniaBuyGiftCardPage(merchant); + }); + + getIt.registerFactoryParam((List args, _) { + final merchant = args.first as IoniaMerchant; + + return IoniaBuyGiftCardDetailPage(merchant); + }); getIt.registerFactory(() => IoniaManageCardsPage(getIt.get())); diff --git a/lib/router.dart b/lib/router.dart index 930424019..27ee24603 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -416,13 +416,15 @@ Route createRoute(RouteSettings settings) { return CupertinoPageRoute(builder: (_) => getIt.get()); case Routes.ioniaBuyGiftCardPage: - return CupertinoPageRoute(builder: (_) => getIt.get()); + final args = settings.arguments as List; + return CupertinoPageRoute(builder: (_) => getIt.get(param1: args)); case Routes.ioniaBuyGiftCardDetailPage: - return CupertinoPageRoute(builder: (_) => getIt.get()); + final args = settings.arguments as List; + return CupertinoPageRoute(builder: (_) => getIt.get(param1: args)); case Routes.ioniaVerifyIoniaOtpPage: - final args = settings.arguments as List; + final args = settings.arguments as List; return CupertinoPageRoute(builder: (_) =>getIt.get(param1: args)); case Routes.ioniaDebitCardPage: diff --git a/lib/src/screens/ionia/auth/ionia_welcome_page.dart b/lib/src/screens/ionia/auth/ionia_welcome_page.dart index 0c4abecab..66e89899b 100644 --- a/lib/src/screens/ionia/auth/ionia_welcome_page.dart +++ b/lib/src/screens/ionia/auth/ionia_welcome_page.dart @@ -30,7 +30,7 @@ class IoniaWelcomePage extends BasePage { Widget body(BuildContext context) { reaction((_) => _ioniaViewModel.isLoggedIn, (bool state) { if (state) { - Navigator.pushReplacementNamed(context, Routes.ioniaDebitCardPage); + Navigator.pushReplacementNamed(context, Routes.ioniaManageCardsPage); } }); return Padding( diff --git a/lib/src/screens/ionia/cards/ionia_buy_card_detail_page.dart b/lib/src/screens/ionia/cards/ionia_buy_card_detail_page.dart index 9f0fa1792..6d56ad362 100644 --- a/lib/src/screens/ionia/cards/ionia_buy_card_detail_page.dart +++ b/lib/src/screens/ionia/cards/ionia_buy_card_detail_page.dart @@ -1,8 +1,8 @@ import 'package:cake_wallet/di.dart'; +import 'package:cake_wallet/ionia/ionia_merchant.dart'; import 'package:cake_wallet/palette.dart'; import 'package:cake_wallet/src/screens/ionia/widgets/confirm_modal.dart'; import 'package:cake_wallet/src/screens/ionia/widgets/text_icon_button.dart'; -import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/widgets/discount_badge.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart'; import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; @@ -14,6 +14,11 @@ import 'package:flutter/material.dart'; import 'package:cake_wallet/generated/i18n.dart'; class IoniaBuyGiftCardDetailPage extends StatelessWidget { + + const IoniaBuyGiftCardDetailPage(this.merchant); + + final IoniaMerchant merchant; + ThemeBase get currentTheme => getIt.get().currentTheme; Color get backgroundLightColor => Colors.white; @@ -52,7 +57,7 @@ class IoniaBuyGiftCardDetailPage extends StatelessWidget { Widget middle(BuildContext context) { return Text( - 'AppleBees', + merchant.legalName, style: TextStyle( fontSize: 22, fontFamily: 'Lato', @@ -74,7 +79,7 @@ class IoniaBuyGiftCardDetailPage extends StatelessWidget { SizedBox(height: 60), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [leading(context), middle(context), DiscountBadge()], + children: [leading(context), middle(context), DiscountBadge(percentage: merchant.minimumDiscount,)], ), SizedBox(height: 36), Container( diff --git a/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart b/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart index 1677a9e77..e46b9ea0a 100644 --- a/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart +++ b/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart @@ -1,3 +1,4 @@ +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'; @@ -12,9 +13,12 @@ import 'package:keyboard_actions/keyboard_actions.dart'; import 'package:cake_wallet/generated/i18n.dart'; class IoniaBuyGiftCardPage extends BasePage { - IoniaBuyGiftCardPage() + IoniaBuyGiftCardPage(this.merchant) : _amountFieldFocus = FocusNode(), _amountController = TextEditingController(); + + final IoniaMerchant merchant; + @override String get title => S.current.enter_amount; @@ -93,7 +97,7 @@ class IoniaBuyGiftCardPage extends BasePage { left: _width / 4, ), child: Text( - 'USD: ', + '${merchant.acceptedCurrency}: ', style: TextStyle( color: Colors.white, fontWeight: FontWeight.w900, @@ -107,13 +111,13 @@ class IoniaBuyGiftCardPage extends BasePage { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - S.of(context).min_amount('5'), + S.of(context).min_amount(merchant.minimumCardPurchase.toString()), style: TextStyle( color: Theme.of(context).primaryTextTheme.headline.color, ), ), Text( - S.of(context).max_amount('20000'), + S.of(context).max_amount(merchant.maximumCardPurchase.toString()), style: TextStyle( color: Theme.of(context).primaryTextTheme.headline.color, ), @@ -127,11 +131,13 @@ class IoniaBuyGiftCardPage extends BasePage { Padding( padding: const EdgeInsets.all(24.0), child: CardItem( - onTap: () {}, - title: 'Applebee’s', - hasDiscount: true, - subTitle: 'subTitle', - logoUrl: '', + title: merchant.legalName, + backgroundColor: Theme.of(context).accentTextTheme.display4.backgroundColor.withOpacity(0.1), + discount: 0.0, + titleColor: Theme.of(context).accentTextTheme.display4.backgroundColor, + subtitleColor: Theme.of(context).hintColor, + subTitle: merchant.isOnline ? S.of(context).online : S.of(context).offline, + logoUrl: merchant.logoUrl, ), ) ], @@ -141,10 +147,10 @@ class IoniaBuyGiftCardPage extends BasePage { Padding( padding: EdgeInsets.only(bottom: 12), child: PrimaryButton( - onPressed: () => Navigator.of(context).pushNamed(Routes.ioniaBuyGiftCardDetailPage), + onPressed: () => Navigator.of(context).pushNamed(Routes.ioniaBuyGiftCardDetailPage, arguments: [merchant] ), text: S.of(context).continue_text, color: Theme.of(context).accentTextTheme.body2.color, - textColor: Colors.white, + textColor: Theme.of(context).primaryTextTheme.body1.color, ), ), SizedBox(height: 30), diff --git a/lib/src/screens/ionia/cards/ionia_manage_cards_page.dart b/lib/src/screens/ionia/cards/ionia_manage_cards_page.dart index 49276307d..a2f885774 100644 --- a/lib/src/screens/ionia/cards/ionia_manage_cards_page.dart +++ b/lib/src/screens/ionia/cards/ionia_manage_cards_page.dart @@ -8,6 +8,8 @@ import 'package:cake_wallet/view_model/ionia/ionia_view_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/generated/i18n.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:mobx/mobx.dart'; class IoniaManageCardsPage extends BasePage { IoniaManageCardsPage(this._ioniaViewModel); @@ -49,7 +51,7 @@ class IoniaManageCardsPage extends BasePage { Widget leading(BuildContext context) { final _backButton = Icon( Icons.arrow_back_ios, - color: titleColor ?? Theme.of(context).primaryTextTheme.title.color, + color: Theme.of(context).accentTextTheme.display3.backgroundColor, size: 16, ); @@ -141,27 +143,43 @@ class IoniaManageCardsPage extends BasePage { ), SizedBox(height: 8), Expanded( - child: RawScrollbar( - thumbColor: Colors.white.withOpacity(0.15), - radius: Radius.circular(20), - isAlwaysShown: true, - thickness: 2, - controller: _scrollController, - child: ListView.separated( - padding: EdgeInsets.only(left: 2, right: 22), - controller: _scrollController, - itemCount: 20, - separatorBuilder: (_, __) => SizedBox(height: 4), - itemBuilder: (_, index) { - return CardItem( - logoUrl: '', - onTap: () => Navigator.of(context).pushNamed(Routes.ioniaBuyGiftCardPage), - title: 'Amazon', - subTitle: 'Onlin', - hasDiscount: true, - ); - }, - ), + child: Observer( + builder: (_) { + final merchantsList = _ioniaViewModel.ioniaMerchants; + return RawScrollbar( + thumbColor: Colors.white.withOpacity(0.15), + radius: Radius.circular(20), + isAlwaysShown: true, + thickness: 2, + controller: _scrollController, + child: ListView.separated( + padding: EdgeInsets.only(left: 2, right: 22), + controller: _scrollController, + itemCount: merchantsList.length, + separatorBuilder: (_, __) => SizedBox(height: 4), + itemBuilder: (_, index) { + final merchant = merchantsList[index]; + return CardItem( + logoUrl: merchant.logoUrl, + onTap: () => Navigator.of(context).pushNamed(Routes.ioniaBuyGiftCardPage, + arguments: [merchant]), + title: merchant.legalName, + subTitle: merchant.isOnline ? S.of(context).online : S.of(context).offline, + backgroundColor: Theme.of(context).textTheme.title.backgroundColor, + titleColor: Theme.of(context) + .accentTextTheme + .display3 + .backgroundColor, + subtitleColor: Theme.of(context) + .accentTextTheme + .display2 + .backgroundColor, + discount: merchant.minimumDiscount, + ); + }, + ), + ); + } ), ), ], diff --git a/lib/src/screens/ionia/widgets/card_item.dart b/lib/src/screens/ionia/widgets/card_item.dart index 95bf9ee1e..38946da5a 100644 --- a/lib/src/screens/ionia/widgets/card_item.dart +++ b/lib/src/screens/ionia/widgets/card_item.dart @@ -1,22 +1,28 @@ -import 'package:cake_wallet/palette.dart'; import 'package:cake_wallet/src/widgets/discount_badge.dart'; import 'package:flutter/material.dart'; class CardItem extends StatelessWidget { CardItem({ - @required this.onTap, @required this.title, @required this.subTitle, + @required this.backgroundColor, + @required this.titleColor, + @required this.subtitleColor, + this.onTap, this.logoUrl, - this.hasDiscount = false, + this.discount, + }); final VoidCallback onTap; final String title; final String subTitle; final String logoUrl; - final bool hasDiscount; + final double discount; + final Color backgroundColor; + final Color titleColor; + final Color subtitleColor; @override Widget build(BuildContext context) { @@ -28,7 +34,7 @@ class CardItem extends StatelessWidget { padding: EdgeInsets.all(12), width: double.infinity, decoration: BoxDecoration( - color: Colors.black.withOpacity(0.1), + color: backgroundColor, borderRadius: BorderRadius.circular(20), border: Border.all( color: Colors.white.withOpacity(0.20), @@ -57,19 +63,23 @@ class CardItem extends StatelessWidget { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - title, - style: TextStyle( - color: Palette.stateGray, - fontSize: 24, - fontWeight: FontWeight.w900, + SizedBox( + width: 200, + child: Text( + title, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: titleColor, + fontSize: 20, + fontWeight: FontWeight.w900, + ), ), ), SizedBox(height: 5), Text( subTitle, style: TextStyle( - color: Palette.niagara , + color: subtitleColor, fontWeight: FontWeight.w500, fontFamily: 'Lato'), ) @@ -78,12 +88,12 @@ class CardItem extends StatelessWidget { ], ), ), - if (hasDiscount) + if (discount != 0.0) Align( alignment: Alignment.topRight, child: Padding( padding: const EdgeInsets.only(top: 20.0), - child: DiscountBadge(), + child: DiscountBadge(percentage: discount), ), ), ], diff --git a/lib/src/widgets/discount_badge.dart b/lib/src/widgets/discount_badge.dart index ad9c4e2ce..c3f9e2148 100644 --- a/lib/src/widgets/discount_badge.dart +++ b/lib/src/widgets/discount_badge.dart @@ -5,8 +5,11 @@ import 'package:cake_wallet/generated/i18n.dart'; class DiscountBadge extends StatelessWidget { const DiscountBadge({ Key key, + @required this.percentage, }) : super(key: key); + final double percentage; + @override Widget build(BuildContext context) { return Stack( @@ -16,7 +19,7 @@ class DiscountBadge extends StatelessWidget { Padding( padding: const EdgeInsets.only(right: 10.0), child: Text( - S.of(context).discount('20'), + S.of(context).discount(percentage.toString()), style: TextStyle( color: Colors.white, fontSize: 12, diff --git a/lib/view_model/ionia/ionia_view_model.dart b/lib/view_model/ionia/ionia_view_model.dart index b07c42440..2f8c54e21 100644 --- a/lib/view_model/ionia/ionia_view_model.dart +++ b/lib/view_model/ionia/ionia_view_model.dart @@ -1,5 +1,7 @@ import 'package:cake_wallet/ionia/ionia_service.dart'; import 'package:cake_wallet/ionia/ionia_create_state.dart'; +import 'package:cake_wallet/ionia/ionia_merchant.dart'; +import 'package:cake_wallet/ionia/ionia_merchant_service.dart'; import 'package:cake_wallet/ionia/ionia_virtual_card.dart'; import 'package:mobx/mobx.dart'; part 'ionia_view_model.g.dart'; @@ -7,14 +9,19 @@ part 'ionia_view_model.g.dart'; class IoniaViewModel = IoniaViewModelBase with _$IoniaViewModel; abstract class IoniaViewModelBase with Store { - IoniaViewModelBase({this.ioniaService}) + + IoniaViewModelBase({this.ioniaService, this.ioniaMerchantService}) : createUserState = IoniaCreateStateSuccess(), otpState = IoniaOtpSendDisabled(), - cardState = IoniaNoCardState() { - _getCard(); + cardState = IoniaNoCardState(), ioniaMerchants = [] { + _getMerchants().then((value){ + ioniaMerchants = value; + }); _getAuthStatus().then((value) => isLoggedIn = value); } + final IoniaMerchantService ioniaMerchantService; + final IoniaService ioniaService; @observable @@ -29,6 +36,9 @@ abstract class IoniaViewModelBase with Store { @observable IoniaFetchCardState cardState; + @observable + List ioniaMerchants; + @observable String email; @@ -88,4 +98,8 @@ abstract class IoniaViewModelBase with Store { cardState = IoniaFetchCardFailure(); } } + + Future> _getMerchants()async{ + return await ioniaMerchantService.getMerchants(); + } } diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index 7f85e3eb4..c5cf06877 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -594,5 +594,7 @@ "by_cake_pay": "by CakePay", "expires": "Expires", "mm": "MM", - "yy": "YY" + "yy": "YY", + "online": "Online", + "offline": "Offline" }