WIP: integration with ledger
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/buttons/send.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/buttons/top_up.dart';
|
||||
import 'package:pshared/provider/payment/wallets.dart';
|
||||
|
||||
|
||||
class ButtonsWalletWidget extends StatelessWidget {
|
||||
@@ -12,25 +9,17 @@ class ButtonsWalletWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<WalletsProvider>();
|
||||
|
||||
if (provider.wallets.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Expanded(
|
||||
child: SendPayoutButton(),
|
||||
),
|
||||
VerticalDivider(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
thickness: 1,
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: TopUpButton(),
|
||||
),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Expanded(child: SendPayoutButton()),
|
||||
VerticalDivider(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
thickness: 1,
|
||||
width: 10,
|
||||
),
|
||||
Expanded(child: TopUpButton()),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/models/payment/source.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
import 'package:pweb/app/router/payout_routes.dart';
|
||||
@@ -18,20 +19,18 @@ class SendPayoutButton extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shadowColor: null,
|
||||
elevation: 0,
|
||||
),
|
||||
style: ElevatedButton.styleFrom(shadowColor: null, elevation: 0),
|
||||
onPressed: () {
|
||||
final wallets = context.read<WalletsController>();
|
||||
final wallet = wallets.selectedWallet;
|
||||
|
||||
if (wallet != null) {
|
||||
context.pushToPayment(
|
||||
paymentType: PaymentType.wallet,
|
||||
returnTo: PayoutDestination.editwallet,
|
||||
);
|
||||
}
|
||||
final source = context.read<PaymentSourceController>().selectedSource;
|
||||
if (source == null) return;
|
||||
final paymentType = switch (source.type) {
|
||||
PaymentSourceType.wallet => PaymentType.wallet,
|
||||
PaymentSourceType.ledger => PaymentType.ledger,
|
||||
};
|
||||
context.pushToPayment(
|
||||
paymentType: paymentType,
|
||||
returnTo: PayoutDestination.editwallet,
|
||||
);
|
||||
},
|
||||
child: Text(loc.payoutNavSendPayout),
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
|
||||
import 'package:pweb/app/router/payout_routes.dart';
|
||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||
@@ -10,23 +10,20 @@ import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class TopUpButton extends StatelessWidget{
|
||||
class TopUpButton extends StatelessWidget {
|
||||
const TopUpButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shadowColor: null,
|
||||
elevation: 0,
|
||||
),
|
||||
style: ElevatedButton.styleFrom(shadowColor: null, elevation: 0),
|
||||
onPressed: () {
|
||||
final wallet = context.read<WalletsController>().selectedWallet;
|
||||
if (wallet == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(loc.noWalletSelected)),
|
||||
);
|
||||
final source = context.read<PaymentSourceController>().selectedSource;
|
||||
if (source == null) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(loc.noWalletSelected)));
|
||||
return;
|
||||
}
|
||||
context.pushToWalletTopUp(returnTo: PayoutDestination.editwallet);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/balance_mask/ledger_accounts.dart';
|
||||
import 'package:pshared/models/ledger/account.dart';
|
||||
|
||||
import 'package:pweb/pages/payout_page/wallet/ledger/format.dart';
|
||||
import 'package:pweb/widgets/refresh_balance/ledger.dart';
|
||||
|
||||
|
||||
class LedgerEditBalanceRow extends StatelessWidget {
|
||||
final LedgerAccount account;
|
||||
|
||||
const LedgerEditBalanceRow({super.key, required this.account});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Consumer<LedgerBalanceMaskController>(
|
||||
builder: (context, controller, _) {
|
||||
final isMasked = controller.isBalanceMasked(account.ledgerAccountRef);
|
||||
final money = account.balance?.balance;
|
||||
final displayBalance = money == null
|
||||
? '--'
|
||||
: isMasked
|
||||
? formatMaskedLedgerBalance(money.currency)
|
||||
: formatLedgerBalance(
|
||||
amount: money.amount,
|
||||
currency: money.currency,
|
||||
);
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
displayBalance,
|
||||
style: theme.textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
controller.toggleBalanceMask(account.ledgerAccountRef),
|
||||
child: Icon(
|
||||
isMasked ? Icons.visibility_off : Icons.visibility,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
LedgerBalanceRefreshButton(
|
||||
ledgerAccountRef: account.ledgerAccountRef,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
|
||||
class LedgerEditCopyableRow extends StatelessWidget {
|
||||
final String title;
|
||||
final String value;
|
||||
|
||||
const LedgerEditCopyableRow({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: theme.textTheme.bodySmall),
|
||||
const SizedBox(height: 2),
|
||||
Text(value, style: theme.textTheme.bodyLarge),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy),
|
||||
iconSize: 18,
|
||||
onPressed: () => Clipboard.setData(ClipboardData(text: value)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/ledger/account.dart';
|
||||
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/buttons/buttons.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/ledger/balance_row.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/ledger/copyable_row.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class LedgerEditView extends StatelessWidget {
|
||||
final LedgerAccount account;
|
||||
final VoidCallback onBack;
|
||||
|
||||
const LedgerEditView({
|
||||
super.key,
|
||||
required this.account,
|
||||
required this.onBack,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dimensions = AppDimensions();
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: dimensions.maxContentWidth),
|
||||
child: Material(
|
||||
elevation: dimensions.elevationSmall,
|
||||
color: theme.colorScheme.onSecondary,
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusMedium),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(dimensions.paddingLarge),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: onBack,
|
||||
),
|
||||
Text(
|
||||
loc.paymentTypeLedger,
|
||||
style: theme.textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (account.currency.trim().isNotEmpty)
|
||||
Text(
|
||||
account.currency,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
LedgerEditBalanceRow(account: account),
|
||||
const SizedBox(height: 12),
|
||||
LedgerEditCopyableRow(
|
||||
title: loc.ledgerAccountRef,
|
||||
value: account.ledgerAccountRef,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
LedgerEditCopyableRow(
|
||||
title: 'Account code',
|
||||
value: account.accountCode,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const ButtonsWalletWidget(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/provider/ledger.dart';
|
||||
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/ledger/view.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
class LedgerEditPage extends StatelessWidget {
|
||||
final VoidCallback onBack;
|
||||
|
||||
const LedgerEditPage({super.key, required this.onBack});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
final source = context.watch<PaymentSourceController>().selectedSource;
|
||||
|
||||
if (source == null || source.ledgerAccount == null) {
|
||||
return Center(child: Text(loc.noWalletSelected));
|
||||
}
|
||||
|
||||
final accountRef = source.ledgerAccount!.ledgerAccountRef;
|
||||
|
||||
return Consumer<LedgerAccountsProvider>(
|
||||
builder: (context, provider, _) {
|
||||
final account = provider.accounts.firstWhereOrNull(
|
||||
(item) => item.ledgerAccountRef == accountRef,
|
||||
);
|
||||
if (account == null) {
|
||||
return Center(child: Text(loc.noWalletSelected));
|
||||
}
|
||||
|
||||
return LedgerEditView(account: account, onBack: onBack);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user