Top Up Balance logic and Added fixes for routing

This commit is contained in:
Arseni
2025-12-05 20:29:43 +03:00
parent f7bf3138ac
commit bf39b1d401
27 changed files with 972 additions and 175 deletions

View File

@@ -0,0 +1,112 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:pweb/widgets/sidebar/destinations.dart';
class PayoutRoutes {
static const dashboard = 'dashboard';
static const sendPayout = payment;
static const recipients = 'payout-recipients';
static const addRecipient = 'payout-add-recipient';
static const payment = 'payout-payment';
static const settings = 'payout-settings';
static const reports = 'payout-reports';
static const methods = 'payout-methods';
static const editWallet = 'payout-edit-wallet';
static const walletTopUp = 'payout-wallet-top-up';
static const dashboardPath = '/dashboard';
static const recipientsPath = '/dashboard/recipients';
static const addRecipientPath = '/dashboard/recipients/add';
static const paymentPath = '/dashboard/payment';
static const settingsPath = '/dashboard/settings';
static const reportsPath = '/dashboard/reports';
static const methodsPath = '/dashboard/methods';
static const editWalletPath = '/dashboard/methods/edit';
static const walletTopUpPath = '/dashboard/wallet/top-up';
static String nameFor(PayoutDestination destination) {
switch (destination) {
case PayoutDestination.dashboard:
return dashboard;
case PayoutDestination.sendPayout:
return payment;
case PayoutDestination.recipients:
return recipients;
case PayoutDestination.addrecipient:
return addRecipient;
case PayoutDestination.payment:
return payment;
case PayoutDestination.settings:
return settings;
case PayoutDestination.reports:
return reports;
case PayoutDestination.methods:
return methods;
case PayoutDestination.editwallet:
return editWallet;
case PayoutDestination.walletTopUp:
return walletTopUp;
}
}
static String pathFor(PayoutDestination destination) {
switch (destination) {
case PayoutDestination.dashboard:
return dashboardPath;
case PayoutDestination.sendPayout:
return paymentPath;
case PayoutDestination.recipients:
return recipientsPath;
case PayoutDestination.addrecipient:
return addRecipientPath;
case PayoutDestination.payment:
return paymentPath;
case PayoutDestination.settings:
return settingsPath;
case PayoutDestination.reports:
return reportsPath;
case PayoutDestination.methods:
return methodsPath;
case PayoutDestination.editwallet:
return editWalletPath;
case PayoutDestination.walletTopUp:
return walletTopUpPath;
}
}
static PayoutDestination? destinationFor(String? routeName) {
switch (routeName) {
case dashboard:
return PayoutDestination.dashboard;
case sendPayout:
return PayoutDestination.payment;
case recipients:
return PayoutDestination.recipients;
case addRecipient:
return PayoutDestination.addrecipient;
case payment:
return PayoutDestination.payment;
case settings:
return PayoutDestination.settings;
case reports:
return PayoutDestination.reports;
case methods:
return PayoutDestination.methods;
case editWallet:
return PayoutDestination.editwallet;
case walletTopUp:
return PayoutDestination.walletTopUp;
default:
return null;
}
}
}
extension PayoutNavigation on BuildContext {
void goToPayout(PayoutDestination destination) => goNamed(PayoutRoutes.nameFor(destination));
void pushToPayout(PayoutDestination destination) => pushNamed(PayoutRoutes.nameFor(destination));
}

View File

