WIP: integration with ledger

This commit is contained in:
Arseni
2026-02-04 02:01:22 +03:00
parent f1f16a30e6
commit f44ef56ff3
32 changed files with 1226 additions and 405 deletions

View File

@@ -2,15 +2,16 @@ import 'package:flutter/material.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
class WalletTopUpHeader extends StatelessWidget {
final VoidCallback onBack;
final String? tokenSymbol;
final String? sourceLabel;
const WalletTopUpHeader({
super.key,
required this.onBack,
this.tokenSymbol,
this.sourceLabel,
});
@override
@@ -20,24 +21,18 @@ class WalletTopUpHeader extends StatelessWidget {
final symbol = tokenSymbol?.trim();
final subtitle = [
loc.paymentTypeCryptoWallet,
sourceLabel ?? loc.paymentTypeCryptoWallet,
if (symbol != null && symbol.isNotEmpty) symbol,
].join(' · ');
return Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: onBack,
),
IconButton(icon: const Icon(Icons.arrow_back), onPressed: onBack),
const SizedBox(width: 8),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
loc.walletTopUpTitle,
style: theme.textTheme.titleLarge,
),
Text(loc.walletTopUpTitle, style: theme.textTheme.titleLarge),
const SizedBox(height: 4),
Text(
subtitle,

View File

@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:pshared/models/ledger/account.dart';
import 'package:pweb/pages/wallet_top_up/details.dart';
import 'package:pweb/pages/wallet_top_up/header.dart';
import 'package:pweb/pages/wallet_top_up/meta.dart';
import 'package:pweb/utils/dimensions.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
class LedgerTopUpContent extends StatelessWidget {
final LedgerAccount account;
final VoidCallback onBack;
const LedgerTopUpContent({
super.key,
required this.account,
required this.onBack,
});
@override
Widget build(BuildContext context) {
final dimensions = AppDimensions();
final theme = Theme.of(context);
final loc = AppLocalizations.of(context)!;
return Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 960),
child: Padding(
padding: EdgeInsets.symmetric(vertical: dimensions.paddingLarge),
child: Material(
elevation: dimensions.elevationSmall,
color: theme.colorScheme.onSecondary,
borderRadius: BorderRadius.circular(
dimensions.borderRadiusMedium,
),
child: Padding(
padding: EdgeInsets.all(dimensions.paddingXLarge),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
WalletTopUpHeader(
onBack: onBack,
tokenSymbol: account.currency,
sourceLabel: loc.paymentTypeLedger,
),
SizedBox(height: dimensions.paddingLarge),
WalletTopUpMeta(
assetLabel: account.currency,
walletId: account.accountCode,
idLabel: loc.ledgerAccountRef,
),
SizedBox(height: dimensions.paddingXLarge),
WalletTopUpDetails(
address: account.ledgerAccountRef,
dimensions: dimensions,
),
],
),
),
),
),
),
),
);
}
}

View File

@@ -10,12 +10,14 @@ class WalletTopUpMeta extends StatelessWidget {
final String assetLabel;
final String walletId;
final String? network;
final String? idLabel;
const WalletTopUpMeta({
super.key,
required this.assetLabel,
required this.walletId,
this.network,
this.idLabel,
});
@override
@@ -27,10 +29,16 @@ class WalletTopUpMeta extends StatelessWidget {
spacing: dimensions.paddingLarge,
runSpacing: dimensions.paddingLarge,
children: [
WalletTopUpInfoChip(label: loc.walletTopUpAssetLabel, value: assetLabel),
WalletTopUpInfoChip(
label: loc.walletTopUpAssetLabel,
value: assetLabel,
),
if (network != null && network!.isNotEmpty)
WalletTopUpInfoChip(label: loc.walletTopUpNetworkLabel, value: network!),
WalletTopUpInfoChip(label: loc.walletId, value: walletId),
WalletTopUpInfoChip(
label: loc.walletTopUpNetworkLabel,
value: network!,
),
WalletTopUpInfoChip(label: idLabel ?? loc.walletId, value: walletId),
],
);
}

View File

@@ -1,10 +1,15 @@
import 'package:flutter/material.dart';
import 'package:collection/collection.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/provider/ledger.dart';
import 'package:pweb/pages/wallet_top_up/content.dart';
import 'package:pweb/pages/wallet_top_up/ledger_content.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
@@ -17,27 +22,55 @@ class WalletTopUpPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context)!;
final source = context.watch<PaymentSourceController>().selectedSource;
return Consumer<WalletsController>(builder: (context, provider, child) {
if (provider.isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (source == null) {
return Center(child: Text(loc.noWalletSelected));
}
if (provider.error != null) {
return Center(
child: Text(loc.notificationError(provider.error.toString())),
);
}
return switch (source.type) {
PaymentSourceType.wallet => Consumer<WalletsController>(
builder: (context, provider, child) {
if (provider.isLoading) {
return const Center(child: CircularProgressIndicator());
}
final wallet = provider.selectedWallet;
if (wallet == null) {
return Center(child: Text(loc.noWalletSelected));
}
if (provider.error != null) {
return Center(
child: Text(loc.notificationError(provider.error.toString())),
);
}
return WalletTopUpContent(
wallet: wallet,
onBack: onBack,
);
});
final wallet = provider.selectedWallet;
if (wallet == null) {
return Center(child: Text(loc.noWalletSelected));
}
return WalletTopUpContent(wallet: wallet, onBack: onBack);
},
),
PaymentSourceType.ledger => Consumer<LedgerAccountsProvider>(
builder: (context, provider, child) {
if (provider.isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (provider.error != null) {
return Center(
child: Text(loc.notificationError(provider.error.toString())),
);
}
final account = provider.accounts.firstWhereOrNull(
(item) => item.ledgerAccountRef == source.id,
);
if (account == null) {
return Center(child: Text(loc.noWalletSelected));
}
return LedgerTopUpContent(account: account, onBack: onBack);
},
),
};
}
}