2021-10-01 15:13:10 +00:00
|
|
|
import 'package:cake_wallet/core/validator.dart';
|
2020-08-31 16:44:48 +00:00
|
|
|
import 'package:cake_wallet/palette.dart';
|
2020-09-25 15:32:44 +00:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/core/address_validator.dart';
|
|
|
|
import 'package:cake_wallet/core/contact_name_validator.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/core/execution_state.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/address_text_field.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/exchange/widgets/currency_picker.dart';
|
|
|
|
|
|
|
|
class ContactPage extends BasePage {
|
|
|
|
ContactPage(this.contactViewModel)
|
|
|
|
: _formKey = GlobalKey<FormState>(),
|
|
|
|
_nameController = TextEditingController(),
|
|
|
|
_addressController = TextEditingController(),
|
|
|
|
_currencyTypeController = TextEditingController() {
|
|
|
|
_nameController.text = contactViewModel.name;
|
|
|
|
_addressController.text = contactViewModel.address;
|
|
|
|
_nameController
|
|
|
|
.addListener(() => contactViewModel.name = _nameController.text);
|
|
|
|
_addressController
|
|
|
|
.addListener(() => contactViewModel.address = _addressController.text);
|
|
|
|
|
|
|
|
autorun((_) =>
|
2020-08-31 16:44:48 +00:00
|
|
|
_currencyTypeController.text = contactViewModel.currency?.toString()??'');
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get title => S.current.contact;
|
|
|
|
|
|
|
|
final ContactViewModel contactViewModel;
|
|
|
|
final GlobalKey<FormState> _formKey;
|
|
|
|
final TextEditingController _nameController;
|
|
|
|
final TextEditingController _currencyTypeController;
|
|
|
|
final TextEditingController _addressController;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
|
|
|
final downArrow = Image.asset('assets/images/arrow_bottom_purple_icon.png',
|
2022-10-12 17:09:57 +00:00
|
|
|
color: Theme.of(context).primaryTextTheme!.overline!.color!, height: 8);
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
reaction((_) => contactViewModel.state, (ExecutionState state) {
|
|
|
|
if (state is FailureState) {
|
2020-07-06 20:09:03 +00:00
|
|
|
_onContactSavingFailure(context, state.error);
|
|
|
|
}
|
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
if (state is ExecutedSuccessfullyState) {
|
2020-07-06 20:09:03 +00:00
|
|
|
_onContactSavedSuccessfully(context);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-31 16:44:48 +00:00
|
|
|
return ScrollableWithBottomSection(
|
|
|
|
contentPadding: EdgeInsets.all(24),
|
|
|
|
content: Form(
|
|
|
|
key: _formKey,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
BaseTextFormField(
|
|
|
|
controller: _nameController,
|
|
|
|
hintText: S.of(context).contact_name,
|
|
|
|
validator: ContactNameValidator()),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 20),
|
|
|
|
child: Container(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => _presentCurrencyPicker(context),
|
|
|
|
child: IgnorePointer(
|
|
|
|
child: BaseTextFormField(
|
|
|
|
controller: _currencyTypeController,
|
|
|
|
hintText: S.of(context).settings_currency,
|
|
|
|
suffixIcon: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: <Widget>[downArrow],
|
|
|
|
),
|
|
|
|
)),
|
2020-07-06 20:09:03 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-08-31 16:44:48 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 20),
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) => AddressTextField(
|
|
|
|
controller: _addressController,
|
2022-06-18 22:51:43 +00:00
|
|
|
options: [
|
|
|
|
AddressTextFieldOption.paste,
|
|
|
|
AddressTextFieldOption.qrCode,
|
|
|
|
],
|
2022-10-12 17:09:57 +00:00
|
|
|
buttonColor: Theme.of(context).accentTextTheme!.headline3!.color!,
|
2020-08-31 16:44:48 +00:00
|
|
|
iconColor: PaletteDark.gray,
|
2022-10-12 17:09:57 +00:00
|
|
|
borderColor: Theme.of(context).primaryTextTheme!.headline6!.backgroundColor!,
|
2021-10-01 15:13:10 +00:00
|
|
|
validator: TextValidator()
|
|
|
|
// AddressValidator(
|
|
|
|
// type: contactViewModel.currency),
|
2020-08-31 16:44:48 +00:00
|
|
|
)),
|
|
|
|
)
|
2020-07-06 20:09:03 +00:00
|
|
|
],
|
2020-08-31 16:44:48 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
bottomSectionPadding:
|
|
|
|
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
|
|
|
bottomSection: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: PrimaryButton(
|
|
|
|
onPressed: () {
|
|
|
|
contactViewModel.reset();
|
|
|
|
_nameController.text = '';
|
|
|
|
_addressController.text = '';
|
|
|
|
},
|
|
|
|
text: S.of(context).reset,
|
CAKE-39 | changed buttons color on base send widget, base exchange widget, exchange confirm page, exchange trade page, node create or edit page, contact page, seed widget, restore wallet from seed details page, restore wallet from keys page, wallet seed page, template tile
2020-09-10 10:33:34 +00:00
|
|
|
color: Colors.orange,
|
2020-08-31 16:44:48 +00:00
|
|
|
textColor: Colors.white),
|
|
|
|
),
|
|
|
|
SizedBox(width: 20),
|
|
|
|
Expanded(
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) => PrimaryButton(
|
|
|
|
onPressed: () async {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
|
2020-08-31 16:44:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await contactViewModel.save();
|
|
|
|
},
|
|
|
|
text: S.of(context).save,
|
2022-10-12 17:09:57 +00:00
|
|
|
color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
|
2020-08-31 16:44:48 +00:00
|
|
|
textColor: Colors.white,
|
|
|
|
isDisabled: !contactViewModel.isReady)))
|
|
|
|
],
|
|
|
|
));
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _presentCurrencyPicker(BuildContext context) {
|
2020-09-25 15:32:44 +00:00
|
|
|
showPopUp<void>(
|
2020-07-06 20:09:03 +00:00
|
|
|
builder: (_) => CurrencyPicker(
|
|
|
|
selectedAtIndex:
|
2022-10-12 17:09:57 +00:00
|
|
|
contactViewModel.currency != null
|
|
|
|
? contactViewModel.currencies.indexOf(contactViewModel.currency!)
|
|
|
|
: 0,
|
2020-07-06 20:09:03 +00:00
|
|
|
items: contactViewModel.currencies,
|
|
|
|
title: S.of(context).please_select,
|
2022-07-01 10:17:09 +00:00
|
|
|
hintText: S.of(context).search_currency,
|
2020-07-06 20:09:03 +00:00
|
|
|
onItemSelected: (CryptoCurrency item) =>
|
|
|
|
contactViewModel.currency = item),
|
|
|
|
context: context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onContactSavingFailure(BuildContext context, String error) {
|
2020-09-25 15:32:44 +00:00
|
|
|
showPopUp<void>(
|
2020-07-06 20:09:03 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.current.contact,
|
|
|
|
alertContent: error,
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onContactSavedSuccessfully(BuildContext context) =>
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|