WIP: integration with ledger
This commit is contained in:
@@ -2,12 +2,13 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/models/payment/source.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentAmountWidget extends StatefulWidget {
|
||||
const PaymentAmountWidget({super.key});
|
||||
|
||||
@@ -32,7 +33,8 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
double? _parseAmount(String value) => double.tryParse(value.replaceAll(',', '.'));
|
||||
double? _parseAmount(String value) =>
|
||||
double.tryParse(value.replaceAll(',', '.'));
|
||||
|
||||
void _syncTextWithAmount(double amount) {
|
||||
final parsedText = _parseAmount(_controller.text);
|
||||
@@ -58,14 +60,28 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final amount = context.select<PaymentAmountProvider, double>((provider) => provider.amount);
|
||||
final amount = context.select<PaymentAmountProvider, double>(
|
||||
(provider) => provider.amount,
|
||||
);
|
||||
final source = context.watch<PaymentSourceController>().selectedSource;
|
||||
_syncTextWithAmount(amount);
|
||||
final sourceCurrency = switch (source?.type) {
|
||||
null => null,
|
||||
PaymentSourceType.wallet => currencyCodeToString(
|
||||
source!.wallet!.currency,
|
||||
),
|
||||
PaymentSourceType.ledger =>
|
||||
source!.ledgerAccount?.currency.trim().toUpperCase(),
|
||||
};
|
||||
final amountLabel = sourceCurrency == null || sourceCurrency.isEmpty
|
||||
? AppLocalizations.of(context)!.amount
|
||||
: '${AppLocalizations.of(context)!.amount} ($sourceCurrency)';
|
||||
|
||||
return TextField(
|
||||
controller: _controller,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context)!.amount,
|
||||
labelText: amountLabel,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
onChanged: _onChanged,
|
||||
|
||||
@@ -2,7 +2,9 @@ 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/currency.dart';
|
||||
import 'package:pshared/models/payment/source.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/payouts/summary/fee.dart';
|
||||
@@ -10,24 +12,43 @@ import 'package:pweb/pages/dashboard/payouts/summary/recipient_receives.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/summary/sent_amount.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/summary/total.dart';
|
||||
|
||||
|
||||
class PaymentSummary extends StatelessWidget {
|
||||
final double spacing;
|
||||
|
||||
const PaymentSummary({super.key, required this.spacing});
|
||||
|
||||
Currency _currencyForSource(PaymentSource? source) {
|
||||
if (source == null) return Currency.usdt;
|
||||
return switch (source.type) {
|
||||
PaymentSourceType.wallet => source.wallet!.currency,
|
||||
PaymentSourceType.ledger => () {
|
||||
final code = source.ledgerAccount?.currency.trim().toUpperCase() ?? '';
|
||||
try {
|
||||
return currencyStringToCode(code);
|
||||
} catch (_) {
|
||||
return Currency.rub;
|
||||
}
|
||||
}(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
PaymentSentAmountRow(currency: currencyStringToCode(context.read<WalletsController>().selectedWallet?.tokenSymbol ?? 'USDT')),
|
||||
const PaymentFeeRow(),
|
||||
const PaymentRecipientReceivesRow(),
|
||||
SizedBox(height: spacing),
|
||||
const PaymentTotalRow(),
|
||||
],
|
||||
),
|
||||
);
|
||||
Widget build(BuildContext context) {
|
||||
final source = context.watch<PaymentSourceController>().selectedSource;
|
||||
final sentCurrency = _currencyForSource(source);
|
||||
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
PaymentSentAmountRow(currency: sentCurrency),
|
||||
const PaymentFeeRow(),
|
||||
const PaymentRecipientReceivesRow(),
|
||||
SizedBox(height: spacing),
|
||||
const PaymentTotalRow(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user