From fb39e96308acfd452119737cd7a3b6a42f895b51 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Fri, 21 Jul 2023 17:56:01 -0600 Subject: [PATCH 01/26] WIP: monkey view + fetching monkey dialog --- lib/pages/monkey/monkey_view.dart | 127 ++++++++++++++++ .../sub_widgets/fetch_monkey_dialog.dart | 135 ++++++++++++++++++ lib/pages/wallet_view/wallet_view.dart | 25 ++++ lib/route_generator.dart | 16 +++ 4 files changed, 303 insertions(+) create mode 100644 lib/pages/monkey/monkey_view.dart create mode 100644 lib/pages/monkey/sub_widgets/fetch_monkey_dialog.dart diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart new file mode 100644 index 000000000..e74d5bbdf --- /dev/null +++ b/lib/pages/monkey/monkey_view.dart @@ -0,0 +1,127 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; +import 'package:stackwallet/services/coins/manager.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; +import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/widgets/background.dart'; +import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; +import 'package:stackwallet/widgets/desktop/primary_button.dart'; + +class MonkeyView extends ConsumerStatefulWidget { + const MonkeyView({ + Key? key, + required this.walletId, + required this.managerProvider, + }) : super(key: key); + + static const String routeName = "/monkey"; + static const double navBarHeight = 65.0; + + final String walletId; + final ChangeNotifierProvider managerProvider; + + @override + ConsumerState createState() => _MonkeyViewState(); +} + +class _MonkeyViewState extends ConsumerState { + late final String walletId; + late final ChangeNotifierProvider managerProvider; + + @override + void initState() { + walletId = widget.walletId; + managerProvider = widget.managerProvider; + + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); + + return Background( + child: Stack( + children: [ + Scaffold( + appBar: AppBar( + leading: AppBarBackButton( + onPressed: () { + Navigator.of(context).pop(); + }, + ), + title: Text( + "MonKey", + style: STextStyles.navBarTitle(context), + ), + ), + body: Column( + // mainAxisAlignment: MainAxisAlignment.center, + // crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Spacer(), + Center( + child: Column( + children: [ + SvgPicture.file( + File( + ref.watch(coinIconProvider(coin)), + ), + width: 164, + height: 164, + ), + const SizedBox( + height: 40, + ), + Text( + "You do not have a MonKey yet. \nFetch yours now!", + style: STextStyles.smallMed14(context).copyWith( + color: Theme.of(context) + .extension()! + .textDark3, + ), + textAlign: TextAlign.center, + ), + ], + ), + ), + const Spacer(), + Padding( + padding: const EdgeInsets.all(16.0), + child: PrimaryButton( + label: "Fetch MonKey", + onPressed: () { + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: false, + builder: (context) { + return FetchMonkeyDialog( + onCancel: () async { + Navigator.of(context).pop(); + }, + ); + }, + ); + }, + ), + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/lib/pages/monkey/sub_widgets/fetch_monkey_dialog.dart b/lib/pages/monkey/sub_widgets/fetch_monkey_dialog.dart new file mode 100644 index 000000000..94034fb78 --- /dev/null +++ b/lib/pages/monkey/sub_widgets/fetch_monkey_dialog.dart @@ -0,0 +1,135 @@ +/* + * This file is part of Stack Wallet. + * + * Copyright (c) 2023 Cypher Stack + * All Rights Reserved. + * The code is distributed under GPLv3 license, see LICENSE file for details. + * Generated by Cypher Stack on 2023-05-26 + * + */ + +import 'package:flutter/material.dart'; +import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/animated_widgets/rotating_arrows.dart'; +import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; +import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; +import 'package:stackwallet/widgets/desktop/secondary_button.dart'; +import 'package:stackwallet/widgets/stack_dialog.dart'; + +class FetchMonkeyDialog extends StatefulWidget { + const FetchMonkeyDialog({ + Key? key, + required this.onCancel, + }) : super(key: key); + + final Future Function() onCancel; + + @override + State createState() => _FetchMonkeyDialogState(); +} + +class _FetchMonkeyDialogState extends State { + late final Future Function() onCancel; + @override + void initState() { + onCancel = widget.onCancel; + + super.initState(); + } + + @override + Widget build(BuildContext context) { + if (Util.isDesktop) { + return DesktopDialog( + child: Column( + children: [ + DesktopDialogCloseButton( + onPressedOverride: () async { + await onCancel.call(); + if (mounted) { + Navigator.of(context).pop(); + } + }, + ), + const Spacer( + flex: 1, + ), + const RotatingArrows( + width: 40, + height: 40, + ), + const Spacer( + flex: 2, + ), + Text( + "Fetching MonKey", + style: STextStyles.desktopH2(context), + textAlign: TextAlign.center, + ), + const SizedBox( + height: 16, + ), + Text( + "We are fetching your MonKey", + style: STextStyles.desktopTextMedium(context).copyWith( + color: Theme.of(context).extension()!.textDark3, + ), + textAlign: TextAlign.center, + ), + const Spacer( + flex: 2, + ), + Padding( + padding: const EdgeInsets.only( + left: 32, + right: 32, + bottom: 32, + ), + child: SecondaryButton( + label: "Cancel", + width: 272.5, + onPressed: () async { + await onCancel.call(); + if (mounted) { + Navigator.of(context).pop(); + } + }, + ), + ), + ], + ), + ); + } else { + return WillPopScope( + onWillPop: () async { + return false; + }, + child: StackDialog( + title: "Fetching MonKey", + message: "We are fetching your MonKey", + icon: const RotatingArrows( + width: 24, + height: 24, + ), + rightButton: TextButton( + style: Theme.of(context) + .extension()! + .getSecondaryEnabledButtonStyle(context), + child: Text( + "Cancel", + style: STextStyles.itemSubtitle12(context), + ), + onPressed: () async { + await onCancel.call(); + if (mounted) { + Navigator.of(context).pop(); + } + }, + ), + ), + ); + } + } +} diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index 3e7fb37fa..bd1c10b3c 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -22,6 +22,7 @@ import 'package:stackwallet/pages/buy_view/buy_in_wallet_view.dart'; import 'package:stackwallet/pages/coin_control/coin_control_view.dart'; import 'package:stackwallet/pages/exchange_view/wallet_initiated_exchange_view.dart'; import 'package:stackwallet/pages/home_view/home_view.dart'; +import 'package:stackwallet/pages/monkey/monkey_view.dart'; import 'package:stackwallet/pages/notification_views/notifications_view.dart'; import 'package:stackwallet/pages/paynym/paynym_claim_view.dart'; import 'package:stackwallet/pages/paynym/paynym_home_view.dart'; @@ -924,6 +925,30 @@ class _WalletViewState extends ConsumerState { ); }, ), + if (ref.watch( + walletsChangeNotifierProvider.select( + (value) => value + .getManager(widget.walletId) + .hasCoinControlSupport, + ), + ) && + ref.watch( + prefsChangeNotifierProvider.select( + (value) => value.enableCoinControl, + ), + )) + WalletNavigationBarItemData( + icon: SvgPicture.asset(Assets.svg.circlePlus), + label: "MonKey", + onTap: () { + Navigator.of(context).pushNamed( + MonkeyView.routeName, + arguments: Tuple2( + widget.walletId, + widget.managerProvider, + ), + ); + }), if (ref.watch( walletsChangeNotifierProvider.select( (value) => value diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 7ccc378c9..4513fd1d6 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -56,6 +56,7 @@ import 'package:stackwallet/pages/generic/single_field_edit_view.dart'; import 'package:stackwallet/pages/home_view/home_view.dart'; import 'package:stackwallet/pages/intro_view.dart'; import 'package:stackwallet/pages/manage_favorites_view/manage_favorites_view.dart'; +import 'package:stackwallet/pages/monkey/monkey_view.dart'; import 'package:stackwallet/pages/notification_views/notifications_view.dart'; import 'package:stackwallet/pages/paynym/add_new_paynym_follow_view.dart'; import 'package:stackwallet/pages/paynym/paynym_claim_view.dart'; @@ -375,6 +376,21 @@ class RouteGenerator { } return _routeError("${settings.name} invalid args: ${args.toString()}"); + case MonkeyView.routeName: + if (args is Tuple2>) { + return getRoute( + shouldUseMaterialRoute: useMaterialPageRoute, + builder: (_) => MonkeyView( + walletId: args.item1, + managerProvider: args.item2, + ), + settings: RouteSettings( + name: settings.name, + ), + ); + } + return _routeError("${settings.name} invalid args: ${args.toString()}"); + case CoinControlView.routeName: if (args is Tuple2) { return getRoute( From ee5a97c2fbccd9d7a116b0e84bad2611c9ed988e Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Fri, 21 Jul 2023 17:59:01 -0600 Subject: [PATCH 02/26] add monkey icon --- assets/svg/monkey.svg | 3 +++ lib/pages/wallet_view/wallet_view.dart | 2 +- lib/utilities/assets.dart | 1 + pubspec.yaml | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 assets/svg/monkey.svg diff --git a/assets/svg/monkey.svg b/assets/svg/monkey.svg new file mode 100644 index 000000000..565ac4fdf --- /dev/null +++ b/assets/svg/monkey.svg @@ -0,0 +1,3 @@ + + + diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index bd1c10b3c..6af2eeb65 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -938,7 +938,7 @@ class _WalletViewState extends ConsumerState { ), )) WalletNavigationBarItemData( - icon: SvgPicture.asset(Assets.svg.circlePlus), + icon: SvgPicture.asset(Assets.svg.monkey), label: "MonKey", onTap: () { Navigator.of(context).pushNamed( diff --git a/lib/utilities/assets.dart b/lib/utilities/assets.dart index b8ec501e8..f22ab6341 100644 --- a/lib/utilities/assets.dart +++ b/lib/utilities/assets.dart @@ -92,6 +92,7 @@ class _SVG { final coinControl = const _COIN_CONTROL(); + String get monkey => "assets/svg/monkey.svg"; String get circleSliders => "assets/svg/configuration.svg"; String get circlePlus => "assets/svg/plus-circle.svg"; String get circlePlusFilled => "assets/svg/circle-plus-filled.svg"; diff --git a/pubspec.yaml b/pubspec.yaml index f5b4cf27b..9999e8e65 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -335,6 +335,7 @@ flutter: - assets/svg/trocador_rating_b.svg - assets/svg/trocador_rating_c.svg - assets/svg/trocador_rating_d.svg + - assets/svg/monkey.svg # coin control icons - assets/svg/coin_control/ From 8ac085fe240b001b3db939352ff8d8549319570d Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Fri, 21 Jul 2023 18:01:38 -0600 Subject: [PATCH 03/26] fix monkey icon --- lib/pages/wallet_view/wallet_view.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index 6af2eeb65..0dcfe18dc 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -938,7 +938,10 @@ class _WalletViewState extends ConsumerState { ), )) WalletNavigationBarItemData( - icon: SvgPicture.asset(Assets.svg.monkey), + icon: SvgPicture.asset(Assets.svg.monkey, + height: 20, + width: 20, + color: Theme.of(context).extension()!.bottomNavIconIcon,), label: "MonKey", onTap: () { Navigator.of(context).pushNamed( From a286ba7b8f3dbc088ed3a811b27d7102778d2658 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Mon, 24 Jul 2023 12:43:33 -0600 Subject: [PATCH 04/26] monkey view page --- lib/pages/monkey/monkey_view.dart | 164 ++++++++++++++++++++++-------- 1 file changed, 119 insertions(+), 45 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index e74d5bbdf..10b9c91bf 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -7,11 +7,13 @@ import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; import 'package:stackwallet/services/coins/manager.dart'; import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; +import 'package:stackwallet/widgets/desktop/secondary_button.dart'; class MonkeyView extends ConsumerStatefulWidget { const MonkeyView({ @@ -50,6 +52,7 @@ class _MonkeyViewState extends ConsumerState { @override Widget build(BuildContext context) { final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); + bool isMonkey = false; return Background( child: Stack( @@ -65,60 +68,131 @@ class _MonkeyViewState extends ConsumerState { "MonKey", style: STextStyles.navBarTitle(context), ), + actions: [ + AspectRatio( + aspectRatio: 1, + child: AppBarIconButton( + icon: SvgPicture.asset(Assets.svg.circleQuestion), + onPressed: () { + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return Dialog( + child: Material( + borderRadius: BorderRadius.circular( + 20, + ), + child: Container( + height: 200, + decoration: BoxDecoration( + color: Theme.of(context) + .extension()! + .popupBG, + borderRadius: BorderRadius.circular( + 20, + ), + ), + child: Column( + children: [ + Center( + child: Text( + "Help", + style: STextStyles.pageTitleH2( + context), + ), + ) + ], + ), + ), + ), + ); + }); + }), + ) + ], ), - body: Column( - // mainAxisAlignment: MainAxisAlignment.center, - // crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const Spacer(), - Center( - child: Column( + body: isMonkey + ? Column( children: [ - SvgPicture.file( - File( - ref.watch(coinIconProvider(coin)), + Spacer(), + Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + SecondaryButton( + label: "Download as SVG", + onPressed: () {}, + ), + const SizedBox(height: 12), + SecondaryButton( + label: "Download as PNG", + onPressed: () {}, + ), + ], ), - width: 164, - height: 164, ), - const SizedBox( - height: 40, + ], + ) + : Column( + children: [ + const Spacer( + flex: 4, ), - Text( - "You do not have a MonKey yet. \nFetch yours now!", - style: STextStyles.smallMed14(context).copyWith( - color: Theme.of(context) - .extension()! - .textDark3, + Center( + child: Column( + children: [ + Opacity( + opacity: 0.2, + child: SvgPicture.file( + File( + ref.watch(coinIconProvider(coin)), + ), + width: 200, + height: 200, + ), + ), + const SizedBox( + height: 40, + ), + Text( + "You do not have a MonKey yet. \nFetch yours now!", + style: STextStyles.smallMed14(context).copyWith( + color: Theme.of(context) + .extension()! + .textDark3, + ), + textAlign: TextAlign.center, + ), + ], + ), + ), + const Spacer( + flex: 6, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: PrimaryButton( + label: "Fetch MonKey", + onPressed: () { + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: false, + builder: (context) { + return FetchMonkeyDialog( + onCancel: () async { + Navigator.of(context).pop(); + }, + ); + }, + ); + }, ), - textAlign: TextAlign.center, ), ], ), - ), - const Spacer(), - Padding( - padding: const EdgeInsets.all(16.0), - child: PrimaryButton( - label: "Fetch MonKey", - onPressed: () { - showDialog( - context: context, - useSafeArea: false, - barrierDismissible: false, - builder: (context) { - return FetchMonkeyDialog( - onCancel: () async { - Navigator.of(context).pop(); - }, - ); - }, - ); - }, - ), - ), - ], - ), ), ], ), From 3cbde8b5c1b91b77297a7f1d436a63509127df35 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 25 Jul 2023 14:52:58 -0600 Subject: [PATCH 05/26] able to download monkey.png --- lib/pages/monkey/monkey_view.dart | 79 +++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 10b9c91bf..f109dd5c7 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -3,7 +3,10 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:http/http.dart' as http; +import 'package:path_provider/path_provider.dart'; import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; +import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/services/coins/manager.dart'; import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; @@ -36,11 +39,69 @@ class _MonkeyViewState extends ConsumerState { late final String walletId; late final ChangeNotifierProvider managerProvider; + String receivingAddress = ""; + + void getMonkeySVG(String address) async { + if (address.isEmpty) { + //address shouldn't be empty + return; + } + + final http.Response response = await http + .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); + final decodedResponse = SvgPicture.memory(response.bodyBytes); + // final decodedResponse = json.decode(response.body); + // return decodedResponse; + debugPrint("$decodedResponse"); + } + + void getMonkeyPNG(String address) async { + if (address.isEmpty) { + //address shouldn't be empty + return; + } + + final http.Response response = await http.get(Uri.parse( + 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); + + if (response.statusCode == 200) { + final decodedResponse = response.bodyBytes; + final directory = await getApplicationDocumentsDirectory(); + // Directory appDir = await getTemporaryDirectory(); + final docPath = directory.path; + final filePath = "$docPath/monkey.png"; + + File imgFile = File(filePath); + await imgFile.writeAsBytes(decodedResponse); + print("$imgFile"); + + // final directory = await getApplicationDocumentsDirectory(); + // final docPath = directory.path; + // final filePath = "$do/monkey.png"; + } else { + throw Exception("Failed to get MonKey"); + } + + // final decodedResponse = json.decode(response.body); + // return decodedResponse; + // debugPrint("$decodedResponse"); + } + @override void initState() { walletId = widget.walletId; managerProvider = widget.managerProvider; + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final address = await ref + .read(walletsChangeNotifierProvider) + .getManager(walletId) + .currentReceivingAddress; + setState(() { + receivingAddress = address; + }); + }); + super.initState(); } @@ -52,7 +113,7 @@ class _MonkeyViewState extends ConsumerState { @override Widget build(BuildContext context) { final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); - bool isMonkey = false; + bool isMonkey = true; return Background( child: Stack( @@ -116,19 +177,29 @@ class _MonkeyViewState extends ConsumerState { body: isMonkey ? Column( children: [ - Spacer(), + Spacer( + flex: 1, + ), + Image.network( + 'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512', + ), + Spacer( + flex: 1, + ), Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ SecondaryButton( label: "Download as SVG", - onPressed: () {}, + onPressed: () async {}, ), const SizedBox(height: 12), SecondaryButton( label: "Download as PNG", - onPressed: () {}, + onPressed: () { + getMonkeyPNG(receivingAddress); + }, ), ], ), From b2ec2763fb6aaa8b07db166dee18523a10792189 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 25 Jul 2023 16:51:21 -0600 Subject: [PATCH 06/26] monkey.png downloads to user device --- lib/pages/monkey/monkey_view.dart | 55 +++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index f109dd5c7..5c1dbede1 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:http/http.dart' as http; import 'package:path_provider/path_provider.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/services/coins/manager.dart'; @@ -49,10 +50,19 @@ class _MonkeyViewState extends ConsumerState { final http.Response response = await http .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); - final decodedResponse = SvgPicture.memory(response.bodyBytes); - // final decodedResponse = json.decode(response.body); - // return decodedResponse; - debugPrint("$decodedResponse"); + if (response.statusCode == 200) { + final decodedResponse = response.bodyBytes; + final directory = await getApplicationDocumentsDirectory(); + // Directory appDir = await getTemporaryDirectory(); + final docPath = directory.path; + final filePath = "$docPath/monkey.svg"; + + File imgFile = File(filePath); + await imgFile.writeAsBytes(decodedResponse); + print("$imgFile"); + } else { + throw Exception("Failed to get MonKey"); + } } void getMonkeyPNG(String address) async { @@ -65,10 +75,29 @@ class _MonkeyViewState extends ConsumerState { 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); if (response.statusCode == 200) { + if (Platform.isAndroid) { + await Permission.storage.request(); + } + final decodedResponse = response.bodyBytes; - final directory = await getApplicationDocumentsDirectory(); - // Directory appDir = await getTemporaryDirectory(); - final docPath = directory.path; + Directory directory = await getApplicationDocumentsDirectory(); + late Directory sampleFolder; + + if (Platform.isAndroid) { + directory = Directory("/storage/emulated/0/"); + sampleFolder = Directory('${directory!.path}Documents'); + } + + try { + if (!sampleFolder.existsSync()) { + sampleFolder.createSync(recursive: true); + } + } catch (e, s) { + // todo: come back to this + debugPrint("$e $s"); + } + + final docPath = sampleFolder.path; final filePath = "$docPath/monkey.png"; File imgFile = File(filePath); @@ -81,10 +110,6 @@ class _MonkeyViewState extends ConsumerState { } else { throw Exception("Failed to get MonKey"); } - - // final decodedResponse = json.decode(response.body); - // return decodedResponse; - // debugPrint("$decodedResponse"); } @override @@ -177,13 +202,13 @@ class _MonkeyViewState extends ConsumerState { body: isMonkey ? Column( children: [ - Spacer( + const Spacer( flex: 1, ), Image.network( 'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512', ), - Spacer( + const Spacer( flex: 1, ), Padding( @@ -192,7 +217,9 @@ class _MonkeyViewState extends ConsumerState { children: [ SecondaryButton( label: "Download as SVG", - onPressed: () async {}, + onPressed: () async { + getMonkeySVG(receivingAddress); + }, ), const SizedBox(height: 12), SecondaryButton( From c6c2b429238c120ca19a4f726b8e5935e888cd35 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 25 Jul 2023 17:06:32 -0600 Subject: [PATCH 07/26] monkey.svg download to user device --- lib/pages/monkey/monkey_view.dart | 38 ++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 5c1dbede1..df449a91d 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -50,11 +50,35 @@ class _MonkeyViewState extends ConsumerState { final http.Response response = await http .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); + if (response.statusCode == 200) { final decodedResponse = response.bodyBytes; - final directory = await getApplicationDocumentsDirectory(); - // Directory appDir = await getTemporaryDirectory(); - final docPath = directory.path; + Directory directory = await getApplicationDocumentsDirectory(); + late Directory sampleFolder; + + if (Platform.isAndroid) { + directory = Directory("/storage/emulated/0/"); + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isIOS) { + sampleFolder = Directory(directory!.path); + } else if (Platform.isLinux) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isWindows) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isMacOS) { + sampleFolder = Directory('${directory!.path}Documents'); + } + + try { + if (!sampleFolder.existsSync()) { + sampleFolder.createSync(recursive: true); + } + } catch (e, s) { + // todo: come back to this + debugPrint("$e $s"); + } + + final docPath = sampleFolder.path; final filePath = "$docPath/monkey.svg"; File imgFile = File(filePath); @@ -86,6 +110,14 @@ class _MonkeyViewState extends ConsumerState { if (Platform.isAndroid) { directory = Directory("/storage/emulated/0/"); sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isIOS) { + sampleFolder = Directory(directory!.path); + } else if (Platform.isLinux) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isWindows) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isMacOS) { + sampleFolder = Directory('${directory!.path}Documents'); } try { From 512960d9b92cf23c1936337927651a9915be9d81 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 25 Jul 2023 17:29:05 -0600 Subject: [PATCH 08/26] changed monkey files around --- lib/pages/monkey/monkey_loaded_view.dart | 272 +++++++++++++++++++++++ lib/pages/monkey/monkey_view.dart | 253 ++++++--------------- lib/route_generator.dart | 16 ++ 3 files changed, 350 insertions(+), 191 deletions(-) create mode 100644 lib/pages/monkey/monkey_loaded_view.dart diff --git a/lib/pages/monkey/monkey_loaded_view.dart b/lib/pages/monkey/monkey_loaded_view.dart new file mode 100644 index 000000000..0b49fc738 --- /dev/null +++ b/lib/pages/monkey/monkey_loaded_view.dart @@ -0,0 +1,272 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:http/http.dart' as http; +import 'package:path_provider/path_provider.dart'; +import 'package:permission_handler/permission_handler.dart'; +import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; +import 'package:stackwallet/providers/global/wallets_provider.dart'; +import 'package:stackwallet/services/coins/manager.dart'; +import 'package:stackwallet/themes/stack_colors.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/widgets/background.dart'; +import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; +import 'package:stackwallet/widgets/desktop/secondary_button.dart'; + +class MonkeyLoadedView extends ConsumerStatefulWidget { + const MonkeyLoadedView({ + Key? key, + required this.walletId, + required this.managerProvider, + }) : super(key: key); + + static const String routeName = "/hasMonkey"; + static const double navBarHeight = 65.0; + + final String walletId; + final ChangeNotifierProvider managerProvider; + + @override + ConsumerState createState() => _MonkeyLoadedViewState(); +} + +class _MonkeyLoadedViewState extends ConsumerState { + late final String walletId; + late final ChangeNotifierProvider managerProvider; + + String receivingAddress = ""; + + void getMonkeySVG(String address) async { + if (address.isEmpty) { + //address shouldn't be empty + return; + } + + final http.Response response = await http + .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); + + if (response.statusCode == 200) { + final decodedResponse = response.bodyBytes; + Directory directory = await getApplicationDocumentsDirectory(); + late Directory sampleFolder; + + if (Platform.isAndroid) { + directory = Directory("/storage/emulated/0/"); + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isIOS) { + sampleFolder = Directory(directory!.path); + } else if (Platform.isLinux) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isWindows) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isMacOS) { + sampleFolder = Directory('${directory!.path}Documents'); + } + + try { + if (!sampleFolder.existsSync()) { + sampleFolder.createSync(recursive: true); + } + } catch (e, s) { + // todo: come back to this + debugPrint("$e $s"); + } + + final docPath = sampleFolder.path; + final filePath = "$docPath/monkey.svg"; + + File imgFile = File(filePath); + await imgFile.writeAsBytes(decodedResponse); + print("$imgFile"); + } else { + throw Exception("Failed to get MonKey"); + } + } + + void getMonkeyPNG(String address) async { + if (address.isEmpty) { + //address shouldn't be empty + return; + } + + final http.Response response = await http.get(Uri.parse( + 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); + + if (response.statusCode == 200) { + if (Platform.isAndroid) { + await Permission.storage.request(); + } + + final decodedResponse = response.bodyBytes; + Directory directory = await getApplicationDocumentsDirectory(); + late Directory sampleFolder; + + if (Platform.isAndroid) { + directory = Directory("/storage/emulated/0/"); + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isIOS) { + sampleFolder = Directory(directory!.path); + } else if (Platform.isLinux) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isWindows) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isMacOS) { + sampleFolder = Directory('${directory!.path}Documents'); + } + + try { + if (!sampleFolder.existsSync()) { + sampleFolder.createSync(recursive: true); + } + } catch (e, s) { + // todo: come back to this + debugPrint("$e $s"); + } + + final docPath = sampleFolder.path; + final filePath = "$docPath/monkey.png"; + + File imgFile = File(filePath); + await imgFile.writeAsBytes(decodedResponse); + print("$imgFile"); + + // final directory = await getApplicationDocumentsDirectory(); + // final docPath = directory.path; + // final filePath = "$do/monkey.png"; + } else { + throw Exception("Failed to get MonKey"); + } + } + + @override + void initState() { + walletId = widget.walletId; + managerProvider = widget.managerProvider; + + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final address = await ref + .read(walletsChangeNotifierProvider) + .getManager(walletId) + .currentReceivingAddress; + setState(() { + receivingAddress = address; + }); + }); + + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); + bool isMonkey = false; + + return Background( + child: Stack( + children: [ + Scaffold( + appBar: AppBar( + leading: AppBarBackButton( + onPressed: () { + Navigator.of(context).popUntil( + ModalRoute.withName(WalletView.routeName), + ); + }, + ), + title: Text( + "MonKey", + style: STextStyles.navBarTitle(context), + ), + actions: [ + AspectRatio( + aspectRatio: 1, + child: AppBarIconButton( + icon: SvgPicture.asset(Assets.svg.circleQuestion), + onPressed: () { + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return Dialog( + child: Material( + borderRadius: BorderRadius.circular( + 20, + ), + child: Container( + height: 200, + decoration: BoxDecoration( + color: Theme.of(context) + .extension()! + .popupBG, + borderRadius: BorderRadius.circular( + 20, + ), + ), + child: Column( + children: [ + Center( + child: Text( + "Help", + style: STextStyles.pageTitleH2( + context), + ), + ) + ], + ), + ), + ), + ); + }); + }), + ) + ], + ), + body: Column( + children: [ + const Spacer( + flex: 1, + ), + Image.network( + 'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512', + ), + const Spacer( + flex: 1, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + SecondaryButton( + label: "Download as SVG", + onPressed: () async { + getMonkeySVG(receivingAddress); + }, + ), + const SizedBox(height: 12), + SecondaryButton( + label: "Download as PNG", + onPressed: () { + getMonkeyPNG(receivingAddress); + }, + ), + ], + ), + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index df449a91d..17758b9f7 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -3,9 +3,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:http/http.dart' as http; -import 'package:path_provider/path_provider.dart'; -import 'package:permission_handler/permission_handler.dart'; +import 'package:stackwallet/pages/monkey/monkey_loaded_view.dart'; import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/services/coins/manager.dart'; @@ -17,7 +15,7 @@ import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; -import 'package:stackwallet/widgets/desktop/secondary_button.dart'; +import 'package:tuple/tuple.dart'; class MonkeyView extends ConsumerStatefulWidget { const MonkeyView({ @@ -42,108 +40,6 @@ class _MonkeyViewState extends ConsumerState { String receivingAddress = ""; - void getMonkeySVG(String address) async { - if (address.isEmpty) { - //address shouldn't be empty - return; - } - - final http.Response response = await http - .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); - - if (response.statusCode == 200) { - final decodedResponse = response.bodyBytes; - Directory directory = await getApplicationDocumentsDirectory(); - late Directory sampleFolder; - - if (Platform.isAndroid) { - directory = Directory("/storage/emulated/0/"); - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isIOS) { - sampleFolder = Directory(directory!.path); - } else if (Platform.isLinux) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isWindows) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isMacOS) { - sampleFolder = Directory('${directory!.path}Documents'); - } - - try { - if (!sampleFolder.existsSync()) { - sampleFolder.createSync(recursive: true); - } - } catch (e, s) { - // todo: come back to this - debugPrint("$e $s"); - } - - final docPath = sampleFolder.path; - final filePath = "$docPath/monkey.svg"; - - File imgFile = File(filePath); - await imgFile.writeAsBytes(decodedResponse); - print("$imgFile"); - } else { - throw Exception("Failed to get MonKey"); - } - } - - void getMonkeyPNG(String address) async { - if (address.isEmpty) { - //address shouldn't be empty - return; - } - - final http.Response response = await http.get(Uri.parse( - 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); - - if (response.statusCode == 200) { - if (Platform.isAndroid) { - await Permission.storage.request(); - } - - final decodedResponse = response.bodyBytes; - Directory directory = await getApplicationDocumentsDirectory(); - late Directory sampleFolder; - - if (Platform.isAndroid) { - directory = Directory("/storage/emulated/0/"); - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isIOS) { - sampleFolder = Directory(directory!.path); - } else if (Platform.isLinux) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isWindows) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isMacOS) { - sampleFolder = Directory('${directory!.path}Documents'); - } - - try { - if (!sampleFolder.existsSync()) { - sampleFolder.createSync(recursive: true); - } - } catch (e, s) { - // todo: come back to this - debugPrint("$e $s"); - } - - final docPath = sampleFolder.path; - final filePath = "$docPath/monkey.png"; - - File imgFile = File(filePath); - await imgFile.writeAsBytes(decodedResponse); - print("$imgFile"); - - // final directory = await getApplicationDocumentsDirectory(); - // final docPath = directory.path; - // final filePath = "$do/monkey.png"; - } else { - throw Exception("Failed to get MonKey"); - } - } - @override void initState() { walletId = widget.walletId; @@ -170,7 +66,6 @@ class _MonkeyViewState extends ConsumerState { @override Widget build(BuildContext context) { final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); - bool isMonkey = true; return Background( child: Stack( @@ -231,98 +126,74 @@ class _MonkeyViewState extends ConsumerState { ) ], ), - body: isMonkey - ? Column( + body: Column( + children: [ + const Spacer( + flex: 4, + ), + Center( + child: Column( children: [ - const Spacer( - flex: 1, - ), - Image.network( - 'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512', - ), - const Spacer( - flex: 1, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - SecondaryButton( - label: "Download as SVG", - onPressed: () async { - getMonkeySVG(receivingAddress); - }, - ), - const SizedBox(height: 12), - SecondaryButton( - label: "Download as PNG", - onPressed: () { - getMonkeyPNG(receivingAddress); - }, - ), - ], + Opacity( + opacity: 0.2, + child: SvgPicture.file( + File( + ref.watch(coinIconProvider(coin)), + ), + width: 200, + height: 200, ), ), - ], - ) - : Column( - children: [ - const Spacer( - flex: 4, + const SizedBox( + height: 40, ), - Center( - child: Column( - children: [ - Opacity( - opacity: 0.2, - child: SvgPicture.file( - File( - ref.watch(coinIconProvider(coin)), - ), - width: 200, - height: 200, - ), - ), - const SizedBox( - height: 40, - ), - Text( - "You do not have a MonKey yet. \nFetch yours now!", - style: STextStyles.smallMed14(context).copyWith( - color: Theme.of(context) - .extension()! - .textDark3, - ), - textAlign: TextAlign.center, - ), - ], - ), - ), - const Spacer( - flex: 6, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: PrimaryButton( - label: "Fetch MonKey", - onPressed: () { - showDialog( - context: context, - useSafeArea: false, - barrierDismissible: false, - builder: (context) { - return FetchMonkeyDialog( - onCancel: () async { - Navigator.of(context).pop(); - }, - ); - }, - ); - }, + Text( + "You do not have a MonKey yet. \nFetch yours now!", + style: STextStyles.smallMed14(context).copyWith( + color: Theme.of(context) + .extension()! + .textDark3, ), + textAlign: TextAlign.center, ), ], ), + ), + const Spacer( + flex: 6, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: PrimaryButton( + label: "Fetch MonKey", + onPressed: () async { + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: false, + builder: (context) { + return FetchMonkeyDialog( + onCancel: () async { + Navigator.of(context).pop(); + }, + ); + }, + ); + + await Future.delayed(const Duration(seconds: 2)); + + Navigator.of(context).pushNamed( + MonkeyLoadedView.routeName, + arguments: Tuple2( + widget.walletId, + widget.managerProvider, + ), + ); + }, + ), + ), + ], + ), ), ], ), diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 4513fd1d6..b02638082 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -56,6 +56,7 @@ import 'package:stackwallet/pages/generic/single_field_edit_view.dart'; import 'package:stackwallet/pages/home_view/home_view.dart'; import 'package:stackwallet/pages/intro_view.dart'; import 'package:stackwallet/pages/manage_favorites_view/manage_favorites_view.dart'; +import 'package:stackwallet/pages/monkey/monkey_loaded_view.dart'; import 'package:stackwallet/pages/monkey/monkey_view.dart'; import 'package:stackwallet/pages/notification_views/notifications_view.dart'; import 'package:stackwallet/pages/paynym/add_new_paynym_follow_view.dart'; @@ -391,6 +392,21 @@ class RouteGenerator { } return _routeError("${settings.name} invalid args: ${args.toString()}"); + case MonkeyLoadedView.routeName: + if (args is Tuple2>) { + return getRoute( + shouldUseMaterialRoute: useMaterialPageRoute, + builder: (_) => MonkeyLoadedView( + walletId: args.item1, + managerProvider: args.item2, + ), + settings: RouteSettings( + name: settings.name, + ), + ); + } + return _routeError("${settings.name} invalid args: ${args.toString()}"); + case CoinControlView.routeName: if (args is Tuple2) { return getRoute( From 78e4cd463172258cdde6fd2ca98a709ca2b0f7e1 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 25 Jul 2023 17:42:36 -0600 Subject: [PATCH 09/26] removed unnecessary lines --- lib/pages/monkey/monkey_loaded_view.dart | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/pages/monkey/monkey_loaded_view.dart b/lib/pages/monkey/monkey_loaded_view.dart index 0b49fc738..32570e6a7 100644 --- a/lib/pages/monkey/monkey_loaded_view.dart +++ b/lib/pages/monkey/monkey_loaded_view.dart @@ -81,7 +81,6 @@ class _MonkeyLoadedViewState extends ConsumerState { File imgFile = File(filePath); await imgFile.writeAsBytes(decodedResponse); - print("$imgFile"); } else { throw Exception("Failed to get MonKey"); } @@ -132,11 +131,6 @@ class _MonkeyLoadedViewState extends ConsumerState { File imgFile = File(filePath); await imgFile.writeAsBytes(decodedResponse); - print("$imgFile"); - - // final directory = await getApplicationDocumentsDirectory(); - // final docPath = directory.path; - // final filePath = "$do/monkey.png"; } else { throw Exception("Failed to get MonKey"); } @@ -168,7 +162,6 @@ class _MonkeyLoadedViewState extends ConsumerState { @override Widget build(BuildContext context) { final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); - bool isMonkey = false; return Background( child: Stack( From 683364750adfab6c04ae7509a332defb77c761b1 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 11:13:48 -0600 Subject: [PATCH 10/26] structure change to add monkey image --- .../sub_widgets/wallet_summary_info.dart | 160 +++++++++++------- 1 file changed, 95 insertions(+), 65 deletions(-) diff --git a/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart b/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart index a4716d190..57658498c 100644 --- a/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart +++ b/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart @@ -31,6 +31,7 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart'; import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/widgets/conditional_parent.dart'; class WalletSummaryInfo extends ConsumerStatefulWidget { const WalletSummaryInfo({ @@ -49,6 +50,8 @@ class WalletSummaryInfo extends ConsumerStatefulWidget { class _WalletSummaryInfoState extends ConsumerState { late StreamSubscription _balanceUpdated; + String receivingAddress = ""; + void showSheet() { showModalBottomSheet( backgroundColor: Colors.transparent, @@ -72,6 +75,17 @@ class _WalletSummaryInfoState extends ConsumerState { } }, ); + + // managerProvider = widget.managerProvider; + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final address = await ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId) + .currentReceivingAddress; + setState(() { + receivingAddress = address; + }); + }); super.initState(); } @@ -85,6 +99,8 @@ class _WalletSummaryInfoState extends ConsumerState { Widget build(BuildContext context) { debugPrint("BUILD: $runtimeType"); + bool isMonkey = true; + final externalCalls = ref.watch( prefsChangeNotifierProvider.select((value) => value.externalCalls)); final coin = ref.watch(walletsChangeNotifierProvider @@ -125,84 +141,98 @@ class _WalletSummaryInfoState extends ConsumerState { title = _showAvailable ? "Available balance" : "Full balance"; } - return Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - GestureDetector( - onTap: showSheet, - child: Row( - children: [ - Text( - title, - style: STextStyles.subtitle500(context).copyWith( + return ConditionalParent( + condition: isMonkey && Coin == Coin.banano, + builder: (child) => Container( + decoration: BoxDecoration( + image: DecorationImage( + alignment: Alignment.centerRight, + image: NetworkImage( + 'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512', + ), + ), + ), + child: child, + ), + child: Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GestureDetector( + onTap: showSheet, + child: Row( + children: [ + Text( + title, + style: STextStyles.subtitle500(context).copyWith( + color: Theme.of(context) + .extension()! + .textFavoriteCard, + ), + ), + const SizedBox( + width: 4, + ), + SvgPicture.asset( + Assets.svg.chevronDown, color: Theme.of(context) .extension()! .textFavoriteCard, + width: 8, + height: 4, ), - ), - const SizedBox( - width: 4, - ), - SvgPicture.asset( - Assets.svg.chevronDown, + ], + ), + ), + const Spacer(), + FittedBox( + fit: BoxFit.scaleDown, + child: SelectableText( + ref.watch(pAmountFormatter(coin)).format(balanceToShow), + style: STextStyles.pageTitleH1(context).copyWith( + fontSize: 24, color: Theme.of(context) .extension()! .textFavoriteCard, - width: 8, - height: 4, ), - ], + ), ), + if (externalCalls) + Text( + "${(priceTuple.item1 * balanceToShow.decimal).toAmount( + fractionDigits: 2, + ).fiatString( + locale: locale, + )} $baseCurrency", + style: STextStyles.subtitle500(context).copyWith( + color: Theme.of(context) + .extension()! + .textFavoriteCard, + ), + ), + ], + ), + ), + Column( + children: [ + SvgPicture.file( + File( + ref.watch(coinIconProvider(coin)), + ), + width: 24, + height: 24, ), const Spacer(), - FittedBox( - fit: BoxFit.scaleDown, - child: SelectableText( - ref.watch(pAmountFormatter(coin)).format(balanceToShow), - style: STextStyles.pageTitleH1(context).copyWith( - fontSize: 24, - color: Theme.of(context) - .extension()! - .textFavoriteCard, - ), - ), + WalletRefreshButton( + walletId: widget.walletId, + initialSyncStatus: widget.initialSyncStatus, ), - if (externalCalls) - Text( - "${(priceTuple.item1 * balanceToShow.decimal).toAmount( - fractionDigits: 2, - ).fiatString( - locale: locale, - )} $baseCurrency", - style: STextStyles.subtitle500(context).copyWith( - color: Theme.of(context) - .extension()! - .textFavoriteCard, - ), - ), ], - ), - ), - Column( - children: [ - SvgPicture.file( - File( - ref.watch(coinIconProvider(coin)), - ), - width: 24, - height: 24, - ), - const Spacer(), - WalletRefreshButton( - walletId: widget.walletId, - initialSyncStatus: widget.initialSyncStatus, - ), - ], - ) - ], + ) + ], + ), ); } } From 2eb10e249f1ee4d9543aea4e583b4f1e0c0bebff Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 11:54:10 -0600 Subject: [PATCH 11/26] add monkey image to hive and display on wallet card --- .../sub_widgets/wallet_summary_info.dart | 32 ++++++++++++------- lib/services/coins/banano/banano_wallet.dart | 16 ++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart b/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart index 57658498c..0c4e6fb08 100644 --- a/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart +++ b/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart @@ -10,6 +10,7 @@ import 'dart:async'; import 'dart:io'; +import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -19,6 +20,7 @@ import 'package:stackwallet/pages/wallet_view/sub_widgets/wallet_refresh_button. import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart'; import 'package:stackwallet/providers/wallet/wallet_balance_toggle_state_provider.dart'; +import 'package:stackwallet/services/coins/banano/banano_wallet.dart'; import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; import 'package:stackwallet/services/event_bus/events/global/balance_refreshed_event.dart'; import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart'; @@ -101,10 +103,12 @@ class _WalletSummaryInfoState extends ConsumerState { bool isMonkey = true; + final manager = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(widget.walletId))); + final externalCalls = ref.watch( prefsChangeNotifierProvider.select((value) => value.externalCalls)); - final coin = ref.watch(walletsChangeNotifierProvider - .select((value) => value.getManager(widget.walletId).coin)); + final coin = manager.coin; final balance = ref.watch(walletsChangeNotifierProvider .select((value) => value.getManager(widget.walletId).balance)); @@ -141,18 +145,24 @@ class _WalletSummaryInfoState extends ConsumerState { title = _showAvailable ? "Available balance" : "Full balance"; } + List? imageBytes; + + if (coin == Coin.banano) { + imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes(); + } + return ConditionalParent( - condition: isMonkey && Coin == Coin.banano, - builder: (child) => Container( - decoration: BoxDecoration( - image: DecorationImage( - alignment: Alignment.centerRight, - image: NetworkImage( - 'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512', + condition: imageBytes != null, + builder: (child) => Stack( + children: [ + Positioned.fill( + left: 150.0, + child: SvgPicture.memory( + Uint8List.fromList(imageBytes!), ), ), - ), - child: child, + child, + ], ), child: Row( children: [ diff --git a/lib/services/coins/banano/banano_wallet.dart b/lib/services/coins/banano/banano_wallet.dart index 8511f5599..be5d20889 100644 --- a/lib/services/coins/banano/banano_wallet.dart +++ b/lib/services/coins/banano/banano_wallet.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:isar/isar.dart'; import 'package:nanodart/nanodart.dart'; +import 'package:stackwallet/db/hive/db.dart'; import 'package:stackwallet/db/isar/main_db.dart'; import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/isar/models/isar_models.dart'; @@ -925,4 +926,19 @@ class BananoWallet extends CoinServiceAPI ); await updateCachedChainHeight(height ?? 0); } + + Future updateMonkeyImageBytes(List bytes) async { + await DB.instance.put( + boxName: _walletId, + key: "monkeyImageBytesKey", + value: bytes, + ); + } + + List? getMonkeyImageBytes() { + return DB.instance.get( + boxName: _walletId, + key: "monkeyImageBytesKey", + ) as List?; + } } From 032061fa1912e536fc72dae0691f9bcd890d8415 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 12:03:01 -0600 Subject: [PATCH 12/26] changed generate monkey structure --- lib/pages/monkey/monkey_loaded_view.dart | 540 ++++++++++++----------- lib/pages/monkey/monkey_view.dart | 296 ++++++++++--- lib/route_generator.dart | 29 +- 3 files changed, 520 insertions(+), 345 deletions(-) diff --git a/lib/pages/monkey/monkey_loaded_view.dart b/lib/pages/monkey/monkey_loaded_view.dart index 32570e6a7..93c28b39a 100644 --- a/lib/pages/monkey/monkey_loaded_view.dart +++ b/lib/pages/monkey/monkey_loaded_view.dart @@ -1,265 +1,275 @@ -import 'dart:io'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:http/http.dart' as http; -import 'package:path_provider/path_provider.dart'; -import 'package:permission_handler/permission_handler.dart'; -import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; -import 'package:stackwallet/providers/global/wallets_provider.dart'; -import 'package:stackwallet/services/coins/manager.dart'; -import 'package:stackwallet/themes/stack_colors.dart'; -import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/enums/coin_enum.dart'; -import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/widgets/background.dart'; -import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; -import 'package:stackwallet/widgets/desktop/secondary_button.dart'; - -class MonkeyLoadedView extends ConsumerStatefulWidget { - const MonkeyLoadedView({ - Key? key, - required this.walletId, - required this.managerProvider, - }) : super(key: key); - - static const String routeName = "/hasMonkey"; - static const double navBarHeight = 65.0; - - final String walletId; - final ChangeNotifierProvider managerProvider; - - @override - ConsumerState createState() => _MonkeyLoadedViewState(); -} - -class _MonkeyLoadedViewState extends ConsumerState { - late final String walletId; - late final ChangeNotifierProvider managerProvider; - - String receivingAddress = ""; - - void getMonkeySVG(String address) async { - if (address.isEmpty) { - //address shouldn't be empty - return; - } - - final http.Response response = await http - .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); - - if (response.statusCode == 200) { - final decodedResponse = response.bodyBytes; - Directory directory = await getApplicationDocumentsDirectory(); - late Directory sampleFolder; - - if (Platform.isAndroid) { - directory = Directory("/storage/emulated/0/"); - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isIOS) { - sampleFolder = Directory(directory!.path); - } else if (Platform.isLinux) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isWindows) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isMacOS) { - sampleFolder = Directory('${directory!.path}Documents'); - } - - try { - if (!sampleFolder.existsSync()) { - sampleFolder.createSync(recursive: true); - } - } catch (e, s) { - // todo: come back to this - debugPrint("$e $s"); - } - - final docPath = sampleFolder.path; - final filePath = "$docPath/monkey.svg"; - - File imgFile = File(filePath); - await imgFile.writeAsBytes(decodedResponse); - } else { - throw Exception("Failed to get MonKey"); - } - } - - void getMonkeyPNG(String address) async { - if (address.isEmpty) { - //address shouldn't be empty - return; - } - - final http.Response response = await http.get(Uri.parse( - 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); - - if (response.statusCode == 200) { - if (Platform.isAndroid) { - await Permission.storage.request(); - } - - final decodedResponse = response.bodyBytes; - Directory directory = await getApplicationDocumentsDirectory(); - late Directory sampleFolder; - - if (Platform.isAndroid) { - directory = Directory("/storage/emulated/0/"); - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isIOS) { - sampleFolder = Directory(directory!.path); - } else if (Platform.isLinux) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isWindows) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isMacOS) { - sampleFolder = Directory('${directory!.path}Documents'); - } - - try { - if (!sampleFolder.existsSync()) { - sampleFolder.createSync(recursive: true); - } - } catch (e, s) { - // todo: come back to this - debugPrint("$e $s"); - } - - final docPath = sampleFolder.path; - final filePath = "$docPath/monkey.png"; - - File imgFile = File(filePath); - await imgFile.writeAsBytes(decodedResponse); - } else { - throw Exception("Failed to get MonKey"); - } - } - - @override - void initState() { - walletId = widget.walletId; - managerProvider = widget.managerProvider; - - WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - final address = await ref - .read(walletsChangeNotifierProvider) - .getManager(walletId) - .currentReceivingAddress; - setState(() { - receivingAddress = address; - }); - }); - - super.initState(); - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); - - return Background( - child: Stack( - children: [ - Scaffold( - appBar: AppBar( - leading: AppBarBackButton( - onPressed: () { - Navigator.of(context).popUntil( - ModalRoute.withName(WalletView.routeName), - ); - }, - ), - title: Text( - "MonKey", - style: STextStyles.navBarTitle(context), - ), - actions: [ - AspectRatio( - aspectRatio: 1, - child: AppBarIconButton( - icon: SvgPicture.asset(Assets.svg.circleQuestion), - onPressed: () { - showDialog( - context: context, - useSafeArea: false, - barrierDismissible: true, - builder: (context) { - return Dialog( - child: Material( - borderRadius: BorderRadius.circular( - 20, - ), - child: Container( - height: 200, - decoration: BoxDecoration( - color: Theme.of(context) - .extension()! - .popupBG, - borderRadius: BorderRadius.circular( - 20, - ), - ), - child: Column( - children: [ - Center( - child: Text( - "Help", - style: STextStyles.pageTitleH2( - context), - ), - ) - ], - ), - ), - ), - ); - }); - }), - ) - ], - ), - body: Column( - children: [ - const Spacer( - flex: 1, - ), - Image.network( - 'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512', - ), - const Spacer( - flex: 1, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - SecondaryButton( - label: "Download as SVG", - onPressed: () async { - getMonkeySVG(receivingAddress); - }, - ), - const SizedBox(height: 12), - SecondaryButton( - label: "Download as PNG", - onPressed: () { - getMonkeyPNG(receivingAddress); - }, - ), - ], - ), - ), - ], - ), - ), - ], - ), - ); - } -} +// import 'dart:io'; +// import 'dart:typed_data'; +// +// import 'package:flutter/material.dart'; +// import 'package:flutter_riverpod/flutter_riverpod.dart'; +// import 'package:flutter_svg/svg.dart'; +// import 'package:http/http.dart' as http; +// import 'package:path_provider/path_provider.dart'; +// import 'package:permission_handler/permission_handler.dart'; +// import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; +// import 'package:stackwallet/providers/global/wallets_provider.dart'; +// import 'package:stackwallet/services/coins/banano/banano_wallet.dart'; +// import 'package:stackwallet/services/coins/manager.dart'; +// import 'package:stackwallet/themes/stack_colors.dart'; +// import 'package:stackwallet/utilities/assets.dart'; +// import 'package:stackwallet/utilities/enums/coin_enum.dart'; +// import 'package:stackwallet/utilities/text_styles.dart'; +// import 'package:stackwallet/widgets/background.dart'; +// import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; +// import 'package:stackwallet/widgets/desktop/secondary_button.dart'; +// +// class MonkeyLoadedView extends ConsumerStatefulWidget { +// const MonkeyLoadedView({ +// Key? key, +// required this.walletId, +// required this.managerProvider, +// }) : super(key: key); +// +// static const String routeName = "/hasMonkey"; +// static const double navBarHeight = 65.0; +// +// final String walletId; +// final ChangeNotifierProvider managerProvider; +// +// @override +// ConsumerState createState() => _MonkeyLoadedViewState(); +// } +// +// class _MonkeyLoadedViewState extends ConsumerState { +// late final String walletId; +// late final ChangeNotifierProvider managerProvider; +// +// String receivingAddress = ""; +// +// void getMonkeySVG(String address) async { +// if (address.isEmpty) { +// //address shouldn't be empty +// return; +// } +// +// final http.Response response = await http +// .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); +// +// if (response.statusCode == 200) { +// final decodedResponse = response.bodyBytes; +// Directory directory = await getApplicationDocumentsDirectory(); +// late Directory sampleFolder; +// +// if (Platform.isAndroid) { +// directory = Directory("/storage/emulated/0/"); +// sampleFolder = Directory('${directory!.path}Documents'); +// } else if (Platform.isIOS) { +// sampleFolder = Directory(directory!.path); +// } else if (Platform.isLinux) { +// sampleFolder = Directory('${directory!.path}Documents'); +// } else if (Platform.isWindows) { +// sampleFolder = Directory('${directory!.path}Documents'); +// } else if (Platform.isMacOS) { +// sampleFolder = Directory('${directory!.path}Documents'); +// } +// +// try { +// if (!sampleFolder.existsSync()) { +// sampleFolder.createSync(recursive: true); +// } +// } catch (e, s) { +// // todo: come back to this +// debugPrint("$e $s"); +// } +// +// final docPath = sampleFolder.path; +// final filePath = "$docPath/monkey.svg"; +// +// File imgFile = File(filePath); +// await imgFile.writeAsBytes(decodedResponse); +// } else { +// throw Exception("Failed to get MonKey"); +// } +// } +// +// void getMonkeyPNG(String address) async { +// if (address.isEmpty) { +// //address shouldn't be empty +// return; +// } +// +// final http.Response response = await http.get(Uri.parse( +// 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); +// +// if (response.statusCode == 200) { +// if (Platform.isAndroid) { +// await Permission.storage.request(); +// } +// +// final decodedResponse = response.bodyBytes; +// Directory directory = await getApplicationDocumentsDirectory(); +// late Directory sampleFolder; +// +// if (Platform.isAndroid) { +// directory = Directory("/storage/emulated/0/"); +// sampleFolder = Directory('${directory!.path}Documents'); +// } else if (Platform.isIOS) { +// sampleFolder = Directory(directory!.path); +// } else if (Platform.isLinux) { +// sampleFolder = Directory('${directory!.path}Documents'); +// } else if (Platform.isWindows) { +// sampleFolder = Directory('${directory!.path}Documents'); +// } else if (Platform.isMacOS) { +// sampleFolder = Directory('${directory!.path}Documents'); +// } +// +// try { +// if (!sampleFolder.existsSync()) { +// sampleFolder.createSync(recursive: true); +// } +// } catch (e, s) { +// // todo: come back to this +// debugPrint("$e $s"); +// } +// +// final docPath = sampleFolder.path; +// final filePath = "$docPath/monkey.png"; +// +// File imgFile = File(filePath); +// await imgFile.writeAsBytes(decodedResponse); +// } else { +// throw Exception("Failed to get MonKey"); +// } +// } +// +// @override +// void initState() { +// walletId = widget.walletId; +// managerProvider = widget.managerProvider; +// +// WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { +// final address = await ref +// .read(walletsChangeNotifierProvider) +// .getManager(walletId) +// .currentReceivingAddress; +// setState(() { +// receivingAddress = address; +// }); +// }); +// +// super.initState(); +// } +// +// @override +// void dispose() { +// super.dispose(); +// } +// +// @override +// Widget build(BuildContext context) { +// final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); +// final manager = ref.watch(walletsChangeNotifierProvider +// .select((value) => value.getManager(widget.walletId))); +// +// List? imageBytes; +// imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes(); +// +// return Background( +// child: Stack( +// children: [ +// Scaffold( +// appBar: AppBar( +// leading: AppBarBackButton( +// onPressed: () { +// Navigator.of(context).popUntil( +// ModalRoute.withName(WalletView.routeName), +// ); +// }, +// ), +// title: Text( +// "MonKey", +// style: STextStyles.navBarTitle(context), +// ), +// actions: [ +// AspectRatio( +// aspectRatio: 1, +// child: AppBarIconButton( +// icon: SvgPicture.asset(Assets.svg.circleQuestion), +// onPressed: () { +// showDialog( +// context: context, +// useSafeArea: false, +// barrierDismissible: true, +// builder: (context) { +// return Dialog( +// child: Material( +// borderRadius: BorderRadius.circular( +// 20, +// ), +// child: Container( +// height: 200, +// decoration: BoxDecoration( +// color: Theme.of(context) +// .extension()! +// .popupBG, +// borderRadius: BorderRadius.circular( +// 20, +// ), +// ), +// child: Column( +// children: [ +// Center( +// child: Text( +// "Help", +// style: STextStyles.pageTitleH2( +// context), +// ), +// ) +// ], +// ), +// ), +// ), +// ); +// }); +// }), +// ) +// ], +// ), +// body: Column( +// children: [ +// const Spacer( +// flex: 1, +// ), +// if (imageBytes != null) +// Container( +// child: SvgPicture.memory(Uint8List.fromList(imageBytes!)), +// width: 300, +// height: 300, +// ), +// const Spacer( +// flex: 1, +// ), +// Padding( +// padding: const EdgeInsets.all(16.0), +// child: Column( +// children: [ +// SecondaryButton( +// label: "Download as SVG", +// onPressed: () async { +// getMonkeySVG(receivingAddress); +// }, +// ), +// const SizedBox(height: 12), +// SecondaryButton( +// label: "Download as PNG", +// onPressed: () { +// getMonkeyPNG(receivingAddress); +// }, +// ), +// ], +// ), +// ), +// ], +// ), +// ), +// ], +// ), +// ); +// } +// } diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 17758b9f7..b631b0703 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -1,11 +1,16 @@ import 'dart:io'; +import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:stackwallet/pages/monkey/monkey_loaded_view.dart'; +import 'package:http/http.dart' as http; +import 'package:path_provider/path_provider.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; +import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; +import 'package:stackwallet/services/coins/banano/banano_wallet.dart'; import 'package:stackwallet/services/coins/manager.dart'; import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; @@ -13,9 +18,10 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/background.dart'; +import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; -import 'package:tuple/tuple.dart'; +import 'package:stackwallet/widgets/desktop/secondary_button.dart'; class MonkeyView extends ConsumerStatefulWidget { const MonkeyView({ @@ -40,6 +46,123 @@ class _MonkeyViewState extends ConsumerState { String receivingAddress = ""; + void getMonkeyImage(String address) async { + if (address.isEmpty) { + //address shouldn't be empty + return; + } + + final manager = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(walletId))); + + final http.Response response = await http + .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); + + if (response.statusCode == 200) { + final decodedResponse = response.bodyBytes; + await (manager.wallet as BananoWallet) + .updateMonkeyImageBytes(decodedResponse); + } else { + throw Exception("Failed to get MonKey"); + } + } + + void getMonkeySVG(String address) async { + if (address.isEmpty) { + //address shouldn't be empty + return; + } + + final http.Response response = await http + .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); + + if (response.statusCode == 200) { + final decodedResponse = response.bodyBytes; + Directory directory = await getApplicationDocumentsDirectory(); + late Directory sampleFolder; + + if (Platform.isAndroid) { + directory = Directory("/storage/emulated/0/"); + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isIOS) { + sampleFolder = Directory(directory!.path); + } else if (Platform.isLinux) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isWindows) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isMacOS) { + sampleFolder = Directory('${directory!.path}Documents'); + } + + try { + if (!sampleFolder.existsSync()) { + sampleFolder.createSync(recursive: true); + } + } catch (e, s) { + // todo: come back to this + debugPrint("$e $s"); + } + + final docPath = sampleFolder.path; + final filePath = "$docPath/monkey.svg"; + + File imgFile = File(filePath); + await imgFile.writeAsBytes(decodedResponse); + } else { + throw Exception("Failed to get MonKey"); + } + } + + void getMonkeyPNG(String address) async { + if (address.isEmpty) { + //address shouldn't be empty + return; + } + + final http.Response response = await http.get(Uri.parse( + 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); + + if (response.statusCode == 200) { + if (Platform.isAndroid) { + await Permission.storage.request(); + } + + final decodedResponse = response.bodyBytes; + Directory directory = await getApplicationDocumentsDirectory(); + late Directory sampleFolder; + + if (Platform.isAndroid) { + directory = Directory("/storage/emulated/0/"); + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isIOS) { + sampleFolder = Directory(directory!.path); + } else if (Platform.isLinux) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isWindows) { + sampleFolder = Directory('${directory!.path}Documents'); + } else if (Platform.isMacOS) { + sampleFolder = Directory('${directory!.path}Documents'); + } + + try { + if (!sampleFolder.existsSync()) { + sampleFolder.createSync(recursive: true); + } + } catch (e, s) { + // todo: come back to this + debugPrint("$e $s"); + } + + final docPath = sampleFolder.path; + final filePath = "$docPath/monkey.png"; + + File imgFile = File(filePath); + await imgFile.writeAsBytes(decodedResponse); + } else { + throw Exception("Failed to get MonKey"); + } + } + @override void initState() { walletId = widget.walletId; @@ -66,6 +189,11 @@ class _MonkeyViewState extends ConsumerState { @override Widget build(BuildContext context) { final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); + final manager = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(widget.walletId))); + + List? imageBytes; + imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes(); return Background( child: Stack( @@ -123,76 +251,114 @@ class _MonkeyViewState extends ConsumerState { ); }); }), - ) + ), ], ), - body: Column( - children: [ - const Spacer( - flex: 4, - ), - Center( - child: Column( - children: [ - Opacity( - opacity: 0.2, - child: SvgPicture.file( - File( - ref.watch(coinIconProvider(coin)), + body: ConditionalParent( + condition: imageBytes != null, + builder: (child) => Column( + children: [ + const Spacer( + flex: 1, + ), + if (imageBytes != null) + Container( + child: SvgPicture.memory(Uint8List.fromList(imageBytes!)), + width: 300, + height: 300, + ), + const Spacer( + flex: 1, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + SecondaryButton( + label: "Download as SVG", + onPressed: () async { + getMonkeySVG(receivingAddress); + }, + ), + const SizedBox(height: 12), + SecondaryButton( + label: "Download as PNG", + onPressed: () { + getMonkeyPNG(receivingAddress); + }, + ), + ], + ), + ), + // child, + ], + ), + child: Column( + children: [ + const Spacer( + flex: 4, + ), + Center( + child: Column( + children: [ + Opacity( + opacity: 0.2, + child: SvgPicture.file( + File( + ref.watch(coinIconProvider(coin)), + ), + width: 200, + height: 200, ), - width: 200, - height: 200, ), - ), - const SizedBox( - height: 40, - ), - Text( - "You do not have a MonKey yet. \nFetch yours now!", - style: STextStyles.smallMed14(context).copyWith( - color: Theme.of(context) - .extension()! - .textDark3, + const SizedBox( + height: 40, ), - textAlign: TextAlign.center, - ), - ], + Text( + "You do not have a MonKey yet. \nFetch yours now!", + style: STextStyles.smallMed14(context).copyWith( + color: Theme.of(context) + .extension()! + .textDark3, + ), + textAlign: TextAlign.center, + ), + ], + ), ), - ), - const Spacer( - flex: 6, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: PrimaryButton( - label: "Fetch MonKey", - onPressed: () async { - showDialog( - context: context, - useSafeArea: false, - barrierDismissible: false, - builder: (context) { - return FetchMonkeyDialog( - onCancel: () async { - Navigator.of(context).pop(); - }, - ); - }, - ); - - await Future.delayed(const Duration(seconds: 2)); - - Navigator.of(context).pushNamed( - MonkeyLoadedView.routeName, - arguments: Tuple2( - widget.walletId, - widget.managerProvider, - ), - ); - }, + const Spacer( + flex: 6, ), - ), - ], + Padding( + padding: const EdgeInsets.all(16.0), + child: PrimaryButton( + label: "Fetch MonKey", + onPressed: () async { + getMonkeyImage(receivingAddress); + + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: false, + builder: (context) { + return FetchMonkeyDialog( + onCancel: () async { + Navigator.of(context).pop(); + }, + ); + }, + ); + + await Future.delayed(const Duration(seconds: 2)); + + Navigator.of(context).popUntil( + ModalRoute.withName(WalletView.routeName), + ); + }, + ), + ), + ], + ), ), ), ], diff --git a/lib/route_generator.dart b/lib/route_generator.dart index b02638082..64c2c86d4 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -56,7 +56,6 @@ import 'package:stackwallet/pages/generic/single_field_edit_view.dart'; import 'package:stackwallet/pages/home_view/home_view.dart'; import 'package:stackwallet/pages/intro_view.dart'; import 'package:stackwallet/pages/manage_favorites_view/manage_favorites_view.dart'; -import 'package:stackwallet/pages/monkey/monkey_loaded_view.dart'; import 'package:stackwallet/pages/monkey/monkey_view.dart'; import 'package:stackwallet/pages/notification_views/notifications_view.dart'; import 'package:stackwallet/pages/paynym/add_new_paynym_follow_view.dart'; @@ -392,20 +391,20 @@ class RouteGenerator { } return _routeError("${settings.name} invalid args: ${args.toString()}"); - case MonkeyLoadedView.routeName: - if (args is Tuple2>) { - return getRoute( - shouldUseMaterialRoute: useMaterialPageRoute, - builder: (_) => MonkeyLoadedView( - walletId: args.item1, - managerProvider: args.item2, - ), - settings: RouteSettings( - name: settings.name, - ), - ); - } - return _routeError("${settings.name} invalid args: ${args.toString()}"); + // case MonkeyLoadedView.routeName: + // if (args is Tuple2>) { + // return getRoute( + // shouldUseMaterialRoute: useMaterialPageRoute, + // builder: (_) => MonkeyLoadedView( + // walletId: args.item1, + // managerProvider: args.item2, + // ), + // settings: RouteSettings( + // name: settings.name, + // ), + // ); + // } + // return _routeError("${settings.name} invalid args: ${args.toString()}"); case CoinControlView.routeName: if (args is Tuple2) { From 86d3258910f3d138d3859159d344a6a888258165 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 13:18:18 -0600 Subject: [PATCH 13/26] Monkey help message --- crypto_plugins/flutter_libmonero | 2 +- lib/pages/monkey/monkey_view.dart | 33 +++--------------- lib/pages/wallet_view/wallet_view.dart | 46 +++++++++++--------------- 3 files changed, 25 insertions(+), 56 deletions(-) diff --git a/crypto_plugins/flutter_libmonero b/crypto_plugins/flutter_libmonero index e48952185..407425c9f 160000 --- a/crypto_plugins/flutter_libmonero +++ b/crypto_plugins/flutter_libmonero @@ -1 +1 @@ -Subproject commit e48952185556a10f182184fd572bcb04365f5831 +Subproject commit 407425c9fcf7a30c81f1345246c7225bc18b5cd5 diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index b631b0703..075191235 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -22,6 +22,7 @@ import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; +import 'package:stackwallet/widgets/stack_dialog.dart'; class MonkeyView extends ConsumerStatefulWidget { const MonkeyView({ @@ -220,34 +221,10 @@ class _MonkeyViewState extends ConsumerState { useSafeArea: false, barrierDismissible: true, builder: (context) { - return Dialog( - child: Material( - borderRadius: BorderRadius.circular( - 20, - ), - child: Container( - height: 200, - decoration: BoxDecoration( - color: Theme.of(context) - .extension()! - .popupBG, - borderRadius: BorderRadius.circular( - 20, - ), - ), - child: Column( - children: [ - Center( - child: Text( - "Help", - style: STextStyles.pageTitleH2( - context), - ), - ) - ], - ), - ), - ), + return const StackOkDialog( + title: "About MonKeys", + message: + "A MonKey is a visual representation of your Banano address.", ); }); }), diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index 0dcfe18dc..b2d5de8e6 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -925,33 +925,25 @@ class _WalletViewState extends ConsumerState { ); }, ), - if (ref.watch( - walletsChangeNotifierProvider.select( - (value) => value - .getManager(widget.walletId) - .hasCoinControlSupport, - ), - ) && - ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.enableCoinControl, - ), - )) - WalletNavigationBarItemData( - icon: SvgPicture.asset(Assets.svg.monkey, - height: 20, - width: 20, - color: Theme.of(context).extension()!.bottomNavIconIcon,), - label: "MonKey", - onTap: () { - Navigator.of(context).pushNamed( - MonkeyView.routeName, - arguments: Tuple2( - widget.walletId, - widget.managerProvider, - ), - ); - }), + WalletNavigationBarItemData( + icon: SvgPicture.asset( + Assets.svg.monkey, + height: 20, + width: 20, + color: Theme.of(context) + .extension()! + .bottomNavIconIcon, + ), + label: "MonKey", + onTap: () { + Navigator.of(context).pushNamed( + MonkeyView.routeName, + arguments: Tuple2( + widget.walletId, + widget.managerProvider, + ), + ); + }), if (ref.watch( walletsChangeNotifierProvider.select( (value) => value From 3cb8a6a173d834e633969ab0f4035918b0aed72f Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 14:12:06 -0600 Subject: [PATCH 14/26] WIP: adding monkey to desktop --- .../sub_widgets/desktop_wallet_features.dart | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart index aa5922959..1ee1b664b 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart @@ -16,6 +16,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/notifications/show_flush_bar.dart'; +import 'package:stackwallet/pages/monkey/monkey_view.dart'; import 'package:stackwallet/pages/paynym/paynym_claim_view.dart'; import 'package:stackwallet/pages/paynym/paynym_home_view.dart'; import 'package:stackwallet/pages_desktop_specific/coin_control/desktop_coin_control_view.dart'; @@ -41,6 +42,7 @@ import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/loading_indicator.dart'; +import 'package:tuple/tuple.dart'; class DesktopWalletFeatures extends ConsumerStatefulWidget { const DesktopWalletFeatures({ @@ -80,6 +82,7 @@ class _DesktopWalletFeaturesState extends ConsumerState { onCoinControlPressed: _onCoinControlPressed, onAnonymizeAllPressed: _onAnonymizeAllPressed, onWhirlpoolPressed: _onWhirlpoolPressed, + onMonkeyPressed: _onMonkeyPressed, ), ); } @@ -313,6 +316,21 @@ class _DesktopWalletFeaturesState extends ConsumerState { } } + Future _onMonkeyPressed() async { + Navigator.of(context, rootNavigator: true).pop(); + final managerProvider = ref + .read(walletsChangeNotifierProvider) + .getManagerProvider(widget.walletId); + + await (Navigator.of(context).pushNamed( + MonkeyView.routeName, + arguments: Tuple2( + widget.walletId, + managerProvider, + ), + )); + } + @override Widget build(BuildContext context) { final manager = ref.watch( @@ -330,8 +348,8 @@ class _DesktopWalletFeaturesState extends ConsumerState { )) || manager.coin == Coin.firo || manager.coin == Coin.firoTestNet || + manager.coin == Coin.banano || manager.hasWhirlpoolSupport; - return Row( children: [ if (Constants.enableExchange) From 5668b045e5ec63a72526263eb408d996758ab21e Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 14:12:19 -0600 Subject: [PATCH 15/26] WIP: adding monkey to desktop --- .../sub_widgets/more_features/more_features_dialog.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/more_features/more_features_dialog.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/more_features/more_features_dialog.dart index 4c8f47c25..3aaa6b5df 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/more_features/more_features_dialog.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/more_features/more_features_dialog.dart @@ -29,6 +29,7 @@ class MoreFeaturesDialog extends ConsumerStatefulWidget { required this.onCoinControlPressed, required this.onAnonymizeAllPressed, required this.onWhirlpoolPressed, + required this.onMonkeyPressed, }) : super(key: key); final String walletId; @@ -36,6 +37,7 @@ class MoreFeaturesDialog extends ConsumerStatefulWidget { final VoidCallback? onCoinControlPressed; final VoidCallback? onAnonymizeAllPressed; final VoidCallback? onWhirlpoolPressed; + final VoidCallback? onMonkeyPressed; @override ConsumerState createState() => _MoreFeaturesDialogState(); @@ -103,6 +105,13 @@ class _MoreFeaturesDialogState extends ConsumerState { iconAsset: Assets.svg.robotHead, onPressed: () => widget.onPaynymPressed?.call(), ), + if (manager.coin == Coin.banano) + _MoreFeaturesItem( + label: "MonKey", + detail: "Generate Banano MonKey", + iconAsset: Assets.svg.monkey, + onPressed: () => widget.onMonkeyPressed?.call(), + ), const SizedBox( height: 28, ), From 66e1db9b52021689ce208b86c593c9cf96d0daa1 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 15:10:53 -0600 Subject: [PATCH 16/26] WIP: scaling monkey view for desktop --- lib/pages/monkey/monkey_view.dart | 315 ++++++++++++++++++++---------- 1 file changed, 207 insertions(+), 108 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 075191235..83901fbca 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -9,6 +9,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; +import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/services/coins/banano/banano_wallet.dart'; import 'package:stackwallet/services/coins/manager.dart'; @@ -17,6 +18,7 @@ import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -24,6 +26,9 @@ import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; +import '../../widgets/desktop/desktop_app_bar.dart'; +import '../../widgets/desktop/desktop_scaffold.dart'; + class MonkeyView extends ConsumerStatefulWidget { const MonkeyView({ Key? key, @@ -193,25 +198,57 @@ class _MonkeyViewState extends ConsumerState { final manager = ref.watch(walletsChangeNotifierProvider .select((value) => value.getManager(widget.walletId))); + final bool isDesktop = Util.isDesktop; + List? imageBytes; imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes(); + //edit for desktop return Background( child: Stack( children: [ - Scaffold( - appBar: AppBar( - leading: AppBarBackButton( - onPressed: () { - Navigator.of(context).pop(); - }, - ), - title: Text( - "MonKey", - style: STextStyles.navBarTitle(context), - ), - actions: [ - AspectRatio( + ConditionalParent( + condition: isDesktop, + builder: (child) => DesktopScaffold( + appBar: DesktopAppBar( + background: Theme.of(context).extension()!.popupBG, + leading: Expanded( + child: Row( + children: [ + const SizedBox( + width: 32, + ), + AppBarIconButton( + size: 32, + color: Theme.of(context) + .extension()! + .textFieldDefaultBG, + shadows: const [], + icon: SvgPicture.asset( + Assets.svg.arrowLeft, + width: 18, + height: 18, + color: Theme.of(context) + .extension()! + .topNavIconPrimary, + ), + onPressed: () { + if (mounted) { + Navigator.of(context).pop(); + } + }, + ), + const SizedBox( + width: 15, + ), + Text( + "MonKey", + style: STextStyles.navBarTitle(context), + ), + ], + ), + ), + trailing: AspectRatio( aspectRatio: 1, child: AppBarIconButton( icon: SvgPicture.asset(Assets.svg.circleQuestion), @@ -221,7 +258,7 @@ class _MonkeyViewState extends ConsumerState { useSafeArea: false, barrierDismissible: true, builder: (context) { - return const StackOkDialog( + return const StackDialog( title: "About MonKeys", message: "A MonKey is a visual representation of your Banano address.", @@ -229,112 +266,174 @@ class _MonkeyViewState extends ConsumerState { }); }), ), - ], - ), - body: ConditionalParent( - condition: imageBytes != null, - builder: (child) => Column( - children: [ - const Spacer( - flex: 1, - ), - if (imageBytes != null) - Container( - child: SvgPicture.memory(Uint8List.fromList(imageBytes!)), - width: 300, - height: 300, - ), - const Spacer( - flex: 1, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - SecondaryButton( - label: "Download as SVG", - onPressed: () async { - getMonkeySVG(receivingAddress); - }, - ), - const SizedBox(height: 12), - SecondaryButton( - label: "Download as PNG", - onPressed: () { - getMonkeyPNG(receivingAddress); - }, - ), - ], - ), - ), - // child, - ], + useSpacers: false, + isCompactHeight: true, ), - child: Column( - children: [ - const Spacer( - flex: 4, + body: child, + ), + child: ConditionalParent( + condition: !isDesktop, + builder: (child) => Scaffold( + appBar: AppBar( + leading: AppBarBackButton( + onPressed: () { + Navigator.of(context).pop(); + }, ), - Center( - child: Column( - children: [ - Opacity( - opacity: 0.2, - child: SvgPicture.file( - File( - ref.watch(coinIconProvider(coin)), - ), - width: 200, - height: 200, - ), - ), - const SizedBox( - height: 40, - ), - Text( - "You do not have a MonKey yet. \nFetch yours now!", - style: STextStyles.smallMed14(context).copyWith( + title: Text( + "MonKey", + style: STextStyles.navBarTitle(context), + ), + actions: [ + AspectRatio( + aspectRatio: 1, + child: AppBarIconButton( + icon: SvgPicture.asset( + Assets.svg.circleQuestion, color: Theme.of(context) .extension()! - .textDark3, + .infoItemText, ), - textAlign: TextAlign.center, - ), - ], + onPressed: () { + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return const StackOkDialog( + title: "About MonKeys", + message: + "A MonKey is a visual representation of your Banano address.", + ); + }); + }), ), + ], + ), + body: child, + ), + child: ConditionalParent( + condition: isDesktop, + builder: (child) => SizedBox( + width: 300, + height: 300, + child: child, + ), + child: ConditionalParent( + condition: imageBytes != null, + builder: (child) => Column( + children: [ + const Spacer( + flex: 1, + ), + if (imageBytes != null) + Container( + child: SvgPicture.memory( + Uint8List.fromList(imageBytes!)), + width: 300, + height: 300, + ), + const Spacer( + flex: 1, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + SecondaryButton( + label: "Download as SVG", + onPressed: () async { + getMonkeySVG(receivingAddress); + }, + ), + const SizedBox(height: 12), + SecondaryButton( + label: "Download as PNG", + onPressed: () { + getMonkeyPNG(receivingAddress); + }, + ), + ], + ), + ), + // child, + ], ), - const Spacer( - flex: 6, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: PrimaryButton( - label: "Fetch MonKey", - onPressed: () async { - getMonkeyImage(receivingAddress); + child: Column( + children: [ + const Spacer( + flex: 4, + ), + Center( + child: Column( + children: [ + Opacity( + opacity: 0.2, + child: SvgPicture.file( + File( + ref.watch(coinIconProvider(coin)), + ), + width: 200, + height: 200, + ), + ), + const SizedBox( + height: 40, + ), + Text( + "You do not have a MonKey yet. \nFetch yours now!", + style: STextStyles.smallMed14(context).copyWith( + color: Theme.of(context) + .extension()! + .textDark3, + ), + textAlign: TextAlign.center, + ), + ], + ), + ), + const Spacer( + flex: 6, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: PrimaryButton( + label: "Fetch MonKey", + onPressed: () async { + getMonkeyImage(receivingAddress); - showDialog( - context: context, - useSafeArea: false, - barrierDismissible: false, - builder: (context) { - return FetchMonkeyDialog( - onCancel: () async { - Navigator.of(context).pop(); + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: false, + builder: (context) { + return FetchMonkeyDialog( + onCancel: () async { + Navigator.of(context).pop(); + }, + ); }, ); + + await Future.delayed( + const Duration(seconds: 2)); + + if (isDesktop) { + Navigator.of(context).popUntil( + ModalRoute.withName( + DesktopWalletView.routeName), + ); + } else { + Navigator.of(context).popUntil( + ModalRoute.withName(WalletView.routeName), + ); + } }, - ); - - await Future.delayed(const Duration(seconds: 2)); - - Navigator.of(context).popUntil( - ModalRoute.withName(WalletView.routeName), - ); - }, - ), + ), + ), + ], ), - ], + ), ), ), ), From b2aa4272b445433bff9dd5232a675d4934e616ce Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 26 Jul 2023 15:32:00 -0600 Subject: [PATCH 17/26] reorg and loading indicator --- lib/pages/monkey/monkey_view.dart | 66 ++++++++----------- .../sub_widgets/desktop_wallet_features.dart | 9 +-- lib/route_generator.dart | 5 +- 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 83901fbca..ce4e951d3 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -7,40 +7,34 @@ import 'package:flutter_svg/svg.dart'; import 'package:http/http.dart' as http; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; -import 'package:stackwallet/pages/monkey/sub_widgets/fetch_monkey_dialog.dart'; -import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; -import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/services/coins/banano/banano_wallet.dart'; -import 'package:stackwallet/services/coins/manager.dart'; import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/show_loading.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; +import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart'; +import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; -import '../../widgets/desktop/desktop_app_bar.dart'; -import '../../widgets/desktop/desktop_scaffold.dart'; - class MonkeyView extends ConsumerStatefulWidget { const MonkeyView({ Key? key, required this.walletId, - required this.managerProvider, }) : super(key: key); static const String routeName = "/monkey"; static const double navBarHeight = 65.0; final String walletId; - final ChangeNotifierProvider managerProvider; @override ConsumerState createState() => _MonkeyViewState(); @@ -48,23 +42,21 @@ class MonkeyView extends ConsumerStatefulWidget { class _MonkeyViewState extends ConsumerState { late final String walletId; - late final ChangeNotifierProvider managerProvider; String receivingAddress = ""; - void getMonkeyImage(String address) async { + Future getMonkeyImage(String address) async { if (address.isEmpty) { //address shouldn't be empty return; } - final manager = ref.watch(walletsChangeNotifierProvider - .select((value) => value.getManager(walletId))); - final http.Response response = await http .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); if (response.statusCode == 200) { + final manager = + ref.read(walletsChangeNotifierProvider).getManager(walletId); final decodedResponse = response.bodyBytes; await (manager.wallet as BananoWallet) .updateMonkeyImageBytes(decodedResponse); @@ -172,7 +164,6 @@ class _MonkeyViewState extends ConsumerState { @override void initState() { walletId = widget.walletId; - managerProvider = widget.managerProvider; WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { final address = await ref @@ -194,9 +185,9 @@ class _MonkeyViewState extends ConsumerState { @override Widget build(BuildContext context) { - final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); final manager = ref.watch(walletsChangeNotifierProvider .select((value) => value.getManager(widget.walletId))); + final Coin coin = manager.coin; final bool isDesktop = Util.isDesktop; @@ -400,34 +391,29 @@ class _MonkeyViewState extends ConsumerState { child: PrimaryButton( label: "Fetch MonKey", onPressed: () async { - getMonkeyImage(receivingAddress); + final future = Future.wait([ + getMonkeyImage(receivingAddress), + Future.delayed(const Duration(seconds: 2)), + ]); - showDialog( + await showLoading( + whileFuture: future, context: context, - useSafeArea: false, - barrierDismissible: false, - builder: (context) { - return FetchMonkeyDialog( - onCancel: () async { - Navigator.of(context).pop(); - }, - ); - }, + isDesktop: Util.isDesktop, + message: "Fetching MonKey", + subMessage: "We are fetching your MonKey", ); - await Future.delayed( - const Duration(seconds: 2)); - - if (isDesktop) { - Navigator.of(context).popUntil( - ModalRoute.withName( - DesktopWalletView.routeName), - ); - } else { - Navigator.of(context).popUntil( - ModalRoute.withName(WalletView.routeName), - ); - } + // if (isDesktop) { + // Navigator.of(context).popUntil( + // ModalRoute.withName( + // DesktopWalletView.routeName), + // ); + // } else { + // Navigator.of(context).popUntil( + // ModalRoute.withName(WalletView.routeName), + // ); + // } }, ), ), diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart index 1ee1b664b..afeec5094 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart @@ -42,7 +42,6 @@ import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/loading_indicator.dart'; -import 'package:tuple/tuple.dart'; class DesktopWalletFeatures extends ConsumerStatefulWidget { const DesktopWalletFeatures({ @@ -318,16 +317,10 @@ class _DesktopWalletFeaturesState extends ConsumerState { Future _onMonkeyPressed() async { Navigator.of(context, rootNavigator: true).pop(); - final managerProvider = ref - .read(walletsChangeNotifierProvider) - .getManagerProvider(widget.walletId); await (Navigator.of(context).pushNamed( MonkeyView.routeName, - arguments: Tuple2( - widget.walletId, - managerProvider, - ), + arguments: widget.walletId, )); } diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 368d23397..edd3b15fc 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -378,12 +378,11 @@ class RouteGenerator { return _routeError("${settings.name} invalid args: ${args.toString()}"); case MonkeyView.routeName: - if (args is Tuple2>) { + if (args is String) { return getRoute( shouldUseMaterialRoute: useMaterialPageRoute, builder: (_) => MonkeyView( - walletId: args.item1, - managerProvider: args.item2, + walletId: args, ), settings: RouteSettings( name: settings.name, From 4e9ba505723970d216cbbc6f2392cfaad59cd9bd Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 15:37:10 -0600 Subject: [PATCH 18/26] Desktop what is monkey button --- lib/pages/monkey/monkey_view.dart | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index ce4e951d3..07466fe1b 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -239,11 +239,12 @@ class _MonkeyViewState extends ConsumerState { ], ), ), - trailing: AspectRatio( - aspectRatio: 1, - child: AppBarIconButton( - icon: SvgPicture.asset(Assets.svg.circleQuestion), - onPressed: () { + trailing: Padding( + padding: const EdgeInsets.all(8.0), + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: () { showDialog( context: context, useSafeArea: false, @@ -255,7 +256,30 @@ class _MonkeyViewState extends ConsumerState { "A MonKey is a visual representation of your Banano address.", ); }); - }), + }, + child: Row( + children: [ + SvgPicture.asset( + Assets.svg.circleQuestion, + color: Colors.blue[800], + ), + SizedBox( + width: 6, + ), + Padding( + padding: const EdgeInsets.only(bottom: 8.0), + child: Text( + "What is MonKey?", + style: STextStyles.desktopTextSmall(context) + .copyWith( + color: Colors.blue[800], + ), + ), + ), + ], + ), + ), + ), ), useSpacers: false, isCompactHeight: true, @@ -281,9 +305,6 @@ class _MonkeyViewState extends ConsumerState { child: AppBarIconButton( icon: SvgPicture.asset( Assets.svg.circleQuestion, - color: Theme.of(context) - .extension()! - .infoItemText, ), onPressed: () { showDialog( @@ -403,7 +424,6 @@ class _MonkeyViewState extends ConsumerState { message: "Fetching MonKey", subMessage: "We are fetching your MonKey", ); - // if (isDesktop) { // Navigator.of(context).popUntil( // ModalRoute.withName( From 0175939d6383526b55f8bb80e84ef7ff6a34d363 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 26 Jul 2023 15:52:52 -0600 Subject: [PATCH 19/26] download/save image on linux --- lib/pages/monkey/monkey_view.dart | 170 +++++++++++++++++------------- 1 file changed, 96 insertions(+), 74 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index ce4e951d3..56cd8cf1d 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -65,60 +65,73 @@ class _MonkeyViewState extends ConsumerState { } } - void getMonkeySVG(String address) async { - if (address.isEmpty) { - //address shouldn't be empty - return; - } + // void getMonkeySVG(String address) async { + // if (address.isEmpty) { + // //address shouldn't be empty + // return; + // } + // + // final http.Response response = await http + // .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); + // + // if (response.statusCode == 200) { + // final decodedResponse = response.bodyBytes; + // Directory directory = await getApplicationDocumentsDirectory(); + // late Directory sampleFolder; + // + // if (Platform.isAndroid) { + // directory = Directory("/storage/emulated/0/"); + // sampleFolder = Directory('${directory!.path}Documents'); + // } else if (Platform.isIOS) { + // sampleFolder = Directory(directory!.path); + // } else if (Platform.isLinux) { + // sampleFolder = Directory('${directory!.path}Documents'); + // } else if (Platform.isWindows) { + // sampleFolder = Directory('${directory!.path}Documents'); + // } else if (Platform.isMacOS) { + // sampleFolder = Directory('${directory!.path}Documents'); + // } + // + // try { + // if (!sampleFolder.existsSync()) { + // sampleFolder.createSync(recursive: true); + // } + // } catch (e, s) { + // // todo: come back to this + // debugPrint("$e $s"); + // } + // + // final docPath = sampleFolder.path; + // final filePath = "$docPath/monkey.svg"; + // + // File imgFile = File(filePath); + // await imgFile.writeAsBytes(decodedResponse); + // } else { + // throw Exception("Failed to get MonKey"); + // } + // } - final http.Response response = await http - .get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address')); - - if (response.statusCode == 200) { - final decodedResponse = response.bodyBytes; - Directory directory = await getApplicationDocumentsDirectory(); - late Directory sampleFolder; - - if (Platform.isAndroid) { - directory = Directory("/storage/emulated/0/"); - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isIOS) { - sampleFolder = Directory(directory!.path); - } else if (Platform.isLinux) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isWindows) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isMacOS) { - sampleFolder = Directory('${directory!.path}Documents'); - } - - try { - if (!sampleFolder.existsSync()) { - sampleFolder.createSync(recursive: true); - } - } catch (e, s) { - // todo: come back to this - debugPrint("$e $s"); - } - - final docPath = sampleFolder.path; - final filePath = "$docPath/monkey.svg"; - - File imgFile = File(filePath); - await imgFile.writeAsBytes(decodedResponse); - } else { - throw Exception("Failed to get MonKey"); + Future getDocsDir() async { + try { + return await getApplicationDocumentsDirectory(); + } catch (_) { + return null; } } - void getMonkeyPNG(String address) async { + Future downloadMonkey(String address, bool isPNG) async { if (address.isEmpty) { //address shouldn't be empty return; } - final http.Response response = await http.get(Uri.parse( - 'https://monkey.banano.cc/api/v1/monkey/${address}?format=png&size=512&background=false')); + String url = "https://monkey.banano.cc/api/v1/monkey/$address"; + + if (isPNG) { + url += '?format=png&size=512&background=false'; + } + + final http.Response response = await http.get(Uri.parse(url)); if (response.statusCode == 200) { if (Platform.isAndroid) { @@ -126,33 +139,30 @@ class _MonkeyViewState extends ConsumerState { } final decodedResponse = response.bodyBytes; - Directory directory = await getApplicationDocumentsDirectory(); - late Directory sampleFolder; + final Directory? sampleFolder = await getDocsDir(); - if (Platform.isAndroid) { - directory = Directory("/storage/emulated/0/"); - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isIOS) { - sampleFolder = Directory(directory!.path); - } else if (Platform.isLinux) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isWindows) { - sampleFolder = Directory('${directory!.path}Documents'); - } else if (Platform.isMacOS) { - sampleFolder = Directory('${directory!.path}Documents'); + print("PATH: ${sampleFolder?.path}"); + + if (sampleFolder == null) { + print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + return; } - try { - if (!sampleFolder.existsSync()) { - sampleFolder.createSync(recursive: true); - } - } catch (e, s) { - // todo: come back to this - debugPrint("$e $s"); - } + // try { + // if (!sampleFolder.existsSync()) { + // sampleFolder.createSync(recursive: true); + // } + // } catch (e, s) { + // // todo: come back to this + // debugPrint("$e $s"); + // } final docPath = sampleFolder.path; - final filePath = "$docPath/monkey.png"; + String filePath = "$docPath/monkey_$address"; + + filePath += isPNG ? ".png" : ".svg"; + + // todo check if monkey.png exists File imgFile = File(filePath); await imgFile.writeAsBytes(decodedResponse); @@ -318,11 +328,11 @@ class _MonkeyViewState extends ConsumerState { flex: 1, ), if (imageBytes != null) - Container( - child: SvgPicture.memory( - Uint8List.fromList(imageBytes!)), + SizedBox( width: 300, height: 300, + child: + SvgPicture.memory(Uint8List.fromList(imageBytes)), ), const Spacer( flex: 1, @@ -332,16 +342,28 @@ class _MonkeyViewState extends ConsumerState { child: Column( children: [ SecondaryButton( - label: "Download as SVG", + label: "Save as SVG", onPressed: () async { - getMonkeySVG(receivingAddress); + await showLoading( + whileFuture: + downloadMonkey(receivingAddress, false), + context: context, + isDesktop: Util.isDesktop, + message: "Saving MonKey svg", + ); }, ), const SizedBox(height: 12), SecondaryButton( label: "Download as PNG", - onPressed: () { - getMonkeyPNG(receivingAddress); + onPressed: () async { + await showLoading( + whileFuture: + downloadMonkey(receivingAddress, true), + context: context, + isDesktop: Util.isDesktop, + message: "Downloading MonKey png", + ); }, ), ], From 39882b0d46bf37d15f05ceb84f60da41aaa1997b Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 16:07:54 -0600 Subject: [PATCH 20/26] monkey icon in app bar --- lib/pages/monkey/monkey_view.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 07466fe1b..940b41fa4 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -232,6 +232,10 @@ class _MonkeyViewState extends ConsumerState { const SizedBox( width: 15, ), + SvgPicture.asset(Assets.svg.monkey), + const SizedBox( + width: 12, + ), Text( "MonKey", style: STextStyles.navBarTitle(context), From 9d2b315bd9a6af38a47addd5f3c3853e79ce5401 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 26 Jul 2023 16:08:01 -0600 Subject: [PATCH 21/26] desktop layout --- lib/pages/monkey/monkey_view.dart | 428 +++++++++++++++--------------- 1 file changed, 219 insertions(+), 209 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 56cd8cf1d..02947a5ce 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -206,60 +206,100 @@ class _MonkeyViewState extends ConsumerState { //edit for desktop return Background( - child: Stack( - children: [ - ConditionalParent( - condition: isDesktop, - builder: (child) => DesktopScaffold( - appBar: DesktopAppBar( - background: Theme.of(context).extension()!.popupBG, - leading: Expanded( - child: Row( - children: [ - const SizedBox( - width: 32, - ), - AppBarIconButton( - size: 32, - color: Theme.of(context) - .extension()! - .textFieldDefaultBG, - shadows: const [], - icon: SvgPicture.asset( - Assets.svg.arrowLeft, - width: 18, - height: 18, - color: Theme.of(context) - .extension()! - .topNavIconPrimary, - ), - onPressed: () { - if (mounted) { - Navigator.of(context).pop(); - } - }, - ), - const SizedBox( - width: 15, - ), - Text( - "MonKey", - style: STextStyles.navBarTitle(context), - ), - ], + child: ConditionalParent( + condition: isDesktop, + builder: (child) => DesktopScaffold( + appBar: DesktopAppBar( + background: Theme.of(context).extension()!.popupBG, + leading: Expanded( + child: Row( + children: [ + const SizedBox( + width: 32, ), - ), - trailing: AspectRatio( + AppBarIconButton( + size: 32, + color: Theme.of(context) + .extension()! + .textFieldDefaultBG, + shadows: const [], + icon: SvgPicture.asset( + Assets.svg.arrowLeft, + width: 18, + height: 18, + color: Theme.of(context) + .extension()! + .topNavIconPrimary, + ), + onPressed: () { + if (mounted) { + Navigator.of(context).pop(); + } + }, + ), + const SizedBox( + width: 15, + ), + Text( + "MonKey", + style: STextStyles.navBarTitle(context), + ), + ], + ), + ), + trailing: AspectRatio( + aspectRatio: 1, + child: AppBarIconButton( + icon: SvgPicture.asset(Assets.svg.circleQuestion), + onPressed: () { + showDialog( + context: context, + useSafeArea: false, + barrierDismissible: true, + builder: (context) { + return const StackDialog( + title: "About MonKeys", + message: + "A MonKey is a visual representation of your Banano address.", + ); + }); + }), + ), + useSpacers: false, + isCompactHeight: true, + ), + body: child, + ), + child: ConditionalParent( + condition: !isDesktop, + builder: (child) => Scaffold( + appBar: AppBar( + leading: AppBarBackButton( + onPressed: () { + Navigator.of(context).pop(); + }, + ), + title: Text( + "MonKey", + style: STextStyles.navBarTitle(context), + ), + actions: [ + AspectRatio( aspectRatio: 1, child: AppBarIconButton( - icon: SvgPicture.asset(Assets.svg.circleQuestion), + icon: SvgPicture.asset( + Assets.svg.circleQuestion, + color: Theme.of(context) + .extension()! + .infoItemText, + ), onPressed: () { showDialog( context: context, useSafeArea: false, barrierDismissible: true, builder: (context) { - return const StackDialog( + return const StackOkDialog( title: "About MonKeys", message: "A MonKey is a visual representation of your Banano address.", @@ -267,185 +307,155 @@ class _MonkeyViewState extends ConsumerState { }); }), ), - useSpacers: false, - isCompactHeight: true, - ), - body: child, + ], + ), + body: child, + ), + child: ConditionalParent( + condition: isDesktop, + builder: (child) => SizedBox( + width: 318, + child: child, ), child: ConditionalParent( - condition: !isDesktop, - builder: (child) => Scaffold( - appBar: AppBar( - leading: AppBarBackButton( - onPressed: () { - Navigator.of(context).pop(); - }, - ), - title: Text( - "MonKey", - style: STextStyles.navBarTitle(context), - ), - actions: [ - AspectRatio( - aspectRatio: 1, - child: AppBarIconButton( - icon: SvgPicture.asset( - Assets.svg.circleQuestion, - color: Theme.of(context) - .extension()! - .infoItemText, - ), - onPressed: () { - showDialog( - context: context, - useSafeArea: false, - barrierDismissible: true, - builder: (context) { - return const StackOkDialog( - title: "About MonKeys", - message: - "A MonKey is a visual representation of your Banano address.", - ); - }); - }), + condition: imageBytes != null, + builder: (_) => Column( + children: [ + isDesktop + ? const SizedBox( + height: 50, + ) + : const Spacer( + flex: 1, + ), + if (imageBytes != null) + SizedBox( + width: 300, + height: 300, + child: SvgPicture.memory(Uint8List.fromList(imageBytes)), ), - ], - ), - body: child, - ), - child: ConditionalParent( - condition: isDesktop, - builder: (child) => SizedBox( - width: 300, - height: 300, - child: child, - ), - child: ConditionalParent( - condition: imageBytes != null, - builder: (child) => Column( - children: [ - const Spacer( - flex: 1, - ), - if (imageBytes != null) - SizedBox( - width: 300, - height: 300, - child: - SvgPicture.memory(Uint8List.fromList(imageBytes)), + isDesktop + ? const SizedBox( + height: 50, + ) + : const Spacer( + flex: 1, ), - const Spacer( - flex: 1, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - SecondaryButton( - label: "Save as SVG", - onPressed: () async { - await showLoading( - whileFuture: - downloadMonkey(receivingAddress, false), - context: context, - isDesktop: Util.isDesktop, - message: "Saving MonKey svg", - ); - }, - ), - const SizedBox(height: 12), - SecondaryButton( - label: "Download as PNG", - onPressed: () async { - await showLoading( - whileFuture: - downloadMonkey(receivingAddress, true), - context: context, - isDesktop: Util.isDesktop, - message: "Downloading MonKey png", - ); - }, - ), - ], - ), - ), - // child, - ], - ), - child: Column( - children: [ - const Spacer( - flex: 4, - ), - Center( - child: Column( - children: [ - Opacity( - opacity: 0.2, - child: SvgPicture.file( - File( - ref.watch(coinIconProvider(coin)), - ), - width: 200, - height: 200, - ), - ), - const SizedBox( - height: 40, - ), - Text( - "You do not have a MonKey yet. \nFetch yours now!", - style: STextStyles.smallMed14(context).copyWith( - color: Theme.of(context) - .extension()! - .textDark3, - ), - textAlign: TextAlign.center, - ), - ], - ), - ), - const Spacer( - flex: 6, - ), - Padding( - padding: const EdgeInsets.all(16.0), - child: PrimaryButton( - label: "Fetch MonKey", + Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + SecondaryButton( + label: "Save as SVG", onPressed: () async { - final future = Future.wait([ - getMonkeyImage(receivingAddress), - Future.delayed(const Duration(seconds: 2)), - ]); - await showLoading( - whileFuture: future, + whileFuture: + downloadMonkey(receivingAddress, false), context: context, isDesktop: Util.isDesktop, - message: "Fetching MonKey", - subMessage: "We are fetching your MonKey", + message: "Saving MonKey svg", ); - - // if (isDesktop) { - // Navigator.of(context).popUntil( - // ModalRoute.withName( - // DesktopWalletView.routeName), - // ); - // } else { - // Navigator.of(context).popUntil( - // ModalRoute.withName(WalletView.routeName), - // ); - // } }, ), - ), - ], + const SizedBox(height: 12), + SecondaryButton( + label: "Download as PNG", + onPressed: () async { + await showLoading( + whileFuture: + downloadMonkey(receivingAddress, true), + context: context, + isDesktop: Util.isDesktop, + message: "Downloading MonKey png", + ); + }, + ), + ], + ), ), - ), + // child, + ], + ), + child: Column( + children: [ + isDesktop + ? const SizedBox( + height: 100, + ) + : const Spacer( + flex: 4, + ), + Center( + child: Column( + children: [ + Opacity( + opacity: 0.2, + child: SvgPicture.file( + File( + ref.watch(coinIconProvider(coin)), + ), + width: 200, + height: 200, + ), + ), + const SizedBox( + height: 70, + ), + Text( + "You do not have a MonKey yet. \nFetch yours now!", + style: STextStyles.smallMed14(context).copyWith( + color: Theme.of(context) + .extension()! + .textDark3, + ), + textAlign: TextAlign.center, + ), + ], + ), + ), + isDesktop + ? const SizedBox( + height: 50, + ) + : const Spacer( + flex: 6, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: PrimaryButton( + label: "Fetch MonKey", + onPressed: () async { + final future = Future.wait([ + getMonkeyImage(receivingAddress), + Future.delayed(const Duration(seconds: 2)), + ]); + + await showLoading( + whileFuture: future, + context: context, + isDesktop: Util.isDesktop, + message: "Fetching MonKey", + subMessage: "We are fetching your MonKey", + ); + + // if (isDesktop) { + // Navigator.of(context).popUntil( + // ModalRoute.withName( + // DesktopWalletView.routeName), + // ); + // } else { + // Navigator.of(context).popUntil( + // ModalRoute.withName(WalletView.routeName), + // ); + // } + }, + ), + ), + ], ), ), ), - ], + ), ), ); } From 2f5a18b61574298b223d5437d19dd4b7bc043db2 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 26 Jul 2023 16:10:27 -0600 Subject: [PATCH 22/26] merge conflict clean things --- lib/pages/monkey/monkey_view.dart | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index c34d4ed95..1dff1fd4d 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -241,9 +241,10 @@ class _MonkeyViewState extends ConsumerState { width: 15, ), SvgPicture.asset(Assets.svg.monkey), - const SizedBox( - width: 12, - ),Text( + const SizedBox( + width: 12, + ), + Text( "MonKey", style: STextStyles.navBarTitle(context), ), @@ -253,8 +254,8 @@ class _MonkeyViewState extends ConsumerState { trailing: Padding( padding: const EdgeInsets.all(8.0), child: MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( + cursor: SystemMouseCursors.click, + child: GestureDetector( onTap: () { showDialog( context: context, @@ -268,28 +269,28 @@ class _MonkeyViewState extends ConsumerState { ); }); }, - child: Row( - children: [ - SvgPicture.asset( - Assets.svg.circleQuestion, + child: Row( + children: [ + SvgPicture.asset( + Assets.svg.circleQuestion, + color: Colors.blue[800], + ), + const SizedBox( + width: 6, + ), + Padding( + padding: const EdgeInsets.only(bottom: 8.0), + child: Text( + "What is MonKey?", + style: STextStyles.desktopTextSmall(context).copyWith( color: Colors.blue[800], ), - SizedBox( - width: 6, - ), - Padding( - padding: const EdgeInsets.only(bottom: 8.0), - child: Text( - "What is MonKey?", - style: STextStyles.desktopTextSmall(context) - .copyWith( - color: Colors.blue[800], - ), - ), - ), - ], + ), ), - ),), + ], + ), + ), + ), ), useSpacers: false, isCompactHeight: true, @@ -315,7 +316,6 @@ class _MonkeyViewState extends ConsumerState { child: AppBarIconButton( icon: SvgPicture.asset( Assets.svg.circleQuestion, - ), onPressed: () { showDialog( From d8e6f3cac691443f4167205a35b8747450282947 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 26 Jul 2023 16:15:29 -0600 Subject: [PATCH 23/26] fix mobile nav error --- lib/pages/wallet_view/wallet_view.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index b2d5de8e6..b3552807f 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -938,10 +938,7 @@ class _WalletViewState extends ConsumerState { onTap: () { Navigator.of(context).pushNamed( MonkeyView.routeName, - arguments: Tuple2( - widget.walletId, - widget.managerProvider, - ), + arguments: widget.walletId, ); }), if (ref.watch( From 8754142694e81e958b25c8e010cfb36661db434b Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 16:21:20 -0600 Subject: [PATCH 24/26] android file path --- lib/pages/monkey/monkey_view.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 1dff1fd4d..554d6d9e0 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -113,6 +113,10 @@ class _MonkeyViewState extends ConsumerState { Future getDocsDir() async { try { + if (Platform.isAndroid) { + return Directory("/storage/emulated/0/"); + } + return await getApplicationDocumentsDirectory(); } catch (_) { return null; From 04b9cddb1994b23208b108f0f73f130298b1c5ab Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Wed, 26 Jul 2023 16:23:34 -0600 Subject: [PATCH 25/26] fixed path --- lib/pages/monkey/monkey_view.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index 554d6d9e0..af2fd91fd 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -114,7 +114,7 @@ class _MonkeyViewState extends ConsumerState { Future getDocsDir() async { try { if (Platform.isAndroid) { - return Directory("/storage/emulated/0/"); + return Directory("/storage/emulated/0/Documents"); } return await getApplicationDocumentsDirectory(); From 7390c498c732f336b7c047827e8c17eb616d1f64 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 26 Jul 2023 16:29:09 -0600 Subject: [PATCH 26/26] set state on download --- lib/pages/monkey/monkey_view.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/pages/monkey/monkey_view.dart b/lib/pages/monkey/monkey_view.dart index af2fd91fd..2ad4b18eb 100644 --- a/lib/pages/monkey/monkey_view.dart +++ b/lib/pages/monkey/monkey_view.dart @@ -42,6 +42,7 @@ class MonkeyView extends ConsumerStatefulWidget { class _MonkeyViewState extends ConsumerState { late final String walletId; + List? imageBytes; String receivingAddress = ""; @@ -205,8 +206,7 @@ class _MonkeyViewState extends ConsumerState { final bool isDesktop = Util.isDesktop; - List? imageBytes; - imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes(); + imageBytes ??= (manager.wallet as BananoWallet).getMonkeyImageBytes(); //edit for desktop return Background( @@ -360,7 +360,7 @@ class _MonkeyViewState extends ConsumerState { SizedBox( width: 300, height: 300, - child: SvgPicture.memory(Uint8List.fromList(imageBytes)), + child: SvgPicture.memory(Uint8List.fromList(imageBytes!)), ), isDesktop ? const SizedBox( @@ -466,6 +466,13 @@ class _MonkeyViewState extends ConsumerState { subMessage: "We are fetching your MonKey", ); + imageBytes = (manager.wallet as BananoWallet) + .getMonkeyImageBytes(); + + if (imageBytes != null) { + setState(() {}); + } + // if (isDesktop) { // Navigator.of(context).popUntil( // ModalRoute.withName(