All checks were successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
102 lines
3.2 KiB
Dart
102 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pshared/models/payment/methods/crypto_address.dart';
|
|
|
|
import 'package:pweb/utils/text_field_styles.dart';
|
|
|
|
|
|
class CryptoAddressForm extends StatefulWidget {
|
|
final void Function(CryptoAddressPaymentMethod) onChanged;
|
|
final CryptoAddressPaymentMethod? initialData;
|
|
final bool isEditable;
|
|
|
|
const CryptoAddressForm({
|
|
super.key,
|
|
required this.onChanged,
|
|
this.initialData,
|
|
required this.isEditable,
|
|
});
|
|
|
|
@override
|
|
State<CryptoAddressForm> createState() => _CryptoAddressFormState();
|
|
}
|
|
|
|
class _CryptoAddressFormState extends State<CryptoAddressForm> {
|
|
late TextEditingController _addressCtrl;
|
|
late TextEditingController _networkCtrl;
|
|
late TextEditingController _destinationTagCtrl;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_addressCtrl = TextEditingController(text: widget.initialData?.address);
|
|
_networkCtrl = TextEditingController(text: widget.initialData?.network);
|
|
_destinationTagCtrl = TextEditingController(text: widget.initialData?.destinationTag);
|
|
}
|
|
|
|
void _emit() {
|
|
if (_addressCtrl.text.isNotEmpty && _networkCtrl.text.isNotEmpty) {
|
|
widget.onChanged(
|
|
CryptoAddressPaymentMethod(
|
|
address: _addressCtrl.text,
|
|
network: _networkCtrl.text,
|
|
destinationTag: _destinationTagCtrl.text.isNotEmpty ? _destinationTagCtrl.text : null,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant CryptoAddressForm oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
final newData = widget.initialData;
|
|
final oldData = oldWidget.initialData;
|
|
|
|
if (newData == null && oldData != null) {
|
|
_addressCtrl.clear();
|
|
_networkCtrl.clear();
|
|
_destinationTagCtrl.clear();
|
|
return;
|
|
}
|
|
|
|
if (newData != null && newData != oldData) {
|
|
_addressCtrl.text = newData.address;
|
|
_networkCtrl.text = newData.network;
|
|
_destinationTagCtrl.text = newData.destinationTag ?? '';
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
TextFormField(
|
|
readOnly: !widget.isEditable,
|
|
controller: _addressCtrl,
|
|
decoration: getInputDecoration(context, 'Crypto address', widget.isEditable),
|
|
style: getTextFieldStyle(context, widget.isEditable),
|
|
onChanged: (_) => _emit(),
|
|
validator: (val) => (val?.isEmpty ?? true) ? 'Enter crypto address' : null,
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextFormField(
|
|
readOnly: !widget.isEditable,
|
|
controller: _networkCtrl,
|
|
decoration: getInputDecoration(context, 'Network', widget.isEditable),
|
|
style: getTextFieldStyle(context, widget.isEditable),
|
|
onChanged: (_) => _emit(),
|
|
validator: (val) => (val?.isEmpty ?? true) ? 'Enter network' : null,
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextFormField(
|
|
readOnly: !widget.isEditable,
|
|
controller: _destinationTagCtrl,
|
|
decoration: getInputDecoration(context, 'Destination tag / memo (optional)', widget.isEditable),
|
|
style: getTextFieldStyle(context, widget.isEditable),
|
|
onChanged: (_) => _emit(),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|