@@ -0,0 +1,160 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:pshared/provider/recipient/provider.dart';
import 'package:pweb/app/router/pages.dart';
import 'package:pweb/app/router/payout_routes.dart';
import 'package:pweb/pages/address_book/form/page.dart';
import 'package:pweb/pages/address_book/page/page.dart';
import 'package:pweb/pages/dashboard/dashboard.dart';
import 'package:pweb/pages/payment_methods/page.dart';
import 'package:pweb/pages/payout_page/page.dart';
import 'package:pweb/pages/payout_page/wallet/edit/page.dart';
import 'package:pweb/pages/report/page.dart';
import 'package:pweb/pages/settings/profile/page.dart';
import 'package:pweb/pages/wallet_top_up/page.dart';
import 'package:pweb/providers/page_selector.dart';
import 'package:pweb/widgets/error/snackbar.dart';
import 'package:pweb/widgets/sidebar/destinations.dart';
import 'package:pweb/widgets/sidebar/page.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
RouteBase payoutShellRoute() => ShellRoute(
builder: (context, state, child) => PageSelector(
child: child,
routerState: state,
),
routes: [
GoRoute(
name: PayoutRoutes.dashboard,
path: routerPage(Pages.dashboard),
pageBuilder: (context, _) => NoTransitionPage(
child: DashboardPage(
onRecipientSelected: (recipient) => context
.read<PageSelectorProvider>()
.selectRecipient(context, recipient),
onGoToPaymentWithoutRecipient: (type) => context
.read<PageSelectorProvider>()
.startPaymentWithoutRecipient(context, type),
onTopUp: (wallet) => context
.read<PageSelectorProvider>()
.openWalletTopUp(context, wallet),
),
),
),
GoRoute(
name: PayoutRoutes.recipients,
path: PayoutRoutes.recipientsPath,
pageBuilder: (context, _) {
final loc = AppLocalizations.of(context)!;
return NoTransitionPage(
child: RecipientAddressBookPage(
onRecipientSelected: (recipient) => context
.read<PageSelectorProvider>()
.selectRecipient(context, recipient, fromList: true),
onAddRecipient: () => context
.read<PageSelectorProvider>()
.goToAddRecipient(context),
onEditRecipient: (recipient) => context
.read<PageSelectorProvider>()
.editRecipient(context, recipient, fromList: true),
onDeleteRecipient: (recipient) => executeActionWithNotification(
context: context,
action: () async =>
context.read<RecipientsProvider>().delete(recipient.id),
successMessage: loc.recipientDeletedSuccessfully,
errorMessage: loc.errorDeleteRecipient,
),
),
);
},
),
GoRoute(
name: PayoutRoutes.addRecipient,
path: PayoutRoutes.addRecipientPath,
pageBuilder: (context, _) {
final selector = context.read<PageSelectorProvider>();
final recipient = selector.recipientProvider.currentObject;
return NoTransitionPage(
child: AdressBookRecipientForm(
recipient: recipient,
onSaved: (_) => selector.selectPage(
context,
PayoutDestination.recipients,
),
),
);
},
),
GoRoute(
name: PayoutRoutes.payment,
path: PayoutRoutes.paymentPath,
pageBuilder: (context, _) => NoTransitionPage(
child: PaymentPage(
onBack: (_) => context
.read<PageSelectorProvider>()
.goBackFromPayment(context),
),
),
),
GoRoute(
name: PayoutRoutes.settings,
path: PayoutRoutes.settingsPath,
pageBuilder: (_, __) => const NoTransitionPage(
child: ProfileSettingsPage(),
),
),
GoRoute(
name: PayoutRoutes.reports,
path: PayoutRoutes.reportsPath,
pageBuilder: (_, __) => const NoTransitionPage(
child: OperationHistoryPage(),
),
),
GoRoute(
name: PayoutRoutes.methods,
path: PayoutRoutes.methodsPath,
pageBuilder: (context, _) => NoTransitionPage(
child: PaymentConfigPage(
onWalletTap: (wallet) => context
.read<PageSelectorProvider>()
.selectWallet(context, wallet),
),
),
),
GoRoute(
name: PayoutRoutes.editWallet,
path: PayoutRoutes.editWalletPath,
pageBuilder: (context, _) {
final provider = context.read<PageSelectorProvider>();
final wallet = provider.walletsProvider.selectedWallet;
final loc = AppLocalizations.of(context)!;
return NoTransitionPage(
child: wallet != null
? WalletEditPage(
onBack: () => provider.goBackFromWalletEdit(context),
)
: Center(child: Text(loc.noWalletSelected)),
);
},
),
GoRoute(
name: PayoutRoutes.walletTopUp,
path: PayoutRoutes.walletTopUpPath,
pageBuilder: (context, _) => NoTransitionPage(
child: WalletTopUpPage(
onBack: () => context
.read<PageSelectorProvider>()
.goBackFromWalletTopUp(context),
),
),
),
],
);

View File

@@ -1,13 +1,14 @@
import 'package:go_router/go_router.dart';
import 'package:pweb/app/router/pages.dart';
import 'package:pweb/app/router/page_params.dart';
import 'package:pweb/app/router/pages.dart';
import 'package:pweb/app/router/payout_shell.dart';
import 'package:pweb/app/router/payout_routes.dart';
import 'package:pweb/pages/2fa/page.dart';
import 'package:pweb/pages/errors/not_found.dart';
import 'package:pweb/pages/login/page.dart';
import 'package:pweb/pages/signup/page.dart';
import 'package:pweb/pages/verification/page.dart';
import 'package:pweb/widgets/sidebar/page.dart';
import 'package:pweb/pages/login/page.dart';
import 'package:pweb/pages/errors/not_found.dart';
GoRouter createRouter() => GoRouter(
@@ -16,40 +17,33 @@ GoRouter createRouter() => GoRouter(
GoRoute(
name: Pages.root.name,
path: routerPage(Pages.root),
builder: (_, _) => const LoginPage(),
routes: [
GoRoute(
name: Pages.login.name,
path: routerPage(Pages.login),
builder: (_, _) => const LoginPage(),
),
GoRoute(
name: Pages.dashboard.name,
path: routerPage(Pages.dashboard),
builder: (_, _) => const PageSelector(),
),
GoRoute(
name: Pages.sfactor.name,
path: routerPage(Pages.sfactor),
builder: (context, _) => TwoFactorCodePage(
onVerificationSuccess: () {
// trigger organization load
context.goNamed(Pages.dashboard.name);
},
),
),
GoRoute(
name: Pages.signup.name,
path: routerPage(Pages.signup),
builder: (_, _) => const SignUpPage(),
),
GoRoute(
name: Pages.verify.name,
path: '${routerPage(Pages.verify)}${routerAddParam(PageParams.token)}',
builder: (_, state) => AccountVerificationPage(token: state.pathParameters[PageParams.token.name]!),
),
],
builder: (_, __) => const LoginPage(),
),
GoRoute(
name: Pages.login.name,
path: routerPage(Pages.login),
builder: (_, __) => const LoginPage(),
),
GoRoute(
name: Pages.sfactor.name,
path: routerPage(Pages.sfactor),
builder: (context, _) => TwoFactorCodePage(
onVerificationSuccess: () => context.goNamed(PayoutRoutes.dashboard),
),
),
GoRoute(
name: Pages.signup.name,
path: routerPage(Pages.signup),
builder: (_, __) => const SignUpPage(),
),
GoRoute(
name: Pages.verify.name,
path: '${routerPage(Pages.verify)}${routerAddParam(PageParams.token)}',
builder: (_, state) => AccountVerificationPage(
token: state.pathParameters[PageParams.token.name]!,
),
),
payoutShellRoute(),
],
errorBuilder: (_, _) => const NotFoundPage(),
);
errorBuilder: (_, __) => const NotFoundPage(),
);