This commit is contained in:
M
2020-08-25 19:32:40 +03:00
parent 4572049c5d
commit 5eefd6a31b
35 changed files with 1273 additions and 618 deletions
@@ -1,6 +1,7 @@
import 'package:cake_wallet/src/domain/common/transaction_direction.dart';
abstract class TransactionInfo extends Object {
String id;
int amount;
TransactionDirection direction;
bool isPending;
+278 -252
View File
@@ -1,40 +1,27 @@
import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/core/amount_validator.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
import 'package:cake_wallet/view_model/send_view_model.dart';
import 'dart:ui';
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/routes.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.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/wallet/wallet_store.dart';
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/widgets/scollable_with_bottom_section.dart';
import 'package:cake_wallet/view_model/send/send_view_model.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/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/widgets/template_tile.dart';
import 'package:cake_wallet/src/stores/send_template/send_template_store.dart';
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
import 'package:cake_wallet/src/widgets/trail_button.dart';
// FIXME: Refactor this screen.
class SendPage extends BasePage {
SendPage({@required this.sendViewModel});
@@ -53,11 +40,8 @@ class SendPage extends BasePage {
bool get resizeToAvoidBottomPadding => false;
@override
Widget trailing(context) {
// final sendStore = Provider.of<SendStore>(context);
return TrailButton(caption: S.of(context).clear, onPressed: () => null);
}
Widget trailing(context) => TrailButton(
caption: S.of(context).clear, onPressed: () => sendViewModel.reset());
@override
Widget body(BuildContext context) => SendForm(sendViewModel: sendViewModel);
@@ -95,36 +79,28 @@ class SendFormState extends State<SendForm> {
}
Future<void> getOpenaliasRecord(BuildContext context) async {
final sendStore = Provider.of<SendStore>(context);
final isOpenalias =
await sendStore.isOpenaliasRecord(_addressController.text);
if (isOpenalias) {
_addressController.text = sendStore.recordAddress;
await showDialog<void>(
context: context,
builder: (BuildContext context) {
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());
});
}
// final sendStore = Provider.of<SendStore>(context);
// final isOpenalias =
// await sendStore.isOpenaliasRecord(_addressController.text);
//
// if (isOpenalias) {
// _addressController.text = sendStore.recordAddress;
//
// await showDialog<void>(
// context: context,
// builder: (BuildContext context) {
// 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());
// });
// }
}
@override
Widget build(BuildContext context) {
// final settingsStore = Provider.of<SettingsStore>(context);
// final sendStore = Provider.of<SendStore>(context);
// sendStore.settingsStore = settingsStore;
// 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 Container(
@@ -140,7 +116,8 @@ class SendFormState extends State<SendForm> {
child: Column(children: <Widget>[
AddressTextField(
controller: _addressController,
placeholder: S.of(context).send_monero_address,
placeholder: 'Address',
//S.of(context).send_monero_address, FIXME: placeholder for btc and xmr address text field.
focusNode: _focusNode,
onURIScanned: (uri) {
var address = '';
@@ -163,110 +140,86 @@ class SendFormState extends State<SendForm> {
buttonColor: Theme.of(context).accentTextTheme.title.color,
validator: widget.sendViewModel.addressValidator,
),
Observer(builder: (_) {
return Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
style: TextStyle(
fontSize: 16.0,
color: Theme.of(context)
.primaryTextTheme
.title
.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: 16,
fontWeight: FontWeight.w500,
Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
onChanged: (value) =>
widget.sendViewModel.setCryptoAmount(value),
style: TextStyle(
fontSize: 16.0,
color:
Theme.of(context).primaryTextTheme.title.color),
controller: _cryptoAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
// inputFormatters: [
// BlacklistingTextInputFormatter(
// RegExp('[\\-|\\ |\\,]'))
// ],
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(top: 12),
child: Text('${widget.sendViewModel.currency.toString()}:',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.primaryTextTheme
.title
.color,
)),
),
suffixIcon: Padding(
padding: EdgeInsets.only(bottom: 5),
child: Container(
height: 32,
width: 32,
margin: EdgeInsets.only(
left: 12, bottom: 7, top: 4),
decoration: BoxDecoration(
color: Theme.of(context)
.primaryTextTheme
.accentTextTheme
.title
.color,
)),
),
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(
' / ' + widget.sendViewModel.balance,
maxLines: 1,
overflow: TextOverflow.ellipsis,
borderRadius:
BorderRadius.all(Radius.circular(6))),
child: InkWell(
onTap: () => widget.sendViewModel.setAll(),
child: Center(
child: Text(S.of(context).all,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontSize: 9,
fontWeight: FontWeight.bold,
color: Theme.of(context)
.primaryTextTheme
.caption
.color)),
),
Container(
height: 32,
width: 32,
margin: EdgeInsets.only(
left: 12, bottom: 7, top: 4),
decoration: BoxDecoration(
color: Theme.of(context)
.accentTextTheme
.title
.color,
borderRadius: BorderRadius.all(
Radius.circular(6))),
child: InkWell(
onTap: () => null,
// widget.sendViewModel,
child: Center(
child: Text(S.of(context).all,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 9,
fontWeight: FontWeight.bold,
color: Theme.of(context)
.primaryTextTheme
.caption
.color)),
),
),
)
],
),
),
hintStyle: TextStyle(
fontSize: 16.0,
color: Theme.of(context)
.primaryTextTheme
.title
.color),
hintText: '0.0000',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).dividerColor,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).dividerColor,
width: 1.0))),
validator: widget.sendViewModel.amountValidator),
);
}),
),
)),
hintStyle: TextStyle(
fontSize: 16.0,
color: Theme.of(context)
.primaryTextTheme
.title
.color),
hintText: '0.0000',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).dividerColor,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).dividerColor,
width: 1.0))),
validator: widget.sendViewModel.amountValidator),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: TextFormField(
onChanged: (value) =>
widget.sendViewModel.setFiatAmount(value),
style: TextStyle(
fontSize: 16.0,
color:
@@ -274,10 +227,10 @@ class SendFormState extends State<SendForm> {
controller: _fiatAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
BlacklistingTextInputFormatter(
RegExp('[\\-|\\ |\\,]'))
],
// inputFormatters: [
// BlacklistingTextInputFormatter(
// RegExp('[\\-|\\ |\\,]'))
// ],
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(top: 12),
@@ -426,52 +379,43 @@ class SendFormState extends State<SendForm> {
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
bottomSection: Observer(builder: (_) {
return LoadingPrimaryButton(
onPressed: () => null,
// syncStore.status is SyncedSyncStatus
// ? () async {
// // Hack. Don't ask me.
// FocusScope.of(context).requestFocus(FocusNode());
//
// 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();
//
// sendStore.createTransaction(
// address: _addressController.text,
// paymentId: '');
// });
// },
// actionRightButton: () =>
// Navigator.of(context).pop());
// });
// }
// }
// : null,
onPressed: () async {
FocusScope.of(context).requestFocus(FocusNode());
if (!_formKey.currentState.validate()) {
return;
}
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();
widget.sendViewModel.createTransaction();
});
},
actionRightButton: () => Navigator.of(context).pop());
});
},
text: S.of(context).send,
color: Colors.blue,
textColor: Colors.white,
isLoading: widget.sendViewModel.state is TransactionIsCreating ||
widget.sendViewModel.state is TransactionCommitting,
isDisabled:
false // FIXME !(syncStore.status is SyncedSyncStatus),
);
isDisabled: !widget.sendViewModel.isReadyForSend);
}),
),
);
@@ -482,47 +426,42 @@ class SendFormState extends State<SendForm> {
return;
}
// reaction((_) => widget.sendViewModel.fiatAmount, (String amount) {
// if (amount != _fiatAmountController.text) {
// _fiatAmountController.text = amount;
// }
// });
//
// reaction((_) => widget.sendViewModel.cryptoAmount, (String amount) {
// if (amount != _cryptoAmountController.text) {
// _cryptoAmountController.text = amount;
// }
// });
//
// reaction((_) => widget.sendViewModel.address, (String address) {
// if (address != _addressController.text) {
// _addressController.text = address;
// }
// });
//
// _addressController.addListener(() {
// final address = _addressController.text;
//
// if (widget.sendViewModel.address != address) {
// widget.sendViewModel.changeAddress(address);
// }
// });
reaction((_) => widget.sendViewModel.all, (bool all) {
if (all) {
_cryptoAmountController.text = S.current.all;
_fiatAmountController.text = null;
}
});
// _fiatAmountController.addListener(() {
// final fiatAmount = _fiatAmountController.text;
//
// if (sendStore.fiatAmount != fiatAmount) {
// sendStore.changeFiatAmount(fiatAmount);
// }
// });
reaction((_) => widget.sendViewModel.fiatAmount, (String amount) {
if (amount != _fiatAmountController.text) {
_fiatAmountController.text = amount;
}
});
// _cryptoAmountController.addListener(() {
// final cryptoAmount = _cryptoAmountController.text;
//
// if (sendStore.cryptoAmount != cryptoAmount) {
// sendStore.changeCryptoAmount(cryptoAmount);
// }
// });
reaction((_) => widget.sendViewModel.cryptoAmount, (String amount) {
if (widget.sendViewModel.all && amount != S.current.all) {
widget.sendViewModel.all = false;
}
if (amount != _cryptoAmountController.text) {
_cryptoAmountController.text = amount;
}
});
reaction((_) => widget.sendViewModel.address, (String address) {
if (address != _addressController.text) {
_addressController.text = address;
}
});
_addressController.addListener(() {
final address = _addressController.text;
if (widget.sendViewModel.address != address) {
widget.sendViewModel.address = address;
}
});
reaction((_) => widget.sendViewModel.state, (SendViewModelState state) {
if (state is SendingFailed) {
@@ -540,30 +479,117 @@ class SendFormState extends State<SendForm> {
}
if (state is TransactionCreatedSuccessfully) {
// WidgetsBinding.instance.addPostFrameCallback((_) {
// showDialog<void>(
// context: context,
// builder: (BuildContext context) {
// 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());
// });
// });
WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return ConfirmSendingAlert(
alertTitle: S.of(context).confirm_sending,
amount: S.of(context).send_amount,
amountValue:
widget.sendViewModel.pendingTransaction.amountFormatted,
fee: S.of(context).send_fee,
feeValue:
widget.sendViewModel.pendingTransaction.feeFormatted,
leftButtonText: S.of(context).ok,
rightButtonText: S.of(context).cancel,
actionLeftButton: () {
Navigator.of(context).pop();
widget.sendViewModel.commitTransaction();
showDialog<void>(
context: context,
builder: (BuildContext context) {
return Observer(builder: (_) {
final state = widget.sendViewModel.state;
if (state is TransactionCommitted) {
return Stack(
children: <Widget>[
Container(
color: Theme.of(context).backgroundColor,
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: Theme.of(context)
.primaryTextTheme
.title
.color,
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: Theme.of(context).backgroundColor,
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: Theme.of(context)
.backgroundColor
.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: Theme.of(context)
.primaryTextTheme
.title
.color,
decoration: TextDecoration.none,
),
),
),
),
),
)
],
);
});
});
},
actionRightButton: () => Navigator.of(context).pop());
});
});
}
if (state is TransactionCommitted) {
@@ -1,6 +1,6 @@
import 'dart:ui';
import 'package:cake_wallet/src/stores/send/sending_state.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/src/stores/send/sending_state.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';
+5 -3
View File
@@ -39,9 +39,11 @@ class SettingsPage extends BasePage {
if (item is PickerListItem) {
return Observer(builder: (_) {
return SettingsPickerCell<dynamic>(
title: item.title,
selectedItem: item.selectedItem(),
items: item.items);
title: item.title,
selectedItem: item.selectedItem(),
items: item.items,
onItemSelected: (dynamic value) => item.onItemSelected(value),
);
});
}
@@ -4,25 +4,30 @@ import 'package:cake_wallet/src/widgets/standard_list.dart';
import 'package:cake_wallet/generated/i18n.dart';
class SettingsPickerCell<ItemType> extends StandardListRow {
SettingsPickerCell({@required String title, this.selectedItem, this.items})
SettingsPickerCell(
{@required String title,
this.selectedItem,
this.items,
this.onItemSelected})
: super(
title: title,
isSelected: false,
onTap: (BuildContext context) async {
final selectedAtIndex = items.indexOf(selectedItem);
title: title,
isSelected: false,
onTap: (BuildContext context) async {
final selectedAtIndex = items.indexOf(selectedItem);
await showDialog<void>(
context: context,
builder: (_) => Picker(
items: items,
selectedAtIndex: selectedAtIndex,
title: S.current.please_select,
mainAxisAlignment: MainAxisAlignment.center,
onItemSelected: (Object _) {}));
});
await showDialog<void>(
context: context,
builder: (_) => Picker(
items: items,
selectedAtIndex: selectedAtIndex,
title: S.current.please_select,
mainAxisAlignment: MainAxisAlignment.center,
onItemSelected: (ItemType item) => onItemSelected?.call(item)));
});
final ItemType selectedItem;
final List<ItemType> items;
final void Function(ItemType item) onItemSelected;
@override
Widget buildTrailing(BuildContext context) {
@@ -35,4 +40,4 @@ class SettingsPickerCell<ItemType> extends StandardListRow {
color: Theme.of(context).primaryTextTheme.caption.color),
);
}
}
}