dev
dart 211 lines 9.23 KB
Raw
1 import 'package:cake_wallet/bitcoin/bitcoin.dart';
2 import 'package:cake_wallet/generated/i18n.dart';
3 import 'package:cake_wallet/new-ui/widgets/new_primary_button.dart';
4 import 'package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart';
5 import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart';
6 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
7 import 'package:cake_wallet/utils/address_formatter.dart';
8 import 'package:cake_wallet/utils/clipboard_util.dart';
9 import 'package:cake_wallet/view_model/send/send_view_model.dart';
10 import 'package:cw_core/payment_uris.dart';
11 import 'package:flutter/cupertino.dart';
12 import 'package:flutter/material.dart';
13 import "package:cw_core/wallet_type.dart";
14
15 class L2SendExternalModal extends StatefulWidget {
16 const L2SendExternalModal({super.key, required this.sendViewModel});
17
18 final SendViewModel sendViewModel;
19
20 @override
21 State<L2SendExternalModal> createState() => _L2SendExternalModalState();
22 }
23
24 class _L2SendExternalModalState extends State<L2SendExternalModal> {
25 PaymentURI? uri;
26 bool largeQrMode = false;
27 static const warningTextColor = Color(0xFFFFB84E);
28 static const warningBackgroundColor = Color(0xFF8E5800);
29
30 @override
31 void initState() {
32 super.initState();
33 () async {
34 if (widget.sendViewModel.wallet.type == WalletType.bitcoin) {
35 await bitcoin!.setAddressType(widget.sendViewModel.wallet,
36 bitcoin!.getOptionToType(bitcoin!.getBitcoinLightningReceivePageOption()));
37 } else if (widget.sendViewModel.wallet.type == WalletType.litecoin) {
38 await bitcoin!.setAddressType(widget.sendViewModel.wallet,
39 bitcoin!.getOptionToType(bitcoin!.getLitecoinMwebReceivePageOption()));
40 }
41 final newUri = await widget.sendViewModel.wallet.walletAddresses
42 .getPaymentRequestUri(widget.sendViewModel.outputs.first.cryptoAmount);
43 setState(() {
44 uri = newUri;
45 });
46 }.call();
47 }
48
49 @override
50 Widget build(BuildContext context) {
51 final output = widget.sendViewModel.outputs.first;
52 final resolvedSize = MediaQuery.of(context).size.width * (largeQrMode ? 0.8 : 0.54);
53
54 return Container(
55 decoration: BoxDecoration(
56 color: Theme.of(context).colorScheme.surface,
57 borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
58 ),
59 child: Column(
60 mainAxisSize: MainAxisSize.min,
61 children: [
62 ModalTopBar(
63 title: "",
64 leadingWidget: Row(
65 spacing: 12,
66 children: [
67 if (widget.sendViewModel.walletType == WalletType.bitcoin)
68 CakeImageWidget(imageUrl: "assets/new-ui/lightning_deposit_help.svg", height: 36),
69 Text(
70 S.of(context).bitcoin_lightning_deposit,
71 style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
72 )
73 ],
74 ),
75 trailingIcon: Icon(Icons.close),
76 trailingSemanticLabel: S.of(context).close,
77 onTrailingPressed: Navigator.of(context).pop,
78 ),
79 SafeArea(
80 child: Padding(
81 padding: const EdgeInsets.symmetric(horizontal: 18.0),
82 child: Column(
83 mainAxisSize: MainAxisSize.min,
84 children: [
85 Column(
86 spacing: 24,
87 children: [
88 Row(
89 mainAxisAlignment: MainAxisAlignment.center,
90 spacing: 12,
91 children: [
92 Text(
93 S.of(context).send_exactly,
94 style: TextStyle(
95 fontSize: 16,
96 color: Theme.of(context).colorScheme.onSurface,
97 fontWeight: FontWeight.w500),
98 ),
99 Container(
100 decoration: BoxDecoration(
101 color: Theme.of(context).colorScheme.surfaceContainer,
102 borderRadius: BorderRadius.circular(12)),
103 child: Padding(
104 padding: const EdgeInsets.all(8.0),
105 child: Row(
106 spacing: 8,
107 children: [
108 Text(
109 output.cryptoAmount,
110 style: TextStyle(
111 fontWeight: FontWeight.w500,
112 fontSize: 16,
113 color: Theme.of(context).colorScheme.primary),
114 ),
115 Text(
116 widget.sendViewModel.currency.title,
117 style: TextStyle(
118 fontWeight: FontWeight.w400,
119 fontSize: 16,
120 color: Theme.of(context).colorScheme.primary),
121 ),
122 ],
123 ),
124 )),
125 Text("${S.of(context).to}:",
126 style: TextStyle(
127 fontSize: 16,
128 color: Theme.of(context).colorScheme.onSurface,
129 fontWeight: FontWeight.w500))
130 ],
131 ),
132 uri == null
133 ? Container(
134 width: resolvedSize,
135 height: resolvedSize,
136 child: CupertinoActivityIndicator(),
137 )
138 : GestureDetector(
139 onTap: () {
140 setState(() {
141 largeQrMode = !largeQrMode;
142 });
143 },
144 child: AnimatedContainer(
145 duration: const Duration(milliseconds: 400),
146 curve: Curves.easeOutCubic,
147 width: resolvedSize,
148 height: resolvedSize,
149 child: ClipRRect(
150 borderRadius: BorderRadius.circular(16),
151 child: QrImage(
152 embeddedImagePath: widget.sendViewModel.currency.iconPath,
153 data: uri.toString(),
154 ),
155 ),
156 ),
157 ),
158 AddressFormatter.buildSegmentedAddress(
159 address: output.address,
160 evenTextStyle: TextStyle(
161 color: Theme.of(context).colorScheme.onSurface,
162 fontFamily: "IBM Plex Mono"),
163 textAlign: TextAlign.center),
164 Container(
165 decoration: BoxDecoration(
166 color: warningBackgroundColor,
167 borderRadius: BorderRadius.circular(16),
168 ),
169 child: Padding(
170 padding: EdgeInsets.all(20),
171 child: Text(
172 S.of(context).lightning_external_disclaimer,
173 textAlign: TextAlign.center,
174 style: TextStyle(
175 color: warningTextColor,
176 fontSize: 14,
177 fontWeight: FontWeight.w500),
178 ),
179 )),
180 Row(
181 spacing: 8,
182 children: [
183 Flexible(
184 child: NewPrimaryButton(
185 onPressed: () =>
186 ClipboardUtil.copyToClipboard(context, output.address),
187 text: S.of(context).copy,
188 color: Theme.of(context).colorScheme.primary,
189 textColor: Theme.of(context).colorScheme.onPrimary),
190 ),
191 Flexible(
192 child: NewPrimaryButton(
193 onPressed: Navigator.of(context).pop,
194 text: S.of(context).sent_the_funds,
195 color: Theme.of(context).colorScheme.surfaceContainer,
196 textColor: Theme.of(context).colorScheme.primary),
197 ),
198 ],
199 ),
200 SizedBox()
201 ],
202 ),
203 ],
204 ),
205 ),
206 ),
207 ],
208 ),
209 );
210 }
211 }