refactor of money utils with new money2 package
This commit is contained in:
@@ -2,6 +2,6 @@ import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/models/payment/chain_network.dart';
|
||||
|
||||
|
||||
const Currency managedCurrencyDefault = Currency.usdt;
|
||||
const Currency ledgerCurrencyDefault = Currency.rub;
|
||||
const CurrencyCode managedCurrencyDefault = CurrencyCode.usdt;
|
||||
const CurrencyCode ledgerCurrencyDefault = CurrencyCode.rub;
|
||||
const ChainNetwork managedNetworkDefault = ChainNetwork.tronMainnet;
|
||||
|
||||
@@ -8,11 +8,9 @@ import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/models/describable.dart';
|
||||
import 'package:pshared/models/payment/chain_network.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/wallet/chain_asset.dart';
|
||||
import 'package:pshared/provider/accounts/employees.dart';
|
||||
import 'package:pshared/provider/ledger.dart';
|
||||
import 'package:pshared/provider/payment/wallets.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/add/form.dart';
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/add/constants.dart';
|
||||
@@ -42,9 +40,9 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
|
||||
PaymentType _assetType = PaymentType.managedWallet;
|
||||
String? _ownerRef;
|
||||
Currency _managedCurrency = managedCurrencyDefault;
|
||||
CurrencyCode _managedCurrency = managedCurrencyDefault;
|
||||
ChainNetwork _network = managedNetworkDefault;
|
||||
Currency _ledgerCurrency = ledgerCurrencyDefault;
|
||||
CurrencyCode _ledgerCurrency = ledgerCurrencyDefault;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -60,7 +58,7 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
|
||||
void _setOwnerRef(String? value) => setState(() => _ownerRef = value);
|
||||
|
||||
void _setManagedCurrency(Currency? value) {
|
||||
void _setManagedCurrency(CurrencyCode? value) {
|
||||
if (value == null) return;
|
||||
setState(() => _managedCurrency = value);
|
||||
}
|
||||
@@ -70,7 +68,7 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
setState(() => _network = value);
|
||||
}
|
||||
|
||||
void _setLedgerCurrency(Currency? value) {
|
||||
void _setLedgerCurrency(CurrencyCode? value) {
|
||||
if (value == null) return;
|
||||
setState(() => _ledgerCurrency = value);
|
||||
}
|
||||
@@ -102,7 +100,8 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
if (_assetType == PaymentType.managedWallet) {
|
||||
await context.read<WalletsProvider>().create(
|
||||
describable: newDescribable(name: name, description: description),
|
||||
asset: ChainAsset(chain: _network, tokenSymbol: currencyCodeToString(_managedCurrency)),
|
||||
chain: _network,
|
||||
currency: _managedCurrency,
|
||||
ownerRef: owner?.id,
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -23,12 +23,12 @@ class AddBalanceForm extends StatelessWidget {
|
||||
final ValueChanged<String?> onOwnerChanged;
|
||||
final TextEditingController nameController;
|
||||
final TextEditingController descriptionController;
|
||||
final Currency managedCurrency;
|
||||
final CurrencyCode managedCurrency;
|
||||
final ChainNetwork network;
|
||||
final Currency ledgerCurrency;
|
||||
final ValueChanged<Currency?> onManagedCurrencyChanged;
|
||||
final CurrencyCode ledgerCurrency;
|
||||
final ValueChanged<CurrencyCode?> onManagedCurrencyChanged;
|
||||
final ValueChanged<ChainNetwork?> onNetworkChanged;
|
||||
final ValueChanged<Currency?> onLedgerCurrencyChanged;
|
||||
final ValueChanged<CurrencyCode?> onLedgerCurrencyChanged;
|
||||
final bool showEmployeesLoading;
|
||||
|
||||
const AddBalanceForm({
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
DropdownMenuItem<Currency> currencyItem(Currency currency) => DropdownMenuItem(
|
||||
DropdownMenuItem<CurrencyCode> currencyItem(CurrencyCode currency) => DropdownMenuItem(
|
||||
value: currency,
|
||||
child: Text(currencyCodeToString(currency)),
|
||||
);
|
||||
@@ -10,8 +10,8 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class LedgerFields extends StatelessWidget {
|
||||
final Currency currency;
|
||||
final ValueChanged<Currency?>? onCurrencyChanged;
|
||||
final CurrencyCode currency;
|
||||
final ValueChanged<CurrencyCode?>? onCurrencyChanged;
|
||||
|
||||
const LedgerFields({
|
||||
super.key,
|
||||
@@ -20,7 +20,7 @@ class LedgerFields extends StatelessWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => DropdownButtonFormField<Currency>(
|
||||
Widget build(BuildContext context) => DropdownButtonFormField<CurrencyCode>(
|
||||
initialValue: currency,
|
||||
decoration: getInputDecoration(context, AppLocalizations.of(context)!.currency, true),
|
||||
items: [
|
||||
|
||||
@@ -12,9 +12,9 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class ManagedWalletFields extends StatelessWidget {
|
||||
final Currency currency;
|
||||
final CurrencyCode currency;
|
||||
final ChainNetwork network;
|
||||
final ValueChanged<Currency?>? onCurrencyChanged;
|
||||
final ValueChanged<CurrencyCode?>? onCurrencyChanged;
|
||||
final ValueChanged<ChainNetwork?>? onNetworkChanged;
|
||||
|
||||
const ManagedWalletFields({
|
||||
@@ -31,7 +31,7 @@ class ManagedWalletFields extends StatelessWidget {
|
||||
return Column(
|
||||
spacing: 12,
|
||||
children: [
|
||||
DropdownButtonFormField<Currency>(
|
||||
DropdownButtonFormField<CurrencyCode>(
|
||||
initialValue: currency,
|
||||
decoration: getInputDecoration(context, l10n.currency, true),
|
||||
items: [
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
@@ -28,12 +27,10 @@ class BalanceAmount extends StatelessWidget {
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final currencyBalance = currencyCodeToSymbol(wallet.currency);
|
||||
final formattedBalance = formatMoneyUi(
|
||||
final formattedBalance = formatAmountUi(
|
||||
context,
|
||||
Money(
|
||||
amount: amountToString(wallet.balance),
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
),
|
||||
amount: wallet.balance,
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
);
|
||||
final wallets = context.watch<WalletsController>();
|
||||
final isMasked = wallets.isBalanceMasked(wallet.id);
|
||||
|
||||
@@ -36,9 +36,7 @@ class PaymentAmountField extends StatelessWidget {
|
||||
decoration: InputDecoration(
|
||||
labelText: loc.amount,
|
||||
border: const OutlineInputBorder(),
|
||||
prefixText: symbol == null
|
||||
? null
|
||||
: withTrailingNonBreakingSpace(symbol),
|
||||
prefixText: symbol == null ? null : '$symbol ',
|
||||
),
|
||||
onChanged: ui.handleChanged,
|
||||
),
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/controllers/payouts/multiple_payouts.dart';
|
||||
import 'package:pweb/models/dashboard/summary_values.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/summary/widget.dart';
|
||||
@@ -28,21 +26,12 @@ class SourceQuoteSummary extends StatelessWidget {
|
||||
values: PaymentSummaryValues(
|
||||
fee: controller.aggregateFeeAmount == null
|
||||
? l10n.noFee
|
||||
: formatMoneyUiWithL10n(
|
||||
l10n,
|
||||
controller.aggregateFeeAmount,
|
||||
separator: nonBreakingSpace,
|
||||
),
|
||||
recipientReceives: formatMoneyUiWithL10n(
|
||||
l10n,
|
||||
: formatMoneyUi(context, controller.aggregateFeeAmount),
|
||||
recipientReceives: formatMoneyUi(
|
||||
context,
|
||||
controller.aggregateSettlementAmount,
|
||||
separator: nonBreakingSpace,
|
||||
),
|
||||
total: formatMoneyUiWithL10n(
|
||||
l10n,
|
||||
controller.aggregateDebitAmount,
|
||||
separator: nonBreakingSpace,
|
||||
),
|
||||
total: formatMoneyUi(context, controller.aggregateDebitAmount),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ class UploadHistorySection extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProxyProvider<PaymentsProvider, RecentPaymentsController>(
|
||||
return ChangeNotifierProxyProvider<
|
||||
PaymentsProvider,
|
||||
RecentPaymentsController
|
||||
>(
|
||||
create: (_) => RecentPaymentsController(),
|
||||
update: (_, payments, controller) => controller!..update(payments),
|
||||
child: const _RecentPaymentsView(),
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:pweb/pages/dashboard/payouts/summary/row.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentFeeRow extends StatelessWidget {
|
||||
const PaymentFeeRow({super.key});
|
||||
|
||||
@@ -19,7 +18,7 @@ class PaymentFeeRow extends StatelessWidget {
|
||||
final l10 = AppLocalizations.of(context)!;
|
||||
return PaymentSummaryRow(
|
||||
labelFactory: l10.fee,
|
||||
asset: fee,
|
||||
money: fee,
|
||||
value: fee == null ? l10.noFee : null,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
);
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:pweb/pages/dashboard/payouts/summary/row.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentRecipientReceivesRow extends StatelessWidget {
|
||||
const PaymentRecipientReceivesRow({super.key});
|
||||
|
||||
@@ -16,7 +15,7 @@ class PaymentRecipientReceivesRow extends StatelessWidget {
|
||||
Widget build(BuildContext context) => Consumer<QuotationProvider>(
|
||||
builder: (context, provider, _) => PaymentSummaryRow(
|
||||
labelFactory: AppLocalizations.of(context)!.recipientWillReceive,
|
||||
asset: provider.recipientGets,
|
||||
money: provider.recipientGets,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/asset.dart';
|
||||
import 'package:money2/money2.dart';
|
||||
|
||||
import 'package:pweb/utils/money_display.dart';
|
||||
|
||||
|
||||
class PaymentSummaryRow extends StatelessWidget {
|
||||
final String Function(String) labelFactory;
|
||||
final Asset? asset;
|
||||
final Money? money;
|
||||
final String? value;
|
||||
final TextStyle? style;
|
||||
|
||||
const PaymentSummaryRow({
|
||||
super.key,
|
||||
required this.labelFactory,
|
||||
required this.asset,
|
||||
required this.money,
|
||||
this.value,
|
||||
this.style,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final formatted = value ?? formatAssetUi(context, asset);
|
||||
final formatted = value ?? formatMoneyUi(context, money);
|
||||
return Text(labelFactory(formatted), style: style);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:pweb/pages/dashboard/payouts/summary/row.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentTotalRow extends StatelessWidget {
|
||||
const PaymentTotalRow({super.key});
|
||||
|
||||
@@ -16,8 +15,10 @@ class PaymentTotalRow extends StatelessWidget {
|
||||
Widget build(BuildContext context) => Consumer<QuotationProvider>(
|
||||
builder: (context, provider, _) => PaymentSummaryRow(
|
||||
labelFactory: AppLocalizations.of(context)!.total,
|
||||
asset: provider.total,
|
||||
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w600),
|
||||
money: provider.total,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,16 +8,11 @@ import 'package:pweb/pages/dashboard/payouts/summary/total.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentSummary extends StatelessWidget {
|
||||
final double spacing;
|
||||
final PaymentSummaryValues? values;
|
||||
|
||||
const PaymentSummary({
|
||||
super.key,
|
||||
required this.spacing,
|
||||
this.values,
|
||||
});
|
||||
const PaymentSummary({super.key, required this.spacing, this.values});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -32,20 +27,20 @@ class PaymentSummary extends StatelessWidget {
|
||||
children: [
|
||||
PaymentSummaryRow(
|
||||
labelFactory: loc.fee,
|
||||
asset: null,
|
||||
money: null,
|
||||
value: resolvedValues.fee,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
PaymentSummaryRow(
|
||||
labelFactory: loc.recipientWillReceive,
|
||||
asset: null,
|
||||
money: null,
|
||||
value: resolvedValues.recipientReceives,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
SizedBox(height: spacing),
|
||||
PaymentSummaryRow(
|
||||
labelFactory: loc.total,
|
||||
asset: null,
|
||||
money: null,
|
||||
value: resolvedValues.total,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -69,4 +64,4 @@ class PaymentSummary extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user