Merge pull request #58 from cake-tech/CWA-210-rework-send-screen

Cwa 210 rework send screen
This commit is contained in:
Oleksandr Sobol
2020-05-12 16:20:33 +03:00
committed by GitHub
37 changed files with 1348 additions and 329 deletions
+22
View File
@@ -0,0 +1,22 @@
import 'package:hive/hive.dart';
part 'template.g.dart';
@HiveType()
class Template extends HiveObject {
Template({this.name, this.address, this.cryptoCurrency, this.amount});
static const boxName = 'Template';
@HiveField(0)
String name;
@HiveField(1)
String address;
@HiveField(2)
String cryptoCurrency;
@HiveField(3)
String amount;
}
+328 -309
View File
@@ -17,22 +17,55 @@ import 'package:cake_wallet/src/stores/send/send_store.dart';
import 'package:cake_wallet/src/stores/send/sending_state.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/balance_display_mode.dart';
import 'package:cake_wallet/src/domain/common/calculate_estimated_fee.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/domain/common/sync_status.dart';
import 'package:cake_wallet/src/stores/sync/sync_store.dart';
import 'package:cake_wallet/src/widgets/top_panel.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart';
import 'package:cake_wallet/src/screens/send/widgets/sending_alert.dart';
import 'package:cake_wallet/src/screens/send/widgets/template_tile.dart';
import 'package:cake_wallet/src/stores/send_template/send_template_store.dart';
class SendPage extends BasePage {
@override
String get title => S.current.send_title;
@override
bool get isModalBackButton => true;
Color get backgroundColor => PaletteDark.menuList;
@override
bool get resizeToAvoidBottomPadding => false;
@override
Widget trailing(context) {
final sendStore = Provider.of<SendStore>(context);
return Container(
height: 32,
width: 82,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
color: PaletteDark.menuHeader
),
child: ButtonTheme(
minWidth: double.minPositive,
child: FlatButton(
onPressed: () => sendStore.clear(),
child: Text(
S.of(context).clear,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10.0,
color: Colors.blue),
)),
),
);
}
@override
Widget body(BuildContext context) => SendForm();
}
@@ -44,7 +77,6 @@ class SendForm extends StatefulWidget {
class SendFormState extends State<SendForm> {
final _addressController = TextEditingController();
final _paymentIdController = TextEditingController();
final _cryptoAmountController = TextEditingController();
final _fiatAmountController = TextEditingController();
@@ -75,14 +107,11 @@ class SendFormState extends State<SendForm> {
await showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(S.of(context).openalias_alert_title),
content: Text(S.of(context).openalias_alert_content(sendStore.recordName)),
actions: <Widget>[
FlatButton(
child: Text(S.of(context).ok),
onPressed: () => Navigator.of(context).pop())
],
return AlertWithOneAction(
alertTitle: S.of(context).openalias_alert_title,
alertContent: S.of(context).openalias_alert_content(sendStore.recordName),
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop()
);
});
}
@@ -96,92 +125,20 @@ class SendFormState extends State<SendForm> {
final balanceStore = Provider.of<BalanceStore>(context);
final walletStore = Provider.of<WalletStore>(context);
final syncStore = Provider.of<SyncStore>(context);
final sendTemplateStore = Provider.of<SendTemplateStore>(context);
_setEffects(context);
return ScrollableWithBottomSection(
contentPadding: EdgeInsets.all(0),
return Container(
color: PaletteDark.historyPanel,
child: ScrollableWithBottomSection(
contentPadding: EdgeInsets.only(bottom: 24),
content: Column(
children: [
Container(
padding: EdgeInsets.only(left: 38, right: 30),
decoration: BoxDecoration(
color: Theme.of(context).backgroundColor,
boxShadow: [
BoxShadow(
color: Palette.shadowGrey,
blurRadius: 10,
offset: Offset(0, 12),
)
],
border: Border(
top: BorderSide(
width: 1,
color: Theme.of(context)
.accentTextTheme
.subtitle
.backgroundColor))),
child: SizedBox(
height: 56,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Observer(builder: (_) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(S.of(context).send_your_wallet,
style: TextStyle(
fontSize: 12, color: Palette.lightViolet)),
Text(walletStore.name,
style: TextStyle(
fontSize: 18,
color: Theme.of(context)
.accentTextTheme
.overline
.color,
height: 1.25)),
]);
}),
Observer(builder: (context) {
final savedDisplayMode = settingsStore.balanceDisplayMode;
final availableBalance =
savedDisplayMode == BalanceDisplayMode.hiddenBalance
? '---'
: balanceStore.unlockedBalance;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(S.of(context).xmr_available_balance,
style: TextStyle(
fontSize: 12,
color: Theme.of(context)
.accentTextTheme
.overline
.backgroundColor,
)),
Text(availableBalance,
style: TextStyle(
fontSize: 22,
color: Theme.of(context)
.accentTextTheme
.overline
.color,
height: 1.1)),
]);
})
],
),
),
),
Form(
key: _formKey,
child: Container(
padding:
EdgeInsets.only(left: 38, right: 33, top: 10, bottom: 30),
children: <Widget>[
TopPanel(
color: PaletteDark.menuList,
widget: Form(
key: _formKey,
child: Column(children: <Widget>[
AddressTextField(
controller: _addressController,
@@ -190,19 +147,16 @@ class SendFormState extends State<SendForm> {
onURIScanned: (uri) {
var address = '';
var amount = '';
var paymentId = '';
if (uri != null) {
address = uri.path;
amount = uri.queryParameters['tx_amount'];
paymentId = uri.queryParameters['tx_payment_id'];
} else {
address = uri.toString();
}
_addressController.text = address;
_cryptoAmountController.text = amount;
_paymentIdController.text = paymentId;
},
options: [
AddressTextFieldOption.qrCode,
@@ -214,102 +168,104 @@ class SendFormState extends State<SendForm> {
return sendStore.errorMessage;
},
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
style: TextStyle(
fontSize: 14.0,
color: Theme.of(context)
.accentTextTheme
.overline
.backgroundColor),
controller: _paymentIdController,
decoration: InputDecoration(
hintStyle: TextStyle(
fontSize: 14.0,
color: Theme.of(context).hintColor),
hintText: S.of(context).send_payment_id,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Palette.cakeGreen, width: 2.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).focusColor,
width: 1.0))),
validator: (value) {
sendStore.validatePaymentID(value);
return sendStore.errorMessage;
}),
Observer(
builder: (_) {
return Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
style: TextStyle(
fontSize: 16.0,
color: Colors.white
),
controller: _cryptoAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
BlacklistingTextInputFormatter(
RegExp('[\\-|\\ |\\,]'))
],
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(top: 12),
child: Text('XMR:',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)),
),
suffixIcon: Padding(
padding: EdgeInsets.only(
bottom: 5
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width/2,
alignment: Alignment.centerLeft,
child: Text(
' / ' + balanceStore.unlockedBalance,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16,
color: PaletteDark.walletCardText
)
),
),
Container(
height: 32,
width: 32,
margin: EdgeInsets.only(left: 12, bottom: 7, top: 4),
decoration: BoxDecoration(
color: PaletteDark.walletCardSubAddressField,
borderRadius: BorderRadius.all(Radius.circular(6))
),
child: InkWell(
onTap: () => sendStore.setSendAll(),
child: Center(
child: Text(S.of(context).all,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 9,
fontWeight: FontWeight.bold,
color: PaletteDark.walletCardText
)
),
),
),
)
],
),
),
hintStyle: TextStyle(
fontSize: 16.0,
color: Colors.white),
hintText: '0.0000',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0))),
validator: (value) {
sendStore.validateXMR(
value, balanceStore.unlockedBalance);
return sendStore.errorMessage;
}),
);
}
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
style: TextStyle(
fontSize: 18.0,
color: Theme.of(context)
.accentTextTheme
.overline
.color),
controller: _cryptoAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
BlacklistingTextInputFormatter(
RegExp('[\\-|\\ |\\,]'))
],
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(top: 12),
child: Text('XMR:',
style: TextStyle(
fontSize: 18,
color: Theme.of(context)
.accentTextTheme
.overline
.color,
)),
),
suffixIcon: Container(
width: 1,
padding: EdgeInsets.only(top: 0),
child: Center(
child: InkWell(
onTap: () => sendStore.setSendAll(),
child: Text(S.of(context).all,
style: TextStyle(
fontSize: 10,
color: Theme.of(context)
.accentTextTheme
.overline
.decorationColor))),
),
),
hintStyle: TextStyle(
fontSize: 18.0,
color: Theme.of(context).hintColor),
hintText: '0.0000',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Palette.cakeGreen, width: 2.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).focusColor,
width: 1.0))),
validator: (value) {
sendStore.validateXMR(
value, balanceStore.unlockedBalance);
return sendStore.errorMessage;
}),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
style: TextStyle(
fontSize: 18.0,
color: Theme.of(context)
.accentTextTheme
.overline
.color),
fontSize: 16.0,
color: Colors.white),
controller: _fiatAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
@@ -323,123 +279,188 @@ class SendFormState extends State<SendForm> {
child: Text(
'${settingsStore.fiatCurrency.toString()}:',
style: TextStyle(
fontSize: 18,
color: Theme.of(context)
.accentTextTheme
.overline
.color,
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)),
),
hintStyle: TextStyle(
fontSize: 18.0,
color: Theme.of(context).hintColor),
fontSize: 16.0,
color: PaletteDark.walletCardText),
hintText: '0.00',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Palette.cakeGreen, width: 2.0)),
color: PaletteDark.walletCardSubAddressField,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).focusColor,
color: PaletteDark.walletCardSubAddressField,
width: 1.0)))),
),
Padding(
padding: const EdgeInsets.only(top: 12.0, bottom: 10),
padding: const EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(S.of(context).send_estimated_fee,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.accentTextTheme
.overline
.backgroundColor,
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.white,
)),
Text(
'${calculateEstimatedFee(priority: settingsStore.transactionPriority)} XMR',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.primaryTextTheme
.overline
.backgroundColor,
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.white,
))
],
),
),
SizedBox(
width: double.infinity,
child: Text(
S.of(context).send_priority(
settingsStore.transactionPriority.toString()),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.primaryTextTheme
.subtitle
.color,
height: 1.3)),
),
)
]),
),
),
Padding(
padding: EdgeInsets.only(
top: 32,
left: 24,
bottom: 24
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
S.of(context).send_templates,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: PaletteDark.walletCardText
),
)
],
),
),
Container(
height: 40,
width: double.infinity,
padding: EdgeInsets.only(left: 24),
child: Observer(
builder: (_) {
final itemCount = sendTemplateStore.templates.length + 1;
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: itemCount,
itemBuilder: (context, index) {
if (index == 0) {
return GestureDetector(
onTap: () => Navigator.of(context)
.pushNamed(Routes.sendTemplate, arguments: sendStore),
child: Container(
padding: EdgeInsets.only(right: 10),
child: DottedBorder(
borderType: BorderType.RRect,
dashPattern: [8, 4],
color: PaletteDark.menuList,
strokeWidth: 2,
radius: Radius.circular(20),
child: Container(
height: 40,
width: 75,
padding: EdgeInsets.only(left: 10, right: 10),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
color: Colors.transparent,
),
child: Text(
S.of(context).send_new,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: PaletteDark.walletCardText
),
),
)
),
),
);
}
index -= 1;
final template = sendTemplateStore.templates[index];
return TemplateTile(
name: template.name,
amount: template.amount,
cryptoCurrency: template.cryptoCurrency,
onTap: () {
_addressController.text = template.address;
_cryptoAmountController.text = template.amount;
getOpenaliasRecord(context);
}
);
}
);
}
),
)
],
),
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
bottomSection: Observer(builder: (_) {
return LoadingPrimaryButton(
onPressed: syncStore.status is SyncedSyncStatus
? () async {
// Hack. Don't ask me.
FocusScope.of(context).requestFocus(FocusNode());
// Hack. Don't ask me.
FocusScope.of(context).requestFocus(FocusNode());
if (_formKey.currentState.validate()) {
await showDialog<void>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: Text(
S.of(context).send_creating_transaction),
content: Text(S.of(context).confirm_sending),
actions: <Widget>[
FlatButton(
child: Text(S.of(context).send),
onPressed: () async {
await Navigator.of(dialogContext)
.popAndPushNamed(Routes.auth,
arguments: (bool
isAuthenticatedSuccessfully,
AuthPageState auth) {
if (!isAuthenticatedSuccessfully) {
return;
}
if (_formKey.currentState.validate()) {
await showDialog<void>(
context: context,
builder: (dialogContext) {
return AlertWithTwoActions(
alertTitle: S.of(context).send_creating_transaction,
alertContent: S.of(context).confirm_sending,
leftButtonText: S.of(context).send,
rightButtonText: S.of(context).cancel,
actionLeftButton: () async {
await Navigator.of(dialogContext)
.popAndPushNamed(Routes.auth,
arguments: (bool
isAuthenticatedSuccessfully,
AuthPageState auth) {
if (!isAuthenticatedSuccessfully) {
return;
}
Navigator.of(auth.context).pop();
Navigator.of(auth.context).pop();
sendStore.createTransaction(
address: _addressController.text,
paymentId:
_paymentIdController.text);
});
}),
FlatButton(
child: Text(S.of(context).cancel),
onPressed: () =>
Navigator.of(context).pop())
],
);
});
}
}
: null,
sendStore.createTransaction(
address: _addressController.text,
paymentId: '');
});
},
actionRightButton: () =>
Navigator.of(context).pop()
);
});
}
}
: null,
text: S.of(context).send,
color: Theme.of(context).accentTextTheme.button.backgroundColor,
textColor: Theme.of(context).primaryTextTheme.button.color,
color: Colors.blue,
textColor: Colors.white,
isLoading: sendStore.state is CreatingTransaction ||
sendStore.state is TransactionCommiting);
}));
sendStore.state is TransactionCommiting,
isDisabled: !(syncStore.status is SyncedSyncStatus),
);
}),
),
);
}
void _setEffects(BuildContext context) {
@@ -461,6 +482,20 @@ class SendFormState extends State<SendForm> {
}
});
reaction((_) => sendStore.address, (String address) {
if (address != _addressController.text) {
_addressController.text = address;
}
});
_addressController.addListener(() {
final address = _addressController.text;
if (sendStore.address != address) {
sendStore.changeAddress(address);
}
});
_fiatAmountController.addListener(() {
final fiatAmount = _fiatAmountController.text;
@@ -483,14 +518,11 @@ class SendFormState extends State<SendForm> {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(S.of(context).error),
content: Text(state.error),
actions: <Widget>[
FlatButton(
child: Text(S.of(context).ok),
onPressed: () => Navigator.of(context).pop())
],
return AlertWithOneAction(
alertTitle: S.of(context).error,
alertContent: state.error,
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop()
);
});
});
@@ -501,23 +533,25 @@ class SendFormState extends State<SendForm> {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(S.of(context).confirm_sending),
content: Text(S.of(context).commit_transaction_amount_fee(
sendStore.pendingTransaction.amount,
sendStore.pendingTransaction.fee)),
actions: <Widget>[
FlatButton(
child: Text(S.of(context).ok),
onPressed: () {
Navigator.of(context).pop();
sendStore.commitTransaction();
}),
FlatButton(
child: Text(S.of(context).cancel),
onPressed: () => Navigator.of(context).pop(),
)
],
return ConfirmSendingAlert(
alertTitle: S.of(context).confirm_sending,
amount: S.of(context).send_amount,
amountValue: sendStore.pendingTransaction.amount,
fee: S.of(context).send_fee,
feeValue: sendStore.pendingTransaction.fee,
leftButtonText: S.of(context).ok,
rightButtonText: S.of(context).cancel,
actionLeftButton: () {
Navigator.of(context).pop();
sendStore.commitTransaction();
showDialog<void>(
context: context,
builder: (BuildContext context) {
return SendingAlert(sendStore: sendStore);
}
);
},
actionRightButton: () => Navigator.of(context).pop()
);
});
});
@@ -525,23 +559,8 @@ class SendFormState extends State<SendForm> {
if (state is TransactionCommitted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(S.of(context).sending),
content: Text(S.of(context).transaction_sent),
actions: <Widget>[
FlatButton(
child: Text(S.of(context).ok),
onPressed: () {
_addressController.text = '';
_cryptoAmountController.text = '';
Navigator.of(context)..pop()..pop();
})
],
);
});
_addressController.text = '';
_cryptoAmountController.text = '';
});
}
});
@@ -0,0 +1,273 @@
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mobx/mobx.dart';
import 'package:provider/provider.dart';
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/src/widgets/address_text_field.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
import 'package:cake_wallet/src/stores/balance/balance_store.dart';
import 'package:cake_wallet/src/stores/send/send_store.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/top_panel.dart';
import 'package:cake_wallet/src/stores/send_template/send_template_store.dart';
class SendTemplatePage extends BasePage {
@override
String get title => S.current.send_title;
@override
Color get backgroundColor => PaletteDark.menuList;
@override
bool get resizeToAvoidBottomPadding => false;
@override
Widget body(BuildContext context) => SendTemplateForm();
}
class SendTemplateForm extends StatefulWidget {
@override
SendTemplateFormState createState() => SendTemplateFormState();
}
class SendTemplateFormState extends State<SendTemplateForm> {
final _nameController = TextEditingController();
final _addressController = TextEditingController();
final _cryptoAmountController = TextEditingController();
final _fiatAmountController = TextEditingController();
final _formKey = GlobalKey<FormState>();
bool _effectsInstalled = false;
@override
void dispose() {
_nameController.dispose();
_addressController.dispose();
_cryptoAmountController.dispose();
_fiatAmountController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final settingsStore = Provider.of<SettingsStore>(context);
final balanceStore = Provider.of<BalanceStore>(context);
final sendStore = Provider.of<SendStore>(context);
sendStore.settingsStore = settingsStore;
final sendTemplateStore = Provider.of<SendTemplateStore>(context);
_setEffects(context);
return Container(
color: PaletteDark.historyPanel,
child: ScrollableWithBottomSection(
contentPadding: EdgeInsets.only(bottom: 24),
content: Column(
children: <Widget>[
TopPanel(
color: PaletteDark.menuList,
widget: Form(
key: _formKey,
child: Column(children: <Widget>[
TextFormField(
style: TextStyle(
fontSize: 16.0,
color: Colors.white),
controller: _nameController,
decoration: InputDecoration(
hintStyle: TextStyle(
fontSize: 16.0,
color: PaletteDark.walletCardText),
hintText: S.of(context).send_name,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0))),
validator: (value) {
sendTemplateStore.validateTemplate(value);
return sendTemplateStore.errorMessage;
},
),
Padding(
padding: EdgeInsets.only(top: 20),
child: AddressTextField(
controller: _addressController,
placeholder: S.of(context).send_monero_address,
onURIScanned: (uri) {
var address = '';
var amount = '';
if (uri != null) {
address = uri.path;
amount = uri.queryParameters['tx_amount'];
} else {
address = uri.toString();
}
_addressController.text = address;
_cryptoAmountController.text = amount;
},
options: [
AddressTextFieldOption.qrCode,
AddressTextFieldOption.addressBook
],
validator: (value) {
sendTemplateStore.validateTemplate(value);
return sendTemplateStore.errorMessage;
},
),
),
Observer(
builder: (_) {
return Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
style: TextStyle(
fontSize: 16.0,
color: Colors.white
),
controller: _cryptoAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
BlacklistingTextInputFormatter(
RegExp('[\\-|\\ |\\,]'))
],
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(top: 12),
child: Text('XMR:',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)),
),
hintStyle: TextStyle(
fontSize: 16.0,
color: Colors.white),
hintText: '0.0000',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0))),
),
);
}
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
style: TextStyle(
fontSize: 16.0,
color: Colors.white),
controller: _fiatAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
BlacklistingTextInputFormatter(
RegExp('[\\-|\\ |\\,]'))
],
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(top: 12),
child: Text(
'${settingsStore.fiatCurrency.toString()}:',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)),
),
hintStyle: TextStyle(
fontSize: 16.0,
color: PaletteDark.walletCardText),
hintText: '0.00',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0)))),
),
]),
),
),
],
),
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
bottomSection: PrimaryButton(
onPressed: () {
if (_formKey.currentState.validate()) {
sendTemplateStore.addTemplate(
name: _nameController.text,
address: _addressController.text,
cryptoCurrency: 'XMR',
amount: _cryptoAmountController.text
);
sendTemplateStore.update();
Navigator.of(context).pop();
}
},
text: S.of(context).save,
color: Colors.blue,
textColor: Colors.white
),
),
);
}
void _setEffects(BuildContext context) {
if (_effectsInstalled) {
return;
}
final sendStore = Provider.of<SendStore>(context);
reaction((_) => sendStore.fiatAmount, (String amount) {
if (amount != _fiatAmountController.text) {
_fiatAmountController.text = amount;
}
});
reaction((_) => sendStore.cryptoAmount, (String amount) {
if (amount != _cryptoAmountController.text) {
_cryptoAmountController.text = amount;
}
});
_fiatAmountController.addListener(() {
final fiatAmount = _fiatAmountController.text;
if (sendStore.fiatAmount != fiatAmount) {
sendStore.changeFiatAmount(fiatAmount);
}
});
_cryptoAmountController.addListener(() {
final cryptoAmount = _cryptoAmountController.text;
if (sendStore.cryptoAmount != cryptoAmount) {
sendStore.changeCryptoAmount(cryptoAmount);
}
});
_effectsInstalled = true;
}
}
@@ -0,0 +1,100 @@
import 'package:flutter/material.dart';
import 'package:cake_wallet/src/widgets/base_alert_dialog.dart';
class ConfirmSendingAlert extends BaseAlertDialog {
ConfirmSendingAlert({
@required this.alertTitle,
@required this.amount,
@required this.amountValue,
@required this.fee,
@required this.feeValue,
@required this.leftButtonText,
@required this.rightButtonText,
@required this.actionLeftButton,
@required this.actionRightButton,
this.alertBarrierDismissible = true
});
final String alertTitle;
final String amount;
final String amountValue;
final String fee;
final String feeValue;
final String leftButtonText;
final String rightButtonText;
final VoidCallback actionLeftButton;
final VoidCallback actionRightButton;
final bool alertBarrierDismissible;
@override
String get titleText => alertTitle;
@override
String get leftActionButtonText => leftButtonText;
@override
String get rightActionButtonText => rightButtonText;
@override
VoidCallback get actionLeft => actionLeftButton;
@override
VoidCallback get actionRight => actionRightButton;
@override
bool get barrierDismissible => alertBarrierDismissible;
@override
Widget content(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
amount,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
decoration: TextDecoration.none,
),
),
Text(
amountValue,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
decoration: TextDecoration.none,
),
)
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
fee,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
decoration: TextDecoration.none,
),
),
Text(
feeValue,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
decoration: TextDecoration.none,
),
)
],
)
],
);
}
}
@@ -0,0 +1,105 @@
import 'dart:ui';
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/src/stores/send/sending_state.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/stores/send/send_store.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
class SendingAlert extends StatefulWidget {
SendingAlert({@required this.sendStore});
final SendStore sendStore;
@override
SendingAlertState createState() => SendingAlertState(sendStore);
}
class SendingAlertState extends State<SendingAlert> {
SendingAlertState(this.sendStore);
final SendStore sendStore;
@override
Widget build(BuildContext context) {
return Observer(
builder: (_) {
final state = sendStore.state;
if (state is TransactionCommitted) {
return Stack(
children: <Widget>[
Container(
color: PaletteDark.historyPanel,
child: Center(
child: Image.asset(
'assets/images/birthday_cake.png'),
),
),
Center(
child: Padding(
padding: EdgeInsets.only(top: 220, left: 24, right: 24),
child: Text(
S.of(context).send_success,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.white,
decoration: TextDecoration.none,
),
),
),
),
Positioned(
left: 24,
right: 24,
bottom: 24,
child: PrimaryButton(
onPressed: () => Navigator.of(context).pop(),
text: S.of(context).send_got_it,
color: Colors.blue,
textColor: Colors.white
)
)
],
);
}
return Stack(
children: <Widget>[
Container(
color: PaletteDark.historyPanel,
child: Center(
child: Image.asset(
'assets/images/birthday_cake.png'),
),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0),
child: Container(
decoration: BoxDecoration(color: PaletteDark.historyPanel.withOpacity(0.25)),
child: Center(
child: Padding(
padding: EdgeInsets.only(top: 220),
child: Text(
S.of(context).send_sending,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.white,
decoration: TextDecoration.none,
),
),
),
),
),
)
],
);
}
);
}
}
@@ -0,0 +1,76 @@
import 'package:flutter/material.dart';
import 'package:cake_wallet/palette.dart';
class TemplateTile extends StatelessWidget {
TemplateTile({
@required this.name,
@required this.amount,
@required this.cryptoCurrency,
@required this.onTap
});
final String name;
final String amount;
final String cryptoCurrency;
final VoidCallback onTap;
final toIcon = Image.asset('assets/images/to_icon.png');
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(right: 10),
child: GestureDetector(
onTap: onTap,
child: Container(
height: 40,
padding: EdgeInsets.only(left: 24, right: 24),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
color: PaletteDark.menuList
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
amount,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white
),
),
Padding(
padding: EdgeInsets.only(left: 5),
child: Text(
cryptoCurrency,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white
),
),
),
Padding(
padding: EdgeInsets.only(left: 5),
child: toIcon,
),
Padding(
padding: EdgeInsets.only(left: 5),
child: Text(
name,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white
),
),
),
],
),
),
),
);
}
}
+15
View File
@@ -45,6 +45,9 @@ abstract class SendStoreBase with Store {
@observable
String cryptoAmount;
@observable
String address;
@observable
bool isValid;
@@ -157,6 +160,18 @@ abstract class SendStoreBase with Store {
}
}
@action
void changeAddress(String address) {
this.address = address;
}
@action
void clear() {
address = '';
cryptoAmount = '';
fiatAmount = '';
}
Future<bool> isOpenaliasRecord(String name) async {
final _openaliasRecord = await OpenaliasRecord
.fetchAddressAndName(OpenaliasRecord.formatDomainName(name));
@@ -0,0 +1,48 @@
import 'dart:async';
import 'package:mobx/mobx.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/src/domain/common/template.dart';
import 'package:cake_wallet/generated/i18n.dart';
part 'send_template_store.g.dart';
class SendTemplateStore = SendTemplateBase with _$SendTemplateStore;
abstract class SendTemplateBase with Store {
SendTemplateBase({this.templateSource}) {
templates = ObservableList<Template>();
update();
}
@observable
ObservableList<Template> templates;
@observable
bool isValid;
@observable
String errorMessage;
Box<Template> templateSource;
@action
void update() =>
templates.replaceRange(0, templates.length, templateSource.values.toList());
@action
Future addTemplate({String name, String address, String cryptoCurrency, String amount}) async {
final template = Template(name: name, address: address,
cryptoCurrency: cryptoCurrency, amount: amount);
await templateSource.add(template);
}
@action
Future remove({Template template}) async => await template.delete();
void validateTemplate(String value) {
const pattern = '''^[^`,'"]{1,106}\$''';
final regExp = RegExp(pattern);
isValid = regExp.hasMatch(value);
errorMessage = isValid ? null : S.current.error_text_template;
}
}
+19 -10
View File
@@ -40,6 +40,10 @@ class AddressTextField extends StatelessWidget {
enabled: isActive,
controller: controller,
focusNode: focusNode,
style: TextStyle(
fontSize: 16,
color: Colors.white
),
decoration: InputDecoration(
suffixIcon: SizedBox(
width: prefixIconWidth * options.length +
@@ -58,9 +62,9 @@ class AddressTextField extends StatelessWidget {
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Palette.wildDarkBlueWithOpacity,
color: PaletteDark.walletCardSubAddressField,
borderRadius:
BorderRadius.all(Radius.circular(8))),
BorderRadius.all(Radius.circular(6))),
child: Image.asset('assets/images/qr_code_icon.png')),
))
],
@@ -76,11 +80,11 @@ class AddressTextField extends StatelessWidget {
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Palette.wildDarkBlueWithOpacity,
color: PaletteDark.walletCardSubAddressField,
borderRadius:
BorderRadius.all(Radius.circular(8))),
BorderRadius.all(Radius.circular(6))),
child: Image.asset(
'assets/images/address_book_icon.png')),
'assets/images/open_book.png')),
))
],
if (this
@@ -95,9 +99,9 @@ class AddressTextField extends StatelessWidget {
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Palette.wildDarkBlueWithOpacity,
color: PaletteDark.walletCardSubAddressField,
borderRadius:
BorderRadius.all(Radius.circular(8))),
BorderRadius.all(Radius.circular(6))),
child: Image.asset(
'assets/images/receive_icon_raw.png')),
))
@@ -105,13 +109,18 @@ class AddressTextField extends StatelessWidget {
],
),
),
hintStyle: TextStyle(color: Theme.of(context).hintColor),
hintStyle: TextStyle(
fontSize: 16,
color: PaletteDark.walletCardText
),
hintText: placeholder ?? S.current.widgets_address,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Palette.cakeGreen, width: 2.0)),
borderSide: BorderSide(
color: PaletteDark.walletCardSubAddressField,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).focusColor, width: 1.0)),
BorderSide(color: PaletteDark.walletCardSubAddressField, width: 1.0)),
),
validator: validator,
);
+1 -1
View File
@@ -138,7 +138,7 @@ class BaseAlertDialog extends StatelessWidget {
Container(
width: 300,
height: 77,
padding: EdgeInsets.all(24),
padding: EdgeInsets.only(left: 24, right: 24),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
-1
View File
@@ -238,7 +238,6 @@ class SeedWidgetState extends State<SeedWidget> {
fit: FlexFit.tight,
flex: 1,
child: TopPanel(
height: null,
color: PaletteDark.menuList,
widget: SingleChildScrollView(
child: Column(
+1 -3
View File
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
class TopPanel extends StatelessWidget {
TopPanel({@required this.height, @required this.color, @required this.widget});
TopPanel({@required this.color, @required this.widget});
final double height;
final Color color;
final Widget widget;
@@ -11,7 +10,6 @@ class TopPanel extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: height ?? double.infinity,
padding: EdgeInsets.all(24),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(