Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline failed
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version unknown status
106 lines
3.3 KiB
Dart
106 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:pweb/app/router/pages.dart';
|
|
import 'package:pweb/app/router/payout_routes.dart';
|
|
import 'package:pweb/providers/account.dart';
|
|
import 'package:pweb/providers/page_selector.dart';
|
|
import 'package:pweb/providers/permissions.dart';
|
|
import 'package:pweb/widgets/appbar/app_bar.dart';
|
|
import 'package:pweb/widgets/sidebar/destinations.dart';
|
|
import 'package:pweb/widgets/sidebar/sidebar.dart';
|
|
|
|
|
|
class PageSelector extends StatelessWidget {
|
|
final PayoutDestination selected;
|
|
final Widget child;
|
|
|
|
const PageSelector({
|
|
super.key,
|
|
required this.selected,
|
|
required this.child,
|
|
});
|
|
|
|
void _handleLogout(BuildContext context) {
|
|
context.read<AccountProvider>().logout();
|
|
context.read<PermissionsProvider>().clear();
|
|
navigateAndReplace(context, Pages.login);
|
|
}
|
|
|
|
void _goToDestination(BuildContext context, PayoutDestination destination) {
|
|
context.go(payoutPath(destination));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final provider = context.watch<PageSelectorProvider>();
|
|
final permissions = context.watch<PermissionsProvider>();
|
|
final account = context.watch<AccountProvider>().account;
|
|
|
|
final allowedDestinations = permissions.isRecipient
|
|
? <PayoutDestination>{
|
|
PayoutDestination.settings,
|
|
PayoutDestination.methods,
|
|
PayoutDestination.editwallet,
|
|
}
|
|
: PayoutDestination.values.toSet();
|
|
|
|
final safeSelected = allowedDestinations.contains(selected)
|
|
? selected
|
|
: (permissions.isRecipient ? PayoutDestination.settings : PayoutDestination.dashboard);
|
|
|
|
if (safeSelected != selected) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _goToDestination(context, safeSelected));
|
|
}
|
|
|
|
if (provider.selected != safeSelected) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => provider.selectPage(safeSelected));
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: PayoutAppBar(
|
|
title: Text(safeSelected.localizedLabel(context)),
|
|
onAddFundsPressed: () {},
|
|
onLogout: () => _handleLogout(context),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.only(left: 200, top: 40, right: 200),
|
|
child: Row(
|
|
spacing: 40,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
PayoutSidebar(
|
|
selected: safeSelected,
|
|
onSelected: (destination) => _goToDestination(context, destination),
|
|
onLogout: () => _handleLogout(context),
|
|
userName: account?.name,
|
|
items: permissions.isRecipient
|
|
? const [PayoutDestination.settings, PayoutDestination.methods]
|
|
: null,
|
|
),
|
|
Expanded(child: child),
|
|
],
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.only(left: 200, top: 40, right: 200),
|
|
child: Row(
|
|
spacing: 40,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
PayoutSidebar(
|
|
selected: selected,
|
|
onSelected: provider.selectPage,
|
|
onLogout: () => logoutUtil(context),
|
|
),
|
|
Expanded(child: content),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
));
|
|
}
|