From 3fa099775404b688216a0e834943a099134fffed Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 12 Sep 2023 16:59:07 -0600 Subject: [PATCH] WIP: tor enabled dialog on buy view --- lib/pages/buy_view/buy_view.dart | 72 ++++++-- .../desktop_buy/desktop_buy_view.dart | 163 ++++++++++++------ 2 files changed, 170 insertions(+), 65 deletions(-) diff --git a/lib/pages/buy_view/buy_view.dart b/lib/pages/buy_view/buy_view.dart index 3d5fe1539..beeece754 100644 --- a/lib/pages/buy_view/buy_view.dart +++ b/lib/pages/buy_view/buy_view.dart @@ -9,38 +9,82 @@ */ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart'; import 'package:stackwallet/pages/buy_view/buy_form.dart'; +import 'package:stackwallet/providers/global/prefs_provider.dart'; +import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/widgets/stack_dialog.dart'; -class BuyView extends StatelessWidget { +class BuyView extends ConsumerStatefulWidget { const BuyView({ Key? key, this.coin, this.tokenContract, }) : super(key: key); - static const String routeName = "/stackBuyView"; - final Coin? coin; final EthContract? tokenContract; + static const String routeName = "/stackBuyView"; + + @override + ConsumerState createState() => _BuyViewState(); +} + +class _BuyViewState extends ConsumerState { + Coin? coin; + EthContract? tokenContract; + late bool torEnabled = false; + + @override + void initState() { + coin = widget.coin; + tokenContract = widget.tokenContract; + + WidgetsBinding.instance.addPostFrameCallback((_) async { + setState(() { + torEnabled = ref.read(prefsChangeNotifierProvider).useTor; + }); + }); + + super.initState(); + } + @override Widget build(BuildContext context) { debugPrint("BUILD: $runtimeType"); - return SafeArea( - child: Padding( - padding: const EdgeInsets.only( - left: 16, - right: 16, - top: 16, + return Stack( + children: [ + SafeArea( + child: Padding( + padding: const EdgeInsets.only( + left: 16, + right: 16, + top: 16, + ), + child: BuyForm( + coin: coin, + tokenContract: tokenContract, + ), + ), ), - child: BuyForm( - coin: coin, - tokenContract: tokenContract, - ), - ), + if (torEnabled) + Container( + color: Theme.of(context) + .extension()! + .overlay + .withOpacity(0.7), + height: MediaQuery.of(context).size.height, + width: MediaQuery.of(context).size.width, + child: const StackDialog( + title: "Tor is enabled", + message: "Purchasing not available while Tor is enabled", + ), + ), + ], ); } } diff --git a/lib/pages_desktop_specific/desktop_buy/desktop_buy_view.dart b/lib/pages_desktop_specific/desktop_buy/desktop_buy_view.dart index e56d2644c..8827641fa 100644 --- a/lib/pages_desktop_specific/desktop_buy/desktop_buy_view.dart +++ b/lib/pages_desktop_specific/desktop_buy/desktop_buy_view.dart @@ -9,76 +9,137 @@ */ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/pages/buy_view/buy_form.dart'; +import 'package:stackwallet/providers/global/prefs_provider.dart'; +import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart'; +import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; -class DesktopBuyView extends StatefulWidget { +class DesktopBuyView extends ConsumerStatefulWidget { const DesktopBuyView({Key? key}) : super(key: key); static const String routeName = "/desktopBuyView"; @override - State createState() => _DesktopBuyViewState(); + ConsumerState createState() => _DesktopBuyViewState(); } -class _DesktopBuyViewState extends State { +class _DesktopBuyViewState extends ConsumerState { + late bool torEnabled = false; + + @override + void initState() { + WidgetsBinding.instance.addPostFrameCallback((_) async { + setState(() { + torEnabled = ref.read(prefsChangeNotifierProvider).useTor; + }); + }); + super.initState(); + } + @override Widget build(BuildContext context) { - return DesktopScaffold( - appBar: DesktopAppBar( - isCompactHeight: true, - leading: Padding( - padding: const EdgeInsets.only( - left: 24, - ), - child: Text( - "Buy crypto", - style: STextStyles.desktopH3(context), - ), - ), - ), - body: Padding( - padding: const EdgeInsets.only( - left: 24, - right: 24, - bottom: 24, - ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: const [ - SizedBox( - height: 16, - ), - RoundedWhiteContainer( - padding: EdgeInsets.all(24), - child: BuyForm(), - ), - ], + return Stack( + children: [ + DesktopScaffold( + appBar: DesktopAppBar( + isCompactHeight: true, + leading: Padding( + padding: const EdgeInsets.only( + left: 24, + ), + child: Text( + "Buy crypto", + style: STextStyles.desktopH3(context), ), ), - const SizedBox( - width: 16, + ), + body: Padding( + padding: const EdgeInsets.only( + left: 24, + right: 24, + bottom: 24, ), - // Expanded( - // child: Row( - // children: const [ - // Expanded( - // child: DesktopTradeHistory(), - // ), - // ], - // ), - // ), - ], + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: const [ + SizedBox( + height: 16, + ), + RoundedWhiteContainer( + padding: EdgeInsets.all(24), + child: BuyForm(), + ), + ], + ), + ), + const SizedBox( + width: 16, + ), + // Expanded( + // child: Row( + // children: const [ + // Expanded( + // child: DesktopTradeHistory(), + // ), + // ], + // ), + // ), + ], + ), + ), ), - ), + if (torEnabled) + Container( + color: Theme.of(context) + .extension()! + .overlay + .withOpacity(0.7), + height: MediaQuery.of(context).size.height, + width: MediaQuery.of(context).size.width, + child: DesktopDialog( + maxHeight: 200, + maxWidth: 350, + child: Padding( + padding: const EdgeInsets.all( + 15.0, + ), + child: Column( + // crossAxisAlignment: CrossAxisAlignment.center, + // mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Tor is enabled", + textAlign: TextAlign.center, + style: STextStyles.pageTitleH1(context), + ), + const SizedBox( + height: 30, + ), + Text( + "Purchasing not available while Tor is enabled", + textAlign: TextAlign.center, + style: STextStyles.desktopTextMedium(context).copyWith( + color: Theme.of(context) + .extension()! + .infoItemLabel, + ), + ), + ], + ), + ), + ), + ), + ], ); } }