| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/address_text_field.dart'; |
| 3 | import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; |
| 4 | import 'package:cake_wallet/utils/show_bar.dart'; |
| 5 | import 'package:cw_core/currency_for_wallet_type.dart'; |
| 6 | import 'package:cw_core/wallet_type.dart'; |
| 7 | import 'package:flutter/material.dart'; |
| 8 | import 'package:flutter/services.dart'; |
| 9 | |
| 10 | class SignForm extends StatefulWidget { |
| 11 | SignForm({ |
| 12 | Key? key, |
| 13 | required this.type, |
| 14 | required this.chainId, |
| 15 | required this.includeAddress, |
| 16 | }) : super(key: key); |
| 17 | |
| 18 | final WalletType type; |
| 19 | final bool includeAddress; |
| 20 | final int? chainId; |
| 21 | |
| 22 | @override |
| 23 | SignFormState createState() => SignFormState(); |
| 24 | } |
| 25 | |
| 26 | class SignFormState extends State<SignForm> with AutomaticKeepAliveClientMixin { |
| 27 | SignFormState() |
| 28 | : messageController = TextEditingController(), |
| 29 | addressController = TextEditingController(), |
| 30 | signatureController = TextEditingController(); |
| 31 | |
| 32 | final TextEditingController messageController; |
| 33 | final TextEditingController addressController; |
| 34 | final TextEditingController signatureController; |
| 35 | |
| 36 | @override |
| 37 | void initState() { |
| 38 | super.initState(); |
| 39 | } |
| 40 | |
| 41 | @override |
| 42 | void dispose() { |
| 43 | super.dispose(); |
| 44 | } |
| 45 | |
| 46 | @override |
| 47 | bool get wantKeepAlive => true; |
| 48 | |
| 49 | @override |
| 50 | Widget build(BuildContext context) { |
| 51 | super.build(context); |
| 52 | return Container( |
| 53 | padding: EdgeInsets.only(left: 24, right: 24), |
| 54 | child: Column( |
| 55 | children: [ |
| 56 | Column( |
| 57 | children: [ |
| 58 | AddressTextField( |
| 59 | controller: messageController, |
| 60 | placeholder: S.current.message, |
| 61 | options: [AddressTextFieldOption.paste], |
| 62 | buttonColor: Theme.of(context).colorScheme.surfaceContainerHighest, |
| 63 | fillColor: Theme.of(context).colorScheme.surface, |
| 64 | ), |
| 65 | if (widget.includeAddress) ...[ |
| 66 | const SizedBox(height: 20), |
| 67 | AddressTextField( |
| 68 | controller: addressController, |
| 69 | options: [AddressTextFieldOption.paste, AddressTextFieldOption.walletAddresses], |
| 70 | buttonColor: Theme.of(context).colorScheme.surfaceContainerHighest, |
| 71 | onSelectedContact: (contact) { |
| 72 | addressController.text = contact.address; |
| 73 | }, |
| 74 | selectedCurrency: |
| 75 | walletTypeToCryptoCurrency(widget.type, chainId: widget.chainId), |
| 76 | fillColor: Theme.of(context).colorScheme.surface, |
| 77 | ), |
| 78 | ], |
| 79 | ], |
| 80 | ), |
| 81 | const SizedBox(height: 20), |
| 82 | GestureDetector( |
| 83 | onTap: () async { |
| 84 | final text = signatureController.text; |
| 85 | if (text.isEmpty) { |
| 86 | return; |
| 87 | } |
| 88 | Clipboard.setData(ClipboardData(text: text)); |
| 89 | showBar<void>(context, S.of(context).transaction_details_copied(text)); |
| 90 | }, |
| 91 | child: BaseTextFormField( |
| 92 | enabled: false, |
| 93 | controller: signatureController, |
| 94 | hintText: S.current.signature, |
| 95 | ), |
| 96 | ), |
| 97 | ], |
| 98 | ), |
| 99 | ); |
| 100 | } |
| 101 | } |