Top Up Balance logic and Added fixes for routing
This commit is contained in:
96
frontend/pweb/lib/pages/wallet_top_up/address_block.dart
Normal file
96
frontend/pweb/lib/pages/wallet_top_up/address_block.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class WalletTopUpAddressBlock extends StatelessWidget {
|
||||
final String address;
|
||||
final AppDimensions dimensions;
|
||||
|
||||
const WalletTopUpAddressBlock({
|
||||
super.key,
|
||||
required this.address,
|
||||
required this.dimensions,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
loc.walletTopUpAddressLabel,
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.copy, size: 16),
|
||||
label: Text(loc.copyAddress),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: address));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(loc.addressCopied)),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(dimensions.paddingMedium),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
color: theme.colorScheme.surfaceVariant.withOpacity(0.4),
|
||||
),
|
||||
child: SelectableText(
|
||||
address,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
fontFeatures: const [FontFeature.tabularFigures()],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
Text(
|
||||
loc.walletTopUpQrLabel,
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: EdgeInsets.all(dimensions.paddingMedium),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
color: theme.colorScheme.surfaceVariant.withOpacity(0.4),
|
||||
),
|
||||
child: Center(
|
||||
child: QrImageView(
|
||||
data: address,
|
||||
backgroundColor: theme.colorScheme.onSecondary,
|
||||
eyeStyle: QrEyeStyle(
|
||||
eyeShape: QrEyeShape.square,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
dataModuleStyle: QrDataModuleStyle(
|
||||
dataModuleShape: QrDataModuleShape.square,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
size: 220,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
76
frontend/pweb/lib/pages/wallet_top_up/content.dart
Normal file
76
frontend/pweb/lib/pages/wallet_top_up/content.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/models/wallet.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/currency.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class WalletTopUpContent extends StatelessWidget {
|
||||
final Wallet wallet;
|
||||
final VoidCallback onBack;
|
||||
|
||||
const WalletTopUpContent({
|
||||
super.key,
|
||||
required this.wallet,
|
||||
required this.onBack,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dimensions = AppDimensions();
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final address = _resolveAddress(wallet);
|
||||
final network = wallet.network?.trim();
|
||||
final assetLabel = wallet.tokenSymbol ?? currencyCodeToSymbol(wallet.currency);
|
||||
|
||||
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,
|
||||
walletName: wallet.name,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
WalletTopUpMeta(
|
||||
assetLabel: assetLabel,
|
||||
network: network,
|
||||
walletId: wallet.walletUserID,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingXLarge),
|
||||
WalletTopUpDetails(
|
||||
address: address,
|
||||
dimensions: dimensions,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String? _resolveAddress(Wallet wallet) {
|
||||
final candidate = wallet.depositAddress?.trim();
|
||||
if (candidate == null || candidate.isEmpty) return null;
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
60
frontend/pweb/lib/pages/wallet_top_up/details.dart
Normal file
60
frontend/pweb/lib/pages/wallet_top_up/details.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/pages/wallet_top_up/address_block.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class WalletTopUpDetails extends StatelessWidget {
|
||||
final String? address;
|
||||
final AppDimensions dimensions;
|
||||
|
||||
const WalletTopUpDetails({
|
||||
super.key,
|
||||
required this.address,
|
||||
required this.dimensions,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
loc.walletTopUpDetailsTitle,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
loc.walletTopUpDescription,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
if (address == null || address!.isEmpty)
|
||||
Text(
|
||||
loc.walletTopUpUnavailable,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
)
|
||||
else ...[
|
||||
WalletTopUpAddressBlock(
|
||||
address: address!,
|
||||
dimensions: dimensions,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
Text(
|
||||
loc.walletTopUpHint,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
47
frontend/pweb/lib/pages/wallet_top_up/header.dart
Normal file
47
frontend/pweb/lib/pages/wallet_top_up/header.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class WalletTopUpHeader extends StatelessWidget {
|
||||
final VoidCallback onBack;
|
||||
final String walletName;
|
||||
|
||||
const WalletTopUpHeader({
|
||||
super.key,
|
||||
required this.onBack,
|
||||
required this.walletName,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
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,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
walletName,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
48
frontend/pweb/lib/pages/wallet_top_up/info_chip.dart
Normal file
48
frontend/pweb/lib/pages/wallet_top_up/info_chip.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class WalletTopUpInfoChip extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
const WalletTopUpInfoChip({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final dimensions = AppDimensions();
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.all(dimensions.paddingMedium),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
color: theme.colorScheme.surfaceVariant.withOpacity(0.4),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
37
frontend/pweb/lib/pages/wallet_top_up/meta.dart
Normal file
37
frontend/pweb/lib/pages/wallet_top_up/meta.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/pages/wallet_top_up/info_chip.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class WalletTopUpMeta extends StatelessWidget {
|
||||
final String assetLabel;
|
||||
final String walletId;
|
||||
final String? network;
|
||||
|
||||
const WalletTopUpMeta({
|
||||
super.key,
|
||||
required this.assetLabel,
|
||||
required this.walletId,
|
||||
this.network,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
final dimensions = AppDimensions();
|
||||
|
||||
return Wrap(
|
||||
spacing: dimensions.paddingLarge,
|
||||
runSpacing: dimensions.paddingLarge,
|
||||
children: [
|
||||
WalletTopUpInfoChip(label: loc.walletTopUpAssetLabel, value: assetLabel),
|
||||
if (network != null && network!.isNotEmpty)
|
||||
WalletTopUpInfoChip(label: loc.walletTopUpNetworkLabel, value: network!),
|
||||
WalletTopUpInfoChip(label: loc.walletId, value: walletId),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
44
frontend/pweb/lib/pages/wallet_top_up/page.dart
Normal file
44
frontend/pweb/lib/pages/wallet_top_up/page.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/pages/wallet_top_up/content.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class WalletTopUpPage extends StatelessWidget {
|
||||
final VoidCallback onBack;
|
||||
|
||||
const WalletTopUpPage({super.key, required this.onBack});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Consumer<WalletsProvider>(
|
||||
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 wallet = provider.selectedWallet;
|
||||
if (wallet == null) {
|
||||
return Center(child: Text(loc.noWalletSelected));
|
||||
}
|
||||
|
||||
return WalletTopUpContent(
|
||||
wallet: wallet,
|
||||
onBack: onBack,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user