mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-03 12:24:19 +01:00
Cw 268 contact address validation (#905)
* feat: Proper Bitcoin address validation in exchange screen * fix: use custom validation in addition to RegEx to make sure all address cases are validated - for cases like P2SH addresses starting with a 3, which are not validated by bitcoin_flutter functions * feat: add bitcoin_flutter to root project * refactor: improve conditional isValid return chain * feat: enhance contact page address validation - only shows address box when a currency is selected, to prevent the selected value from being null - changes TextValidator() for the new AddressValidator() * fix: use -1 for initial selectedAtIndex, since there is no currency yet selected
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
import 'package:cake_wallet/core/validator.dart';
|
import 'package:cake_wallet/core/address_validator.dart';
|
||||||
import 'package:cake_wallet/palette.dart';
|
import 'package:cake_wallet/palette.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:cw_core/currency.dart';
|
import 'package:cw_core/currency.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.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';
|
import 'package:cake_wallet/core/contact_name_validator.dart';
|
||||||
import 'package:cake_wallet/core/execution_state.dart';
|
import 'package:cake_wallet/core/execution_state.dart';
|
||||||
import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart';
|
import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart';
|
||||||
@@ -33,8 +31,8 @@ class ContactPage extends BasePage {
|
|||||||
_addressController
|
_addressController
|
||||||
.addListener(() => contactViewModel.address = _addressController.text);
|
.addListener(() => contactViewModel.address = _addressController.text);
|
||||||
|
|
||||||
autorun((_) =>
|
autorun((_) => _currencyTypeController.text =
|
||||||
_currencyTypeController.text = contactViewModel.currency?.toString()??'');
|
contactViewModel.currency?.toString() ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -61,96 +59,105 @@ class ContactPage extends BasePage {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return ScrollableWithBottomSection(
|
return Observer(
|
||||||
contentPadding: EdgeInsets.all(24),
|
builder: (_) => ScrollableWithBottomSection(
|
||||||
content: Form(
|
contentPadding: EdgeInsets.all(24),
|
||||||
key: _formKey,
|
content: Form(
|
||||||
child: Column(
|
key: _formKey,
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
children: <Widget>[
|
mainAxisSize: MainAxisSize.min,
|
||||||
BaseTextFormField(
|
children: <Widget>[
|
||||||
controller: _nameController,
|
BaseTextFormField(
|
||||||
hintText: S.of(context).contact_name,
|
controller: _nameController,
|
||||||
validator: ContactNameValidator()),
|
hintText: S.of(context).contact_name,
|
||||||
Padding(
|
validator: ContactNameValidator()),
|
||||||
padding: EdgeInsets.only(top: 20),
|
Padding(
|
||||||
child: Container(
|
padding: EdgeInsets.only(top: 20),
|
||||||
child: InkWell(
|
child: Container(
|
||||||
onTap: () => _presentCurrencyPicker(context),
|
child: InkWell(
|
||||||
child: IgnorePointer(
|
onTap: () => _presentCurrencyPicker(context),
|
||||||
child: BaseTextFormField(
|
child: IgnorePointer(
|
||||||
controller: _currencyTypeController,
|
child: BaseTextFormField(
|
||||||
hintText: S.of(context).settings_currency,
|
controller: _currencyTypeController,
|
||||||
suffixIcon: Row(
|
hintText: S.of(context).settings_currency,
|
||||||
mainAxisSize: MainAxisSize.min,
|
suffixIcon: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[downArrow],
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
),
|
children: <Widget>[downArrow],
|
||||||
)),
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
if (contactViewModel.currency != null)
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 20),
|
padding: EdgeInsets.only(top: 20),
|
||||||
child: Observer(
|
child: AddressTextField(
|
||||||
builder: (_) => AddressTextField(
|
|
||||||
controller: _addressController,
|
controller: _addressController,
|
||||||
options: [
|
options: [
|
||||||
AddressTextFieldOption.paste,
|
AddressTextFieldOption.paste,
|
||||||
AddressTextFieldOption.qrCode,
|
AddressTextFieldOption.qrCode,
|
||||||
],
|
],
|
||||||
buttonColor: Theme.of(context).accentTextTheme!.headline3!.color!,
|
buttonColor:
|
||||||
|
Theme.of(context).accentTextTheme!.headline3!.color!,
|
||||||
iconColor: PaletteDark.gray,
|
iconColor: PaletteDark.gray,
|
||||||
borderColor: Theme.of(context).primaryTextTheme!.headline6!.backgroundColor!,
|
borderColor: Theme.of(context)
|
||||||
validator: TextValidator()
|
.primaryTextTheme!
|
||||||
// AddressValidator(
|
.headline6!
|
||||||
// type: contactViewModel.currency),
|
.backgroundColor!,
|
||||||
)),
|
validator:
|
||||||
)
|
AddressValidator(type: contactViewModel.currency!),
|
||||||
],
|
),
|
||||||
),
|
)
|
||||||
),
|
],
|
||||||
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,
|
|
||||||
color: Colors.orange,
|
|
||||||
textColor: Colors.white),
|
|
||||||
),
|
),
|
||||||
SizedBox(width: 20),
|
),
|
||||||
Expanded(
|
bottomSectionPadding:
|
||||||
child: Observer(
|
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||||
builder: (_) => PrimaryButton(
|
bottomSection: Row(
|
||||||
onPressed: () async {
|
children: <Widget>[
|
||||||
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
|
Expanded(
|
||||||
return;
|
child: PrimaryButton(
|
||||||
}
|
onPressed: () {
|
||||||
|
contactViewModel.reset();
|
||||||
|
_nameController.text = '';
|
||||||
|
_addressController.text = '';
|
||||||
|
},
|
||||||
|
text: S.of(context).reset,
|
||||||
|
color: Colors.orange,
|
||||||
|
textColor: Colors.white),
|
||||||
|
),
|
||||||
|
SizedBox(width: 20),
|
||||||
|
Expanded(
|
||||||
|
child: Observer(
|
||||||
|
builder: (_) => PrimaryButton(
|
||||||
|
onPressed: () async {
|
||||||
|
if (_formKey.currentState != null &&
|
||||||
|
!_formKey.currentState!.validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await contactViewModel.save();
|
await contactViewModel.save();
|
||||||
},
|
},
|
||||||
text: S.of(context).save,
|
text: S.of(context).save,
|
||||||
color: Theme.of(context).accentTextTheme!.bodyText1!.color!,
|
color: Theme.of(context)
|
||||||
textColor: Colors.white,
|
.accentTextTheme!
|
||||||
isDisabled: !contactViewModel.isReady)))
|
.bodyText1!
|
||||||
],
|
.color!,
|
||||||
));
|
textColor: Colors.white,
|
||||||
|
isDisabled: !contactViewModel.isReady)))
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _presentCurrencyPicker(BuildContext context) {
|
void _presentCurrencyPicker(BuildContext context) {
|
||||||
showPopUp<void>(
|
showPopUp<void>(
|
||||||
builder: (_) => CurrencyPicker(
|
builder: (_) => CurrencyPicker(
|
||||||
selectedAtIndex:
|
selectedAtIndex: contactViewModel.currency != null
|
||||||
contactViewModel.currency != null
|
? contactViewModel.currencies
|
||||||
? contactViewModel.currencies.indexOf(contactViewModel.currency!)
|
.indexOf(contactViewModel.currency!)
|
||||||
: 0,
|
: -1,
|
||||||
items: contactViewModel.currencies,
|
items: contactViewModel.currencies,
|
||||||
title: S.of(context).please_select,
|
title: S.of(context).please_select,
|
||||||
hintText: S.of(context).search_currency,
|
hintText: S.of(context).search_currency,
|
||||||
|
|||||||
Reference in New Issue
Block a user