mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-24 11:15:58 +00:00
reorg and loading indicator
This commit is contained in:
parent
66e1db9b52
commit
b2aa4272b4
3 changed files with 29 additions and 51 deletions
|
@ -7,40 +7,34 @@ import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:permission_handler/permission_handler.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/providers/global/wallets_provider.dart';
|
||||||
import 'package:stackwallet/services/coins/banano/banano_wallet.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/coin_icon_provider.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.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/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/util.dart';
|
import 'package:stackwallet/utilities/util.dart';
|
||||||
import 'package:stackwallet/widgets/background.dart';
|
import 'package:stackwallet/widgets/background.dart';
|
||||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.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/primary_button.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
import 'package:stackwallet/widgets/stack_dialog.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 {
|
class MonkeyView extends ConsumerStatefulWidget {
|
||||||
const MonkeyView({
|
const MonkeyView({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.walletId,
|
required this.walletId,
|
||||||
required this.managerProvider,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
static const String routeName = "/monkey";
|
static const String routeName = "/monkey";
|
||||||
static const double navBarHeight = 65.0;
|
static const double navBarHeight = 65.0;
|
||||||
|
|
||||||
final String walletId;
|
final String walletId;
|
||||||
final ChangeNotifierProvider<Manager> managerProvider;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<MonkeyView> createState() => _MonkeyViewState();
|
ConsumerState<MonkeyView> createState() => _MonkeyViewState();
|
||||||
|
@ -48,23 +42,21 @@ class MonkeyView extends ConsumerStatefulWidget {
|
||||||
|
|
||||||
class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
late final String walletId;
|
late final String walletId;
|
||||||
late final ChangeNotifierProvider<Manager> managerProvider;
|
|
||||||
|
|
||||||
String receivingAddress = "";
|
String receivingAddress = "";
|
||||||
|
|
||||||
void getMonkeyImage(String address) async {
|
Future<void> getMonkeyImage(String address) async {
|
||||||
if (address.isEmpty) {
|
if (address.isEmpty) {
|
||||||
//address shouldn't be empty
|
//address shouldn't be empty
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final manager = ref.watch(walletsChangeNotifierProvider
|
|
||||||
.select((value) => value.getManager(walletId)));
|
|
||||||
|
|
||||||
final http.Response response = await http
|
final http.Response response = await http
|
||||||
.get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address'));
|
.get(Uri.parse('https://monkey.banano.cc/api/v1/monkey/$address'));
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
|
final manager =
|
||||||
|
ref.read(walletsChangeNotifierProvider).getManager(walletId);
|
||||||
final decodedResponse = response.bodyBytes;
|
final decodedResponse = response.bodyBytes;
|
||||||
await (manager.wallet as BananoWallet)
|
await (manager.wallet as BananoWallet)
|
||||||
.updateMonkeyImageBytes(decodedResponse);
|
.updateMonkeyImageBytes(decodedResponse);
|
||||||
|
@ -172,7 +164,6 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
walletId = widget.walletId;
|
walletId = widget.walletId;
|
||||||
managerProvider = widget.managerProvider;
|
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||||
final address = await ref
|
final address = await ref
|
||||||
|
@ -194,9 +185,9 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final Coin coin = ref.watch(managerProvider.select((value) => value.coin));
|
|
||||||
final manager = ref.watch(walletsChangeNotifierProvider
|
final manager = ref.watch(walletsChangeNotifierProvider
|
||||||
.select((value) => value.getManager(widget.walletId)));
|
.select((value) => value.getManager(widget.walletId)));
|
||||||
|
final Coin coin = manager.coin;
|
||||||
|
|
||||||
final bool isDesktop = Util.isDesktop;
|
final bool isDesktop = Util.isDesktop;
|
||||||
|
|
||||||
|
@ -400,34 +391,29 @@ class _MonkeyViewState extends ConsumerState<MonkeyView> {
|
||||||
child: PrimaryButton(
|
child: PrimaryButton(
|
||||||
label: "Fetch MonKey",
|
label: "Fetch MonKey",
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
getMonkeyImage(receivingAddress);
|
final future = Future.wait([
|
||||||
|
getMonkeyImage(receivingAddress),
|
||||||
|
Future<void>.delayed(const Duration(seconds: 2)),
|
||||||
|
]);
|
||||||
|
|
||||||
showDialog<dynamic>(
|
await showLoading(
|
||||||
|
whileFuture: future,
|
||||||
context: context,
|
context: context,
|
||||||
useSafeArea: false,
|
isDesktop: Util.isDesktop,
|
||||||
barrierDismissible: false,
|
message: "Fetching MonKey",
|
||||||
builder: (context) {
|
subMessage: "We are fetching your MonKey",
|
||||||
return FetchMonkeyDialog(
|
|
||||||
onCancel: () async {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await Future<void>.delayed(
|
// if (isDesktop) {
|
||||||
const Duration(seconds: 2));
|
// Navigator.of(context).popUntil(
|
||||||
|
// ModalRoute.withName(
|
||||||
if (isDesktop) {
|
// DesktopWalletView.routeName),
|
||||||
Navigator.of(context).popUntil(
|
// );
|
||||||
ModalRoute.withName(
|
// } else {
|
||||||
DesktopWalletView.routeName),
|
// Navigator.of(context).popUntil(
|
||||||
);
|
// ModalRoute.withName(WalletView.routeName),
|
||||||
} else {
|
// );
|
||||||
Navigator.of(context).popUntil(
|
// }
|
||||||
ModalRoute.withName(WalletView.routeName),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -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/primary_button.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class DesktopWalletFeatures extends ConsumerStatefulWidget {
|
class DesktopWalletFeatures extends ConsumerStatefulWidget {
|
||||||
const DesktopWalletFeatures({
|
const DesktopWalletFeatures({
|
||||||
|
@ -318,16 +317,10 @@ class _DesktopWalletFeaturesState extends ConsumerState<DesktopWalletFeatures> {
|
||||||
|
|
||||||
Future<void> _onMonkeyPressed() async {
|
Future<void> _onMonkeyPressed() async {
|
||||||
Navigator.of(context, rootNavigator: true).pop();
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
final managerProvider = ref
|
|
||||||
.read(walletsChangeNotifierProvider)
|
|
||||||
.getManagerProvider(widget.walletId);
|
|
||||||
|
|
||||||
await (Navigator.of(context).pushNamed(
|
await (Navigator.of(context).pushNamed(
|
||||||
MonkeyView.routeName,
|
MonkeyView.routeName,
|
||||||
arguments: Tuple2(
|
arguments: widget.walletId,
|
||||||
widget.walletId,
|
|
||||||
managerProvider,
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -378,12 +378,11 @@ class RouteGenerator {
|
||||||
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||||
|
|
||||||
case MonkeyView.routeName:
|
case MonkeyView.routeName:
|
||||||
if (args is Tuple2<String, ChangeNotifierProvider<Manager>>) {
|
if (args is String) {
|
||||||
return getRoute(
|
return getRoute(
|
||||||
shouldUseMaterialRoute: useMaterialPageRoute,
|
shouldUseMaterialRoute: useMaterialPageRoute,
|
||||||
builder: (_) => MonkeyView(
|
builder: (_) => MonkeyView(
|
||||||
walletId: args.item1,
|
walletId: args,
|
||||||
managerProvider: args.item2,
|
|
||||||
),
|
),
|
||||||
settings: RouteSettings(
|
settings: RouteSettings(
|
||||||
name: settings.name,
|
name: settings.name,
|
||||||
|
|
Loading…
Reference in a new issue