Multiple Wallet support, history of each wallet and updated payment page
This commit is contained in:
61
frontend/pweb/lib/pages/payout_page/wallet/card.dart
Normal file
61
frontend/pweb/lib/pages/payout_page/wallet/card.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/amount.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
import 'package:pweb/utils/currency.dart';
|
||||
|
||||
|
||||
class WalletCard extends StatelessWidget {
|
||||
final Wallet wallet;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const WalletCard({super.key, required this.wallet, required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Card(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
elevation: theme.cardTheme.elevation ?? 4,
|
||||
color: theme.colorScheme.onSecondary,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(left: 50, top: 16, bottom: 16),
|
||||
child: Row(
|
||||
spacing: 3,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 24,
|
||||
child: Icon(iconForCurrencyType(wallet.currency), size: 28),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BalanceAmount(
|
||||
wallet: wallet,
|
||||
onToggleVisibility: () {
|
||||
context.read<WalletsProvider>().toggleVisibility(wallet.id);
|
||||
},
|
||||
),
|
||||
Text(
|
||||
wallet.name,
|
||||
style: theme.textTheme.bodyLarge!.copyWith(fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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:pweb/providers/wallets.dart';
|
||||
|
||||
|
||||
class ButtonsWalletWidget extends StatelessWidget {
|
||||
const ButtonsWalletWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<WalletsProvider>();
|
||||
final wallet = provider.wallets?.first;
|
||||
|
||||
if (wallet == null) 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(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class SaveWalletButton extends StatelessWidget {
|
||||
final Wallet wallet;
|
||||
final TextEditingController nameController;
|
||||
final TextEditingController balanceController;
|
||||
final VoidCallback onSave; // Changed to VoidCallback
|
||||
|
||||
const SaveWalletButton({
|
||||
super.key,
|
||||
required this.wallet,
|
||||
required this.nameController,
|
||||
required this.balanceController,
|
||||
required this.onSave, // Now matches _saveWallet signature
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final dimensions = AppDimensions();
|
||||
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: dimensions.buttonWidth,
|
||||
height: dimensions.buttonHeight,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
onTap: onSave, // Directly use onSave now
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primary,
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Save',
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: theme.colorScheme.onSecondary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:pweb/providers/page_selector.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
|
||||
|
||||
class SendPayoutButton extends StatelessWidget {
|
||||
const SendPayoutButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shadowColor: null,
|
||||
elevation: 0,
|
||||
),
|
||||
onPressed: () {
|
||||
final pageSelectorProvider = context.read<PageSelectorProvider>();
|
||||
final walletsProvider = context.read<WalletsProvider>();
|
||||
final wallet = walletsProvider.selectedWallet;
|
||||
|
||||
if (wallet != null) {
|
||||
pageSelectorProvider.startPaymentFromWallet(wallet);
|
||||
}
|
||||
},
|
||||
child: Text('Send Payout'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class TopUpButton extends StatelessWidget{
|
||||
const TopUpButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shadowColor: null,
|
||||
elevation: 0,
|
||||
),
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Add functionality')),
|
||||
);
|
||||
},
|
||||
child: Text('Top Up Balance'),
|
||||
);
|
||||
}
|
||||
}
|
||||
53
frontend/pweb/lib/pages/payout_page/wallet/edit/fields.dart
Normal file
53
frontend/pweb/lib/pages/payout_page/wallet/edit/fields.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/amount.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
|
||||
|
||||
class WalletEditFields extends StatelessWidget {
|
||||
const WalletEditFields({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<WalletsProvider>(
|
||||
builder: (context, provider, child) {
|
||||
final wallet = provider.selectedWallet;
|
||||
|
||||
if (wallet == null) {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
BalanceAmount(
|
||||
wallet: wallet,
|
||||
onToggleVisibility: () {
|
||||
context.read<WalletsProvider>().toggleVisibility(wallet.id);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(wallet.walletUserID, style: Theme.of(context).textTheme.bodyLarge),
|
||||
IconButton(
|
||||
icon: Icon(Icons.copy),
|
||||
iconSize: 18,
|
||||
onPressed: () => Clipboard.setData(ClipboardData(text: wallet.walletUserID)),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
113
frontend/pweb/lib/pages/payout_page/wallet/edit/header.dart
Normal file
113
frontend/pweb/lib/pages/payout_page/wallet/edit/header.dart
Normal file
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
|
||||
|
||||
class WalletEditHeader extends StatefulWidget {
|
||||
const WalletEditHeader({super.key});
|
||||
|
||||
@override
|
||||
State<WalletEditHeader> createState() => _WalletEditHeaderState();
|
||||
}
|
||||
|
||||
class _WalletEditHeaderState extends State<WalletEditHeader> {
|
||||
bool _isEditing = false;
|
||||
late TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<WalletsProvider>();
|
||||
final wallet = provider.selectedWallet;
|
||||
|
||||
if (wallet == null) {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
|
||||
final theme = Theme.of(context);
|
||||
|
||||
if (!_isEditing) {
|
||||
_controller.text = wallet.name;
|
||||
}
|
||||
|
||||
return Row(
|
||||
spacing: 8,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: !_isEditing
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
wallet.name,
|
||||
style: theme.textTheme.headlineMedium!.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isEditing = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _controller,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
isDense: true,
|
||||
hintText: 'Wallet name',
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.check),
|
||||
color: theme.colorScheme.primary,
|
||||
onPressed: () async {
|
||||
provider.updateName(wallet.id, _controller.text);
|
||||
await provider.updateWallet(wallet.copyWith(name: _controller.text));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Wallet name saved')),
|
||||
);
|
||||
setState(() {
|
||||
_isEditing = false;
|
||||
});
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
_controller.text = wallet.name;
|
||||
setState(() {
|
||||
_isEditing = false;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
73
frontend/pweb/lib/pages/payout_page/wallet/edit/page.dart
Normal file
73
frontend/pweb/lib/pages/payout_page/wallet/edit/page.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/buttons/buttons.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/fields.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/header.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/history/history.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class WalletEditPage extends StatelessWidget {
|
||||
final VoidCallback onBack;
|
||||
|
||||
const WalletEditPage({super.key, required this.onBack});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dimensions = AppDimensions();
|
||||
|
||||
return Consumer<WalletsProvider>(
|
||||
builder: (context, provider, child) {
|
||||
final wallet = provider.selectedWallet;
|
||||
|
||||
if (wallet == null) {
|
||||
return Center(child: Text('Кошелёк не выбран'));
|
||||
}
|
||||
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: Column(
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: dimensions.maxContentWidth),
|
||||
child: Material(
|
||||
elevation: dimensions.elevationSmall,
|
||||
color: Theme.of(context).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,
|
||||
),
|
||||
WalletEditHeader(),
|
||||
WalletEditFields(),
|
||||
const SizedBox(height: 24),
|
||||
ButtonsWalletWidget(),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: WalletHistory(wallet: wallet),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
48
frontend/pweb/lib/pages/payout_page/wallet/history/chip.dart
Normal file
48
frontend/pweb/lib/pages/payout_page/wallet/history/chip.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/models/wallet_transaction.dart';
|
||||
|
||||
|
||||
class TypeChip extends StatelessWidget {
|
||||
final WalletTransactionType type;
|
||||
|
||||
const TypeChip({super.key, required this.type});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isTopUp = type == WalletTransactionType.topUp;
|
||||
final bg = isTopUp
|
||||
? theme.colorScheme.secondaryContainer
|
||||
: theme.colorScheme.errorContainer;
|
||||
|
||||
final fg = bg.computeLuminance() > 0.5 ? Colors.black : Colors.white;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
isTopUp ? Icons.arrow_downward_rounded : Icons.arrow_upward_rounded,
|
||||
size: 16,
|
||||
color: fg,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
type.label(context),
|
||||
style: TextStyle(
|
||||
color: fg,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/utils/localization.dart';
|
||||
|
||||
import 'package:pweb/models/wallet_transaction.dart';
|
||||
import 'package:pweb/providers/wallet_transactions.dart';
|
||||
|
||||
|
||||
class WalletHistoryFilters extends StatelessWidget {
|
||||
final WalletTransactionsProvider provider;
|
||||
final VoidCallback onPickRange;
|
||||
|
||||
const WalletHistoryFilters({
|
||||
super.key,
|
||||
required this.provider,
|
||||
required this.onPickRange,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Card(
|
||||
elevation: 2,
|
||||
color: theme.colorScheme.onSecondary,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Wallet activity',
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
if (provider.hasFilters)
|
||||
TextButton(
|
||||
onPressed: provider.resetFilters,
|
||||
child: const Text('Reset'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: WalletTransactionType.values.map((type) {
|
||||
final isSelected = provider.selectedTypes.contains(type);
|
||||
return FilterChip(
|
||||
label: Text(type.label(context)),
|
||||
selected: isSelected,
|
||||
onSelected: (_) => provider.toggleType(type),
|
||||
pressElevation: 0,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: OperationStatus.values.map((status) {
|
||||
final isSelected = provider.selectedStatuses.contains(status);
|
||||
return FilterChip(
|
||||
label: Text(status.localized(context)),
|
||||
selected: isSelected,
|
||||
onSelected: (_) => provider.toggleStatus(status),
|
||||
pressElevation: 0,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: onPickRange,
|
||||
icon: const Icon(Icons.date_range_outlined),
|
||||
label: Text(
|
||||
provider.dateRange == null
|
||||
? 'Select period'
|
||||
: '${dateToLocalFormat(context, provider.dateRange!.start)} – ${dateToLocalFormat(context, provider.dateRange!.end)}',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
116
frontend/pweb/lib/pages/payout_page/wallet/history/history.dart
Normal file
116
frontend/pweb/lib/pages/payout_page/wallet/history/history.dart
Normal file
@@ -0,0 +1,116 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/history/filters.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/history/table.dart';
|
||||
import 'package:pweb/providers/wallet_transactions.dart';
|
||||
|
||||
|
||||
class WalletHistory extends StatefulWidget {
|
||||
final Wallet wallet;
|
||||
|
||||
const WalletHistory({super.key, required this.wallet});
|
||||
|
||||
@override
|
||||
State<WalletHistory> createState() => _WalletHistoryState();
|
||||
}
|
||||
|
||||
class _WalletHistoryState extends State<WalletHistory> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant WalletHistory oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.wallet.id != widget.wallet.id) {
|
||||
_load();
|
||||
}
|
||||
}
|
||||
|
||||
void _load() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context
|
||||
.read<WalletTransactionsProvider>()
|
||||
.load(walletId: widget.wallet.id);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _pickRange() async {
|
||||
final provider = context.read<WalletTransactionsProvider>();
|
||||
final now = DateTime.now();
|
||||
final initial = provider.dateRange ??
|
||||
DateTimeRange(
|
||||
start: now.subtract(const Duration(days: 30)),
|
||||
end: now,
|
||||
);
|
||||
|
||||
final picked = await showDateRangePicker(
|
||||
context: context,
|
||||
firstDate: now.subtract(const Duration(days: 365)),
|
||||
lastDate: now.add(const Duration(days: 1)),
|
||||
initialDateRange: initial,
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
provider.setDateRange(picked);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Consumer<WalletTransactionsProvider>(
|
||||
builder: (context, provider, child) {
|
||||
if (provider.isLoading) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
if (provider.error != null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Failed to load history',
|
||||
style: theme.textTheme.titleMedium!
|
||||
.copyWith(color: theme.colorScheme.error),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(provider.error!),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton(
|
||||
onPressed: _load,
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final transactions = provider.filteredTransactions;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
WalletHistoryFilters(
|
||||
provider: provider,
|
||||
onPickRange: _pickRange,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
WalletTransactionsTable(transactions: transactions),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/models/wallet_transaction.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/history/chip.dart';
|
||||
import 'package:pweb/pages/report/table/badge.dart';
|
||||
import 'package:pweb/utils/currency.dart';
|
||||
|
||||
|
||||
class WalletTransactionsTable extends StatelessWidget {
|
||||
final List<WalletTransaction> transactions;
|
||||
|
||||
const WalletTransactionsTable({super.key, required this.transactions});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
if (transactions.isEmpty) {
|
||||
return Card(
|
||||
color: theme.colorScheme.onSecondary,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('No history yet'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Card(
|
||||
color: theme.colorScheme.onSecondary,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: DataTable(
|
||||
columnSpacing: 18,
|
||||
headingTextStyle: const TextStyle(fontWeight: FontWeight.w600),
|
||||
columns: const [
|
||||
DataColumn(label: Text('Status')),
|
||||
DataColumn(label: Text('Type')),
|
||||
DataColumn(label: Text('Amount')),
|
||||
DataColumn(label: Text('Balance')),
|
||||
DataColumn(label: Text('Counterparty')),
|
||||
DataColumn(label: Text('Date')),
|
||||
DataColumn(label: Text('Comment')),
|
||||
],
|
||||
rows: List.generate(
|
||||
transactions.length,
|
||||
(index) {
|
||||
final tx = transactions[index];
|
||||
final color = WidgetStateProperty.resolveWith<Color?>(
|
||||
(states) => index.isEven
|
||||
? theme.colorScheme.surfaceContainerHighest
|
||||
: null,
|
||||
);
|
||||
|
||||
return DataRow.byIndex(
|
||||
index: index,
|
||||
color: color,
|
||||
cells: [
|
||||
DataCell(OperationStatusBadge(status: tx.status)),
|
||||
DataCell(TypeChip(type: tx.type)),
|
||||
DataCell(Text(
|
||||
'${tx.type.sign}${tx.amount.toStringAsFixed(2)} ${currencyCodeToSymbol(tx.currency)}')),
|
||||
DataCell(Text(
|
||||
tx.balanceAfter == null
|
||||
? '-'
|
||||
: '${tx.balanceAfter!.toStringAsFixed(2)} ${currencyCodeToSymbol(tx.currency)}',
|
||||
)),
|
||||
DataCell(Text(tx.counterparty ?? '-')),
|
||||
DataCell(Text(
|
||||
'${TimeOfDay.fromDateTime(tx.date).format(context)}\n'
|
||||
'${tx.date.toLocal().toIso8601String().split("T").first}',
|
||||
)),
|
||||
DataCell(Text(tx.description)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
49
frontend/pweb/lib/pages/payout_page/wallet/wigets.dart
Normal file
49
frontend/pweb/lib/pages/payout_page/wallet/wigets.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
|
||||
import 'package:pweb/pages/payout_page/wallet/card.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
|
||||
|
||||
class WalletWidgets extends StatelessWidget {
|
||||
final Function(Wallet) onWalletTap;
|
||||
|
||||
const WalletWidgets({super.key, required this.onWalletTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<WalletsProvider>();
|
||||
|
||||
final wallets = provider.wallets;
|
||||
|
||||
if (wallets == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
scrollDirection: Axis.vertical,
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
childAspectRatio: 3,
|
||||
),
|
||||
itemCount: wallets.length,
|
||||
itemBuilder: (context, index) {
|
||||
final wallet = wallets[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: WalletCard(
|
||||
wallet: wallet,
|
||||
onTap: () {
|
||||
onWalletTap(wallet);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user