dev
dart 187 lines 6.23 KB
Raw
1 import 'package:cake_wallet/core/execution_state.dart';
2 import 'package:cake_wallet/generated/i18n.dart';
3 import 'package:cake_wallet/new-ui/widgets/confirm_swiper.dart';
4 import 'package:cake_wallet/new-ui/widgets/hardware_wallet/proceed_on_device_message.dart';
5 import 'package:cake_wallet/new-ui/widgets/new_primary_button.dart';
6 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
7 import 'package:cake_wallet/view_model/send/send_view_model.dart';
8 import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
9 import 'package:flutter/cupertino.dart';
10 import 'package:flutter/material.dart';
11 import 'package:flutter_mobx/flutter_mobx.dart';
12
13 class SendConfirmBottomWidget extends StatelessWidget {
14 const SendConfirmBottomWidget({super.key, required this.sendViewModel});
15
16 final SendViewModel sendViewModel;
17
18 @override
19 Widget build(BuildContext context) {
20 return Observer(builder: (_) {
21 return Center(
22 child: AnimatedSize(
23 alignment: Alignment.bottomCenter,
24 duration: Duration(milliseconds: 150),
25 curve: Curves.easeOutCubic,
26 child: AnimatedSwitcher(
27 duration: Duration(milliseconds: 150),
28 switchInCurve: Curves.easeOutCubic,
29 switchOutCurve: Curves.easeInCubic,
30 child: Container(
31 key: ValueKey(sendViewModel.state.runtimeType),
32 child: _buildBottomWidget(
33 context,
34 sendViewModel.state.runtimeType,
35 ),
36 ),
37 ),
38 ),
39 );
40 });
41 }
42
43 Widget _buildBottomWidget(BuildContext context, Type state) {
44 switch (state) {
45 case ExecutedSuccessfullyState:
46 return ConfirmSwiper(
47 onConfirmed: () {
48 sendViewModel.commitTransaction(context);
49 },
50 swiperText: "${S.of(context).swipe_to_send}",
51 accessibleNavigationModeButtonText: S.of(context).send);
52 case IsExecutingState:
53 return LoadingBottomWidget(
54 text: "${S.of(context).generating_transaction}...",
55 );
56 case FailureState:
57 return TransactionErrorActions(errorText: (sendViewModel.state as FailureState).error);
58 case IsDeviceSigningResponseState:
59 return LoadingBottomWidget(
60 text: "${S.of(context).signing_transaction}...",
61 );
62 case IsAwaitingDeviceResponseState:
63 return HardwareWalletProceedOnDeviceMessage(
64 hardwareWalletType: sendViewModel.wallet.hardwareWalletType!);
65 case TransactionCommitting:
66 return LoadingBottomWidget(
67 text: "${S.of(context).sending}...",
68 );
69 case TransactionCommitted:
70 return SizedBox.shrink();
71 default:
72 return SizedBox.shrink();
73 }
74 }
75 }
76
77 class LoadingBottomWidget extends StatelessWidget {
78 const LoadingBottomWidget({super.key, required this.text});
79
80 final String text;
81
82 @override
83 Widget build(BuildContext context) {
84 // One node per state so each step of the send is announced exactly once.
85 return Semantics(
86 container: true,
87 liveRegion: true,
88 label: text,
89 excludeSemantics: true,
90 child: Row(
91 mainAxisAlignment: MainAxisAlignment.center,
92 spacing: 12,
93 children: [
94 CupertinoActivityIndicator(
95 color: Theme.of(context).colorScheme.onSurfaceVariant,
96 ),
97 Text(
98 text,
99 style: TextStyle(color: Theme.of(context).colorScheme.onSurfaceVariant),
100 )
101 ],
102 ),
103 );
104 }
105 }
106
107 class TransactionErrorActions extends StatelessWidget {
108 const TransactionErrorActions({super.key, required this.errorText});
109
110 final String errorText;
111
112 @override
113 Widget build(BuildContext context) {
114 return Column(
115 spacing: 12,
116 children: [
117 Semantics(
118 container: true,
119 liveRegion: true,
120 label: "${S.of(context).transaction_error}\n$errorText",
121 excludeSemantics: true,
122 child: Container(
123 decoration: BoxDecoration(
124 color: Theme.of(context).colorScheme.errorContainer.withAlpha(64),
125 borderRadius: BorderRadius.circular(16),
126 ),
127 child: Padding(
128 padding: const EdgeInsets.all(12.0),
129 child: Column(
130 spacing: 12,
131 children: [
132 Row(
133 mainAxisAlignment: MainAxisAlignment.center,
134 spacing: 8,
135 children: [
136 CakeImageWidget(
137 imageUrl: "assets/new-ui/warning.svg",
138 height: 24,
139 width: 24,
140 colorFilter:
141 ColorFilter.mode(Theme.of(context).colorScheme.error, BlendMode.srcIn),
142 ),
143 Text(
144 S.of(context).transaction_error,
145 style: TextStyle(
146 fontSize: 16,
147 fontWeight: FontWeight.w400,
148 color: Theme.of(context).colorScheme.error),
149 )
150 ],
151 ),
152 Text(
153 errorText,
154 style: TextStyle(
155 fontSize: 14,
156 fontWeight: FontWeight.w400,
157 color: Theme.of(context).colorScheme.error),
158 textAlign: TextAlign.center,
159 ),
160 ],
161 ),
162 ),
163 ),
164 ),
165 Row(
166 spacing: 8,
167 children: [
168 // Flexible(
169 // child: NewPrimaryButton(
170 // onPressed: () {},
171 // text: S.of(context).more_details,
172 // color: Theme.of(context).colorScheme.surfaceContainer,
173 // textColor: Theme.of(context).colorScheme.primary),
174 // ),
175 Flexible(
176 child: NewPrimaryButton(
177 onPressed: Navigator.of(context).maybePop,
178 text: S.of(context).close,
179 color: Theme.of(context).colorScheme.primary,
180 textColor: Theme.of(context).colorScheme.onPrimary),
181 ),
182 ],
183 )
184 ],
185 );
186 }
187 }