| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/utils/clipboard_util.dart'; |
| 3 | import 'package:cake_wallet/utils/show_bar.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter/services.dart'; |
| 6 | |
| 7 | class WCWalletCard extends StatelessWidget { |
| 8 | const WCWalletCard({ |
| 9 | super.key, |
| 10 | required this.walletName, |
| 11 | required this.address, |
| 12 | }); |
| 13 | |
| 14 | final String walletName; |
| 15 | final String address; |
| 16 | |
| 17 | static String _truncate(String value) { |
| 18 | if (value.length <= 14) return value; |
| 19 | return '${value.substring(0, 6)}...${value.substring(value.length - 7)}'; |
| 20 | } |
| 21 | |
| 22 | @override |
| 23 | Widget build(BuildContext context) { |
| 24 | final colors = Theme.of(context).colorScheme; |
| 25 | |
| 26 | return Container( |
| 27 | width: double.infinity, |
| 28 | decoration: BoxDecoration( |
| 29 | color: colors.surfaceContainer, |
| 30 | borderRadius: BorderRadius.circular(20), |
| 31 | ), |
| 32 | padding: const EdgeInsets.symmetric(horizontal: 16), |
| 33 | child: Column( |
| 34 | children: [ |
| 35 | WalletDetailEntry(label: S.of(context).wallet, value: walletName), |
| 36 | Divider(height: 1, color: colors.outlineVariant), |
| 37 | WalletDetailEntry( |
| 38 | label: S.of(context).address, |
| 39 | value: _truncate(address), |
| 40 | onTap: address.isEmpty |
| 41 | ? null |
| 42 | : () async { |
| 43 | await ClipboardUtil.setSensitiveDataToClipboard( |
| 44 | ClipboardData(text: address), |
| 45 | ); |
| 46 | if (!context.mounted) return; |
| 47 | showBar<void>(context, S.of(context).copied_to_clipboard); |
| 48 | }, |
| 49 | ), |
| 50 | ], |
| 51 | ), |
| 52 | ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | class WalletDetailEntry extends StatelessWidget { |
| 57 | const WalletDetailEntry({required this.label, required this.value, this.onTap}); |
| 58 | |
| 59 | final String label; |
| 60 | final String value; |
| 61 | final VoidCallback? onTap; |
| 62 | |
| 63 | @override |
| 64 | Widget build(BuildContext context) { |
| 65 | final colors = Theme.of(context).colorScheme; |
| 66 | |
| 67 | return InkWell( |
| 68 | onTap: onTap, |
| 69 | borderRadius: BorderRadius.circular(8), |
| 70 | child: Padding( |
| 71 | padding: const EdgeInsets.symmetric(vertical: 16), |
| 72 | child: Row( |
| 73 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 74 | children: [ |
| 75 | Text( |
| 76 | label, |
| 77 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 78 | fontWeight: FontWeight.w500, |
| 79 | ), |
| 80 | ), |
| 81 | Flexible( |
| 82 | child: Text( |
| 83 | value, |
| 84 | overflow: TextOverflow.ellipsis, |
| 85 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 86 | color: colors.onSurfaceVariant, |
| 87 | ), |
| 88 | ), |
| 89 | ), |
| 90 | ], |
| 91 | ), |
| 92 | ), |
| 93 | ); |
| 94 | } |
| 95 | } |