WIP: integration with ledger
This commit is contained in:
46
frontend/pweb/lib/pages/payout_page/wallet/ledger/card.dart
Normal file
46
frontend/pweb/lib/pages/payout_page/wallet/ledger/card.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/ledger/account.dart';
|
||||
|
||||
import 'package:pweb/pages/payout_page/wallet/ledger/card_body.dart';
|
||||
|
||||
|
||||
class LedgerWalletCard extends StatelessWidget {
|
||||
final LedgerAccount account;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const LedgerWalletCard({
|
||||
super.key,
|
||||
required this.account,
|
||||
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: [
|
||||
const CircleAvatar(
|
||||
radius: 24,
|
||||
child: Icon(Icons.account_balance, size: 28),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: LedgerCardBody(account: account)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
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';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class LedgerCardBody extends StatelessWidget {
|
||||
final LedgerAccount account;
|
||||
|
||||
const LedgerCardBody({super.key, required this.account});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final loc = AppLocalizations.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 Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
displayBalance,
|
||||
style: theme.textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () => controller.toggleBalanceMask(
|
||||
account.ledgerAccountRef,
|
||||
),
|
||||
child: Icon(
|
||||
isMasked ? Icons.visibility_off : Icons.visibility,
|
||||
size: 24,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
LedgerBalanceRefreshButton(
|
||||
ledgerAccountRef: account.ledgerAccountRef,
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
loc.paymentTypeLedger,
|
||||
style: theme.textTheme.bodyLarge!.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
account.accountCode,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
String formatLedgerBalance({required String amount, required String currency}) {
|
||||
final parsed = double.tryParse(amount);
|
||||
if (parsed == null) return '$amount $currency';
|
||||
|
||||
try {
|
||||
final symbol = currencyCodeToSymbol(currencyStringToCode(currency));
|
||||
if (symbol.trim().isEmpty) return '${amountToString(parsed)} $currency';
|
||||
return '${amountToString(parsed)} $symbol';
|
||||
} catch (_) {
|
||||
return '${amountToString(parsed)} $currency';
|
||||
}
|
||||
}
|
||||
|
||||
String formatMaskedLedgerBalance(String currency) {
|
||||
final normalized = currency.trim();
|
||||
if (normalized.isEmpty) return '••••';
|
||||
try {
|
||||
final symbol = currencyCodeToSymbol(currencyStringToCode(normalized));
|
||||
if (symbol.trim().isEmpty) return '•••• $normalized';
|
||||
return '•••• $symbol';
|
||||
} catch (_) {
|
||||
return '•••• $normalized';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user