CakeWallet/lib/src/screens/dashboard/dashboard_page.dart

329 lines
12 KiB
Dart
Raw Normal View History

2021-11-02 09:17:24 +00:00
import 'dart:async';
Ionia (#437) * Initial ionia service * Ionia manage card UI (#374) * design ui for cakepay * Add manage cards page ui * create auth ui for ionia * add authentication logic * implement user create card * Add ionia merchant sevic * Add anypay. Add purschase gift card. * display virtual card (#385) * display virtual card * fix formatting * Remove IoniaMerchantService from IoniaViewModel * Add hex and txKey for monero pending transaction. * Changed monero version and monero repo to cake tech. * Add anypay payment. Add filter by search for ionia, add get purchased items for ionia. * Fix for get transactions for hidden addresses for electrum wallet * Add ionia categories. * Add anypay commited info for payments. * Update UI with new fixes (#400) * Change ionia base url. Add exception throwing for error messaging for some of ionia calls. * CW-102 fix logic for ionia issues (#403) * refactor tips (#406) * refactor tips * refactor ionia tips implementation * Cw 115 implement gift cards list for ionia (#405) * Implement show purchased cards * fix padding * Fixes for getting of purchased gift cards. * Implement gift card details screen (#408) * Implement gift card details screen * Add redeem for ionia gift cards * Fix navigation after ionia opt redirection. * Fix update gift cards list. * Add payment status update for ionia. * Add usage instruction to gift card. * Add copy for ionia gift card info. * Change version for Cake Wallet ios. * Add localisation (#414) * Fixes for fiat amounts for ionia. * CW-128 marketplace screen text changes (#416) * Change text on marketplace * fix build issues * fix build * UI fixes for ionia. * UI fixes for ionia. (#421) * CW-129 ionia welcome screen text changes (#418) * update welcome text * Update localization * Cw 133 (#422) * UI fixes for ionia. * Fixes for display card item on gift cards screen. * Fix signup page (#419) * Changed tips for ionia. * Cw 132 (#425) * UI fixes for ionia. * Changed tips for ionia. * Cw 131 (#426) * UI fixes for ionia. * Changed tips for ionia. * Fixes for IoniaBuyGiftCardDetailPage screen. Renamed 'Manage Cards' to 'Gift Cards'. Hide discount badge label for 0 discount. * Change ionia heading font style (#427) * Fix for AddressResolver in di * Changed build number for Cake Wallet ios. * fix currency format for card details and routing for mark as redeemed (#431) * fix terms and condition overflow in ionia (#430) * fix terms and condition scroll * fix color issues * reuse * refactor widget * Remove IoniaTokenService * Change api for ionia to staging * Update versions for Cake Wallet for android and ios. * Fixes for instructions. Remove diplay error on payment status screen. * Change build versions for Cake Wallet * Add ionia sign in. * Update for discounts and statuses for ionia merch. * Fixes for qr/barcode on ionia gift card screen. * Fixed formatting for display ionia discounts. * Fix merchant.discount.toStringAsFixed issue * Add savingsPercentage to ionia merch discount. * Change build number for Cake Wallet ios and android. * Disable ionia for haven (#440) Co-authored-by: Godwin Asuquo <41484542+godilite@users.noreply.github.com>
2022-07-28 18:03:16 +01:00
import 'package:cake_wallet/src/screens/dashboard/widgets/market_place_page.dart';
import 'package:cake_wallet/wallet_type_utils.dart';
2021-12-24 14:37:24 +02:00
import 'package:cw_core/wallet_type.dart';
2020-07-06 23:09:03 +03:00
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/routes.dart';
2021-11-02 09:17:24 +00:00
import 'package:cake_wallet/src/screens/yat_emoji_id.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
2020-01-04 21:31:52 +02:00
import 'package:flutter/material.dart';
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
2020-07-06 23:09:03 +03:00
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/menu_widget.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/action_button.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/balance_page.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/transactions_page.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mobx/mobx.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
2021-11-02 09:17:24 +00:00
import 'package:cake_wallet/main.dart';
2021-12-08 12:46:01 +00:00
import 'package:cake_wallet/buy/moonpay/moonpay_buy_provider.dart';
import 'package:url_launcher/url_launcher.dart';
2020-01-04 21:31:52 +02:00
2020-07-06 23:09:03 +03:00
class DashboardPage extends BasePage {
DashboardPage({
2022-10-12 13:09:57 -04:00
required this.balancePage,
required this.walletViewModel,
required this.addressListViewModel,
});
final BalancePage balancePage;
2020-04-14 21:15:47 +03:00
@override
Color get backgroundLightColor =>
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
2020-01-04 21:31:52 +02:00
@override
Color get backgroundDarkColor => Colors.transparent;
@override
Widget Function(BuildContext, Widget) get rootWrapper =>
2020-09-01 14:18:07 +03:00
(BuildContext context, Widget scaffold) => Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
2020-09-01 14:18:07 +03:00
Theme.of(context).accentColor,
Theme.of(context).scaffoldBackgroundColor,
Theme.of(context).primaryColor,
], begin: Alignment.topRight, end: Alignment.bottomLeft)),
child: scaffold);
2020-01-04 21:31:52 +02:00
@override
bool get resizeToAvoidBottomInset => false;
@override
2020-09-01 14:18:07 +03:00
Widget get endDrawer => MenuWidget(walletViewModel);
@override
Widget middle(BuildContext context) {
return SyncIndicator(dashboardViewModel: walletViewModel,
onTap: () => Navigator.of(context, rootNavigator: true)
.pushNamed(Routes.connectionSync));
}
2020-01-04 21:31:52 +02:00
@override
2020-07-06 23:09:03 +03:00
Widget trailing(BuildContext context) {
final menuButton = Image.asset('assets/images/menu.png',
2022-10-12 13:09:57 -04:00
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!);
2020-07-06 23:09:03 +03:00
return Container(
2020-09-01 14:18:07 +03:00
alignment: Alignment.centerRight,
width: 40,
2022-10-12 13:09:57 -04:00
child: TextButton(
// FIX-ME: Style
//highlightColor: Colors.transparent,
//splashColor: Colors.transparent,
//padding: EdgeInsets.all(0),
2020-09-01 14:18:07 +03:00
onPressed: () => onOpenEndDrawer(),
child: menuButton));
2020-07-06 23:09:03 +03:00
}
2020-04-14 21:15:47 +03:00
2020-07-06 23:09:03 +03:00
final DashboardViewModel walletViewModel;
final WalletAddressListViewModel addressListViewModel;
Ionia (#437) * Initial ionia service * Ionia manage card UI (#374) * design ui for cakepay * Add manage cards page ui * create auth ui for ionia * add authentication logic * implement user create card * Add ionia merchant sevic * Add anypay. Add purschase gift card. * display virtual card (#385) * display virtual card * fix formatting * Remove IoniaMerchantService from IoniaViewModel * Add hex and txKey for monero pending transaction. * Changed monero version and monero repo to cake tech. * Add anypay payment. Add filter by search for ionia, add get purchased items for ionia. * Fix for get transactions for hidden addresses for electrum wallet * Add ionia categories. * Add anypay commited info for payments. * Update UI with new fixes (#400) * Change ionia base url. Add exception throwing for error messaging for some of ionia calls. * CW-102 fix logic for ionia issues (#403) * refactor tips (#406) * refactor tips * refactor ionia tips implementation * Cw 115 implement gift cards list for ionia (#405) * Implement show purchased cards * fix padding * Fixes for getting of purchased gift cards. * Implement gift card details screen (#408) * Implement gift card details screen * Add redeem for ionia gift cards * Fix navigation after ionia opt redirection. * Fix update gift cards list. * Add payment status update for ionia. * Add usage instruction to gift card. * Add copy for ionia gift card info. * Change version for Cake Wallet ios. * Add localisation (#414) * Fixes for fiat amounts for ionia. * CW-128 marketplace screen text changes (#416) * Change text on marketplace * fix build issues * fix build * UI fixes for ionia. * UI fixes for ionia. (#421) * CW-129 ionia welcome screen text changes (#418) * update welcome text * Update localization * Cw 133 (#422) * UI fixes for ionia. * Fixes for display card item on gift cards screen. * Fix signup page (#419) * Changed tips for ionia. * Cw 132 (#425) * UI fixes for ionia. * Changed tips for ionia. * Cw 131 (#426) * UI fixes for ionia. * Changed tips for ionia. * Fixes for IoniaBuyGiftCardDetailPage screen. Renamed 'Manage Cards' to 'Gift Cards'. Hide discount badge label for 0 discount. * Change ionia heading font style (#427) * Fix for AddressResolver in di * Changed build number for Cake Wallet ios. * fix currency format for card details and routing for mark as redeemed (#431) * fix terms and condition overflow in ionia (#430) * fix terms and condition scroll * fix color issues * reuse * refactor widget * Remove IoniaTokenService * Change api for ionia to staging * Update versions for Cake Wallet for android and ios. * Fixes for instructions. Remove diplay error on payment status screen. * Change build versions for Cake Wallet * Add ionia sign in. * Update for discounts and statuses for ionia merch. * Fixes for qr/barcode on ionia gift card screen. * Fixed formatting for display ionia discounts. * Fix merchant.discount.toStringAsFixed issue * Add savingsPercentage to ionia merch discount. * Change build number for Cake Wallet ios and android. * Disable ionia for haven (#440) Co-authored-by: Godwin Asuquo <41484542+godilite@users.noreply.github.com>
2022-07-28 18:03:16 +01:00
final controller = PageController(initialPage: 1);
var pages = <Widget>[];
bool _isEffectsInstalled = false;
2022-10-12 13:09:57 -04:00
StreamSubscription<bool>? _onInactiveSub;
2020-07-06 23:09:03 +03:00
@override
Widget body(BuildContext context) {
final sendImage = Image.asset('assets/images/upload.png',
height: 24,
width: 24,
2022-10-12 13:09:57 -04:00
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!);
final receiveImage = Image.asset('assets/images/received.png',
height: 24,
width: 24,
2022-10-12 13:09:57 -04:00
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!);
_setEffects(context);
return SafeArea(
2022-03-30 17:57:04 +02:00
minimum: EdgeInsets.only(bottom: 24),
2020-09-01 14:18:07 +03:00
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: PageView.builder(
2020-09-01 14:18:07 +03:00
controller: controller,
itemCount: pages.length,
2020-09-09 17:13:44 +03:00
itemBuilder: (context, index) => pages[index])),
2020-09-01 14:18:07 +03:00
Padding(
2022-03-30 17:57:04 +02:00
padding: EdgeInsets.only(bottom: 24, top: 10),
child: SmoothPageIndicator(
controller: controller,
2020-09-01 14:18:07 +03:00
count: pages.length,
effect: ColorTransitionEffect(
2020-09-01 14:18:07 +03:00
spacing: 6.0,
radius: 6.0,
dotWidth: 6.0,
dotHeight: 6.0,
dotColor: Theme.of(context).indicatorColor,
activeDotColor: Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline4!
.backgroundColor!),
2020-09-01 14:18:07 +03:00
)),
2022-03-30 17:57:04 +02:00
Observer(builder: (_) {
return ClipRect(
child:Container(
margin: const EdgeInsets.only(left: 16, right: 16),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0),
border: Border.all(color: currentTheme.type == ThemeType.bright ? Color.fromRGBO(255, 255, 255, 0.2): Colors.transparent, width: 1, ),
2022-10-12 13:09:57 -04:00
color:Theme.of(context).textTheme!.headline6!.backgroundColor!),
2022-03-30 17:57:04 +02:00
child: Container(
padding: EdgeInsets.only(left: 32, right: 32),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
if (walletViewModel.hasBuyAction)
ActionButton(
image: Image.asset('assets/images/buy.png',
height: 24,
width: 24,
color: !walletViewModel.isEnabledBuyAction
? Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline3!
.backgroundColor!
: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!),
2022-03-30 17:57:04 +02:00
title: S.of(context).buy,
onClick: () async => await _onClickBuyButton(context),
textColor: !walletViewModel.isEnabledBuyAction
? Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline3!
.backgroundColor!
2022-03-30 17:57:04 +02:00
: null),
ActionButton(
2022-03-30 17:57:04 +02:00
image: receiveImage,
title: S.of(context).receive,
route: Routes.addressPage),
if (walletViewModel.hasExchangeAction)
ActionButton(
image: Image.asset('assets/images/transfer.png',
height: 24,
width: 24,
color: !walletViewModel.isEnabledExchangeAction
? Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline3!
.backgroundColor!
: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!),
2022-03-30 17:57:04 +02:00
title: S.of(context).exchange,
onClick: () async => _onClickExchangeButton(context),
textColor: !walletViewModel.isEnabledExchangeAction
? Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline3!
.backgroundColor!
2022-03-30 17:57:04 +02:00
: null),
ActionButton(
2022-03-30 17:57:04 +02:00
image: sendImage,
title: S.of(context).send,
route: Routes.send),
if (walletViewModel.hasSellAction)
ActionButton(
image: Image.asset('assets/images/sell.png',
height: 24,
width: 24,
color: !walletViewModel.isEnabledSellAction
? Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline3!
.backgroundColor!
: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!),
2022-03-30 17:57:04 +02:00
title: S.of(context).sell,
onClick: () async => await _onClickSellButton(context),
textColor: !walletViewModel.isEnabledSellAction
? Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline3!
.backgroundColor!
2022-03-30 17:57:04 +02:00
: null),
],
),),
),),);
}),
2020-09-01 14:18:07 +03:00
],
));
2020-07-06 23:09:03 +03:00
}
void _setEffects(BuildContext context) async {
if (_isEffectsInstalled) {
return;
}
Ionia (#437) * Initial ionia service * Ionia manage card UI (#374) * design ui for cakepay * Add manage cards page ui * create auth ui for ionia * add authentication logic * implement user create card * Add ionia merchant sevic * Add anypay. Add purschase gift card. * display virtual card (#385) * display virtual card * fix formatting * Remove IoniaMerchantService from IoniaViewModel * Add hex and txKey for monero pending transaction. * Changed monero version and monero repo to cake tech. * Add anypay payment. Add filter by search for ionia, add get purchased items for ionia. * Fix for get transactions for hidden addresses for electrum wallet * Add ionia categories. * Add anypay commited info for payments. * Update UI with new fixes (#400) * Change ionia base url. Add exception throwing for error messaging for some of ionia calls. * CW-102 fix logic for ionia issues (#403) * refactor tips (#406) * refactor tips * refactor ionia tips implementation * Cw 115 implement gift cards list for ionia (#405) * Implement show purchased cards * fix padding * Fixes for getting of purchased gift cards. * Implement gift card details screen (#408) * Implement gift card details screen * Add redeem for ionia gift cards * Fix navigation after ionia opt redirection. * Fix update gift cards list. * Add payment status update for ionia. * Add usage instruction to gift card. * Add copy for ionia gift card info. * Change version for Cake Wallet ios. * Add localisation (#414) * Fixes for fiat amounts for ionia. * CW-128 marketplace screen text changes (#416) * Change text on marketplace * fix build issues * fix build * UI fixes for ionia. * UI fixes for ionia. (#421) * CW-129 ionia welcome screen text changes (#418) * update welcome text * Update localization * Cw 133 (#422) * UI fixes for ionia. * Fixes for display card item on gift cards screen. * Fix signup page (#419) * Changed tips for ionia. * Cw 132 (#425) * UI fixes for ionia. * Changed tips for ionia. * Cw 131 (#426) * UI fixes for ionia. * Changed tips for ionia. * Fixes for IoniaBuyGiftCardDetailPage screen. Renamed 'Manage Cards' to 'Gift Cards'. Hide discount badge label for 0 discount. * Change ionia heading font style (#427) * Fix for AddressResolver in di * Changed build number for Cake Wallet ios. * fix currency format for card details and routing for mark as redeemed (#431) * fix terms and condition overflow in ionia (#430) * fix terms and condition scroll * fix color issues * reuse * refactor widget * Remove IoniaTokenService * Change api for ionia to staging * Update versions for Cake Wallet for android and ios. * Fixes for instructions. Remove diplay error on payment status screen. * Change build versions for Cake Wallet * Add ionia sign in. * Update for discounts and statuses for ionia merch. * Fixes for qr/barcode on ionia gift card screen. * Fixed formatting for display ionia discounts. * Fix merchant.discount.toStringAsFixed issue * Add savingsPercentage to ionia merch discount. * Change build number for Cake Wallet ios and android. * Disable ionia for haven (#440) Co-authored-by: Godwin Asuquo <41484542+godilite@users.noreply.github.com>
2022-07-28 18:03:16 +01:00
pages.add(MarketPlacePage(dashboardViewModel: walletViewModel));
pages.add(balancePage);
pages.add(TransactionsPage(dashboardViewModel: walletViewModel));
2021-11-02 09:17:24 +00:00
_isEffectsInstalled = true;
2022-01-14 00:10:27 +06:00
autorun((_) async {
if (!walletViewModel.isOutdatedElectrumWallet) {
return;
}
await Future<void>.delayed(Duration(seconds: 1));
if (context.mounted) {
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: S.of(context).pre_seed_title,
alertContent:
S.of(context).outdated_electrum_wallet_description,
buttonText: S.of(context).understand,
buttonAction: () => Navigator.of(context).pop());
});
}
});
2021-11-02 09:17:24 +00:00
var needToPresentYat = false;
var isInactive = false;
2022-10-12 13:09:57 -04:00
_onInactiveSub = rootKey.currentState!.isInactive.listen((inactive) {
2021-11-02 09:17:24 +00:00
isInactive = inactive;
if (needToPresentYat) {
Future<void>.delayed(Duration(milliseconds: 500)).then((_) {
showPopUp<void>(
2022-10-12 13:09:57 -04:00
context: navigatorKey.currentContext!,
2022-01-14 00:10:27 +06:00
builder: (_) => YatEmojiId(walletViewModel.yatStore.emoji));
2021-11-02 09:17:24 +00:00
needToPresentYat = false;
});
}
});
walletViewModel.yatStore.emojiIncommingStream.listen((String emoji) {
if (!_isEffectsInstalled || emoji.isEmpty) {
return;
}
needToPresentYat = true;
});
}
Future<void> _onClickBuyButton(BuildContext context) async {
final walletType = walletViewModel.type;
switch (walletType) {
2021-12-08 11:09:38 +00:00
case WalletType.bitcoin:
Navigator.of(context).pushNamed(Routes.onramperPage);
2021-12-08 11:09:38 +00:00
break;
case WalletType.litecoin:
Navigator.of(context).pushNamed(Routes.onramperPage);
2021-12-08 11:09:38 +00:00
break;
case WalletType.monero:
Navigator.of(context).pushNamed(Routes.payfuraPage);
break;
2021-12-08 11:09:38 +00:00
default:
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: S.of(context).buy,
alertContent: S.of(context).buy_alert_content,
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
2021-12-08 11:09:38 +00:00
}
}
Future<void> _onClickSellButton(BuildContext context) async {
final walletType = walletViewModel.type;
switch (walletType) {
case WalletType.bitcoin:
2021-12-08 12:46:01 +00:00
final moonPaySellProvider = MoonPaySellProvider();
final uri = await moonPaySellProvider.requestUrl(
2022-01-14 00:10:27 +06:00
currency: walletViewModel.wallet.currency,
refundWalletAddress:
walletViewModel.wallet.walletAddresses.address);
2021-12-08 12:46:01 +00:00
await launch(uri);
break;
2021-12-08 11:09:38 +00:00
default:
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
2022-01-14 00:10:27 +06:00
alertTitle: S.of(context).sell,
alertContent: isMoneroOnly ? S.of(context).sell_monero_com_alert_content
: S.of(context).sell_alert_content,
2021-12-08 11:09:38 +00:00
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
}
}
2022-03-30 17:57:04 +02:00
Future<void> _onClickExchangeButton(BuildContext context) async {
if (walletViewModel.isEnabledExchangeAction) {
await Navigator.of(context).pushNamed(Routes.exchange);
}
2022-03-30 17:57:04 +02:00
}
}