dev
dart 132 lines 3.69 KB
Raw
1 import 'package:cake_wallet/generated/i18n.dart';
2 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
3 import 'package:cake_wallet/themes/core/custom_theme_colors.dart';
4 import 'package:flutter/material.dart';
5 import 'package:reown_walletkit/reown_walletkit.dart';
6
7 enum WCDappCardAction { connect, sign, connected }
8
9 class WCDappCard extends StatelessWidget {
10 const WCDappCard({
11 super.key,
12 required this.name,
13 required this.iconUrl,
14 required this.subtitle,
15 required this.action,
16 this.verifyContext,
17 });
18
19 final String name;
20 final String? iconUrl;
21 final String subtitle;
22 final WCDappCardAction action;
23 final VerifyContext? verifyContext;
24
25 String _actionLine(BuildContext context) {
26 switch (action) {
27 case WCDappCardAction.connect:
28 return S.of(context).wc_would_like_to_connect_to(name);
29 case WCDappCardAction.sign:
30 return S.of(context).wc_would_like_to_sign(name);
31 case WCDappCardAction.connected:
32 return S.of(context).wc_connected_to(name);
33 }
34 }
35
36 @override
37 Widget build(BuildContext context) {
38 final colors = Theme.of(context).colorScheme;
39
40 return Container(
41 width: double.infinity,
42 decoration: BoxDecoration(
43 color: colors.surfaceContainer,
44 borderRadius: BorderRadius.circular(20),
45 ),
46 padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
47 child: Column(
48 crossAxisAlignment: CrossAxisAlignment.center,
49 children: [
50 SizedBox(
51 width: 56,
52 height: 56,
53 child: CakeImageWidget(
54 borderRadius: 16,
55 imageUrl: iconUrl,
56 fit: BoxFit.cover,
57 errorWidget: CakeImageWidget(
58 imageUrl: 'assets/new-ui/walletconnect_icon.svg',
59 width: 40,
60 height: 40,
61 ),
62 ),
63 ),
64 const SizedBox(height: 10),
65 Text(
66 _actionLine(context),
67 textAlign: TextAlign.center,
68 style: Theme.of(context).textTheme.titleMedium!.copyWith(
69 fontWeight: FontWeight.w600,
70 color: colors.onSurface,
71 ),
72 ),
73 if (subtitle.trim().isNotEmpty) ...[
74 const SizedBox(height: 10),
75 Text(
76 subtitle,
77 textAlign: TextAlign.center,
78 style: Theme.of(context).textTheme.bodySmall!.copyWith(
79 color: colors.onSurfaceVariant,
80 ),
81 ),
82 ],
83 if (_shouldShowBadge()) ...[
84 const SizedBox(height: 10),
85 _VerifyBadge(verifyContext: verifyContext!),
86 ],
87 ],
88 ),
89 );
90 }
91
92 bool _shouldShowBadge() {
93 if (verifyContext == null) return false;
94 if (verifyContext!.validation.scam) return false;
95 return true;
96 }
97 }
98
99 class _VerifyBadge extends StatelessWidget {
100 const _VerifyBadge({required this.verifyContext});
101
102 final VerifyContext verifyContext;
103
104 @override
105 Widget build(BuildContext context) {
106 final IconData icon;
107 final Color color;
108 final String label;
109
110 if (verifyContext.validation.valid) {
111 icon = Icons.check_circle;
112 color = CustomThemeColors.syncGreen;
113 label = S.of(context).wc_verified;
114 } else {
115 icon = Icons.warning_amber_rounded;
116 color = CustomThemeColors.syncYellow;
117 label = S.of(context).wc_not_verified;
118 }
119
120 return Row(
121 mainAxisSize: MainAxisSize.min,
122 children: [
123 Icon(icon, size: 16, color: color),
124 const SizedBox(width: 4),
125 Text(
126 label,
127 style: Theme.of(context).textTheme.bodySmall!.copyWith(color: color),
128 ),
129 ],
130 );
131 }
132 }