ledger top up functionality and few small fixes for project architechture and design

This commit is contained in:
Arseni
2026-03-05 21:49:23 +03:00
parent 39c04beb21
commit 97b16542c2
41 changed files with 764 additions and 455 deletions

View File

@@ -25,6 +25,7 @@ class PayoutRoutes {
static const walletTopUp = 'payout-wallet-top-up';
static const paymentTypeQuery = 'paymentType';
static const destinationLedgerAccountRefQuery = 'destinationLedgerAccountRef';
static const reportPaymentIdQuery = 'paymentId';
static const dashboardPath = '/dashboard';
@@ -40,7 +41,6 @@ class PayoutRoutes {
static const editWalletPath = '/methods/edit';
static const walletTopUpPath = '/wallet/top-up';
static String nameFor(PayoutDestination destination) {
switch (destination) {
case PayoutDestination.dashboard:
@@ -126,9 +126,13 @@ class PayoutRoutes {
static Map<String, String> buildQueryParameters({
PaymentType? paymentType,
String? destinationLedgerAccountRef,
}) {
final params = <String, String>{
if (paymentType != null) paymentTypeQuery: paymentType.name,
if (destinationLedgerAccountRef != null &&
destinationLedgerAccountRef.trim().isNotEmpty)
destinationLedgerAccountRefQuery: destinationLedgerAccountRef.trim(),
};
return params;
}
@@ -140,35 +144,44 @@ class PayoutRoutes {
? null
: PaymentType.values.firstWhereOrNull((type) => type.name == raw);
static String? destinationLedgerAccountRefFromState(GoRouterState state) =>
destinationLedgerAccountRefFromRaw(
state.uri.queryParameters[destinationLedgerAccountRefQuery],
);
static String? destinationLedgerAccountRefFromRaw(String? raw) {
final value = raw?.trim();
if (value == null || value.isEmpty) return null;
return value;
}
}
extension PayoutNavigation on BuildContext {
void goToPayout(PayoutDestination destination) => goNamed(PayoutRoutes.nameFor(destination));
void goToPayout(PayoutDestination destination) =>
goNamed(PayoutRoutes.nameFor(destination));
void pushToPayout(PayoutDestination destination) => pushNamed(PayoutRoutes.nameFor(destination));
void pushToPayout(PayoutDestination destination) =>
pushNamed(PayoutRoutes.nameFor(destination));
void goToPayment({
PaymentType? paymentType,
}) =>
goNamed(
String? destinationLedgerAccountRef,
}) => goNamed(
PayoutRoutes.payment,
queryParameters: PayoutRoutes.buildQueryParameters(
paymentType: paymentType,
destinationLedgerAccountRef: destinationLedgerAccountRef,
),
);
void goToReportPayment(String paymentId) => goNamed(
PayoutRoutes.reportPayment,
queryParameters: {
PayoutRoutes.reportPaymentIdQuery: paymentId,
},
queryParameters: {PayoutRoutes.reportPaymentIdQuery: paymentId},
);
void pushToReportPayment(String paymentId) => pushNamed(
PayoutRoutes.reportPayment,
queryParameters: {
PayoutRoutes.reportPaymentIdQuery: paymentId,
},
queryParameters: {PayoutRoutes.reportPaymentIdQuery: paymentId},
);
void pushToWalletTopUp() => pushNamed(PayoutRoutes.walletTopUp);

View File

@@ -228,6 +228,7 @@ RouteBase payoutShellRoute() => ShellRoute(
onGoToPaymentWithoutRecipient: (type) =>
_startPayment(context, recipient: null, paymentType: type),
onTopUp: (wallet) => _openWalletTopUp(context, wallet),
onLedgerAddFunds: (account) => _openLedgerAddFunds(context, account),
onWalletTap: (wallet) => _openWalletEdit(context, wallet),
onLedgerTap: (account) => _openLedgerEdit(context, account),
),
@@ -306,6 +307,8 @@ RouteBase payoutShellRoute() => ShellRoute(
child: PaymentPage(
onBack: (_) => _popOrGo(context),
initialPaymentType: PayoutRoutes.paymentTypeFromState(state),
initialDestinationLedgerAccountRef:
PayoutRoutes.destinationLedgerAccountRefFromState(state),
fallbackDestination: fallbackDestination,
),
);
@@ -395,6 +398,20 @@ void _openLedgerEdit(BuildContext context, LedgerAccount account) {
context.pushToEditWallet();
}
void _openLedgerAddFunds(BuildContext context, LedgerAccount account) {
context.read<PaymentSourceController>().selectLedgerByRef(
account.ledgerAccountRef,
);
context.read<RecipientsProvider>().setCurrentObject(null);
context.pushNamed(
PayoutRoutes.payment,
queryParameters: PayoutRoutes.buildQueryParameters(
paymentType: PaymentType.ledger,
destinationLedgerAccountRef: account.ledgerAccountRef,
),
);
}
void _openWalletTopUp(BuildContext context, Wallet wallet) {
context.read<WalletsController>().selectWallet(wallet);
context.pushToWalletTopUp();