mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 02:34:59 +00:00
CAKE-345 | reworked send page for batch sending; added send_item.dart, send_card.dart, send_template_view_model.dart and parse_address_from_domain_alert.dart to the app; reworked send template page; fixed exchange_trade_page.dart and exchange_trade_view_model.dart
This commit is contained in:
parent
96ea969519
commit
e6cfa2b636
13 changed files with 1189 additions and 876 deletions
13
lib/di.dart
13
lib/di.dart
|
@ -72,6 +72,7 @@ import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.
|
||||||
import 'package:cake_wallet/view_model/order_details_view_model.dart';
|
import 'package:cake_wallet/view_model/order_details_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/rescan_view_model.dart';
|
import 'package:cake_wallet/view_model/rescan_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/restore_from_backup_view_model.dart';
|
import 'package:cake_wallet/view_model/restore_from_backup_view_model.dart';
|
||||||
|
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
|
import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/support_view_model.dart';
|
import 'package:cake_wallet/view_model/support_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/transaction_details_view_model.dart';
|
import 'package:cake_wallet/view_model/transaction_details_view_model.dart';
|
||||||
|
@ -307,10 +308,17 @@ Future setup(
|
||||||
addressEditOrCreateViewModel:
|
addressEditOrCreateViewModel:
|
||||||
getIt.get<WalletAddressEditOrCreateViewModel>(param1: item)));
|
getIt.get<WalletAddressEditOrCreateViewModel>(param1: item)));
|
||||||
|
|
||||||
getIt.registerFactory<SendViewModel>(() => SendViewModel(
|
getIt.registerFactory<SendTemplateViewModel>(() => SendTemplateViewModel(
|
||||||
getIt.get<AppStore>().wallet,
|
getIt.get<AppStore>().wallet,
|
||||||
getIt.get<AppStore>().settingsStore,
|
getIt.get<AppStore>().settingsStore,
|
||||||
getIt.get<SendTemplateStore>(),
|
getIt.get<SendTemplateStore>(),
|
||||||
|
getIt.get<FiatConversionStore>()
|
||||||
|
));
|
||||||
|
|
||||||
|
getIt.registerFactory<SendViewModel>(() => SendViewModel(
|
||||||
|
getIt.get<AppStore>().wallet,
|
||||||
|
getIt.get<AppStore>().settingsStore,
|
||||||
|
getIt.get<SendTemplateViewModel>(),
|
||||||
getIt.get<FiatConversionStore>(),
|
getIt.get<FiatConversionStore>(),
|
||||||
_transactionDescriptionBox));
|
_transactionDescriptionBox));
|
||||||
|
|
||||||
|
@ -318,7 +326,8 @@ Future setup(
|
||||||
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
|
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
|
||||||
|
|
||||||
getIt.registerFactory(
|
getIt.registerFactory(
|
||||||
() => SendTemplatePage(sendViewModel: getIt.get<SendViewModel>()));
|
() => SendTemplatePage(
|
||||||
|
sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
|
||||||
|
|
||||||
getIt.registerFactory(() => WalletListViewModel(
|
getIt.registerFactory(() => WalletListViewModel(
|
||||||
_walletInfoSource,
|
_walletInfoSource,
|
||||||
|
|
|
@ -262,6 +262,9 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
|
|
||||||
if (state is ExecutedSuccessfullyState) {
|
if (state is ExecutedSuccessfullyState) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
final item = widget.exchangeTradeViewModel.sendViewModel
|
||||||
|
.sendItemList.first;
|
||||||
|
|
||||||
showPopUp<void>(
|
showPopUp<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
@ -386,8 +389,7 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
' ' +
|
' ' +
|
||||||
widget.exchangeTradeViewModel.sendViewModel.fiat.title,
|
widget.exchangeTradeViewModel.sendViewModel.fiat.title,
|
||||||
recipientTitle: S.of(context).recipient_address,
|
recipientTitle: S.of(context).recipient_address,
|
||||||
recipientAddress:
|
recipientAddress: item.address);
|
||||||
widget.exchangeTradeViewModel.sendViewModel.address);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
import 'package:cake_wallet/entities/monero_transaction_priority.dart';
|
import 'package:cake_wallet/src/screens/send/widgets/parse_address_from_domain_alert.dart';
|
||||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
import 'package:cake_wallet/src/screens/send/widgets/send_card.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||||
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
|
||||||
import 'package:cake_wallet/src/widgets/picker.dart';
|
|
||||||
import 'package:cake_wallet/src/widgets/template_tile.dart';
|
import 'package:cake_wallet/src/widgets/template_tile.dart';
|
||||||
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
|
import 'package:cake_wallet/view_model/send/send_item.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.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:keyboard_actions/keyboard_actions.dart';
|
|
||||||
import 'package:cake_wallet/routes.dart';
|
import 'package:cake_wallet/routes.dart';
|
||||||
import 'package:cake_wallet/view_model/send/send_view_model.dart';
|
import 'package:cake_wallet/view_model/send/send_view_model.dart';
|
||||||
import 'package:cake_wallet/core/execution_state.dart';
|
import 'package:cake_wallet/core/execution_state.dart';
|
||||||
|
@ -21,42 +17,18 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
||||||
import 'package:cake_wallet/src/widgets/trail_button.dart';
|
import 'package:cake_wallet/src/widgets/trail_button.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
||||||
import 'package:cake_wallet/src/widgets/address_text_field.dart';
|
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:dotted_border/dotted_border.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_one_action.dart';
|
||||||
import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart';
|
import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart';
|
||||||
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||||
|
|
||||||
class SendPage extends BasePage {
|
class SendPage extends BasePage {
|
||||||
SendPage({@required this.sendViewModel})
|
SendPage({@required this.sendViewModel}) :_formKey = GlobalKey<FormState>();
|
||||||
: _addressController = TextEditingController(),
|
|
||||||
_cryptoAmountController = TextEditingController(),
|
|
||||||
_fiatAmountController = TextEditingController(),
|
|
||||||
_noteController = TextEditingController(),
|
|
||||||
_formKey = GlobalKey<FormState>(),
|
|
||||||
_cryptoAmountFocus = FocusNode(),
|
|
||||||
_fiatAmountFocus = FocusNode(),
|
|
||||||
_addressFocusNode = FocusNode() {
|
|
||||||
_addressFocusNode.addListener(() {
|
|
||||||
if (!_addressFocusNode.hasFocus && _addressController.text.isNotEmpty) {
|
|
||||||
getOpenaliasRecord(_addressFocusNode.context);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static const prefixIconWidth = 34.0;
|
|
||||||
static const prefixIconHeight = 34.0;
|
|
||||||
|
|
||||||
final SendViewModel sendViewModel;
|
final SendViewModel sendViewModel;
|
||||||
final TextEditingController _addressController;
|
|
||||||
final TextEditingController _cryptoAmountController;
|
|
||||||
final TextEditingController _fiatAmountController;
|
|
||||||
final TextEditingController _noteController;
|
|
||||||
final GlobalKey<FormState> _formKey;
|
final GlobalKey<FormState> _formKey;
|
||||||
final FocusNode _cryptoAmountFocus;
|
final controller = PageController(initialPage: 0);
|
||||||
final FocusNode _fiatAmountFocus;
|
|
||||||
final FocusNode _addressFocusNode;
|
|
||||||
|
|
||||||
bool _effectsInstalled = false;
|
bool _effectsInstalled = false;
|
||||||
|
|
||||||
|
@ -76,505 +48,277 @@ class SendPage extends BasePage {
|
||||||
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget trailing(context) => TrailButton(
|
Widget trailing(context) => Observer(builder: (_) {
|
||||||
caption: S.of(context).clear,
|
return sendViewModel.isRemoveButtonShow
|
||||||
onPressed: () {
|
? TrailButton(
|
||||||
_formKey.currentState.reset();
|
caption: S.of(context).remove,
|
||||||
sendViewModel.reset();
|
onPressed: () {
|
||||||
});
|
var pageToJump = controller.page.round() - 1;
|
||||||
|
pageToJump = pageToJump > 0 ? pageToJump : 0;
|
||||||
|
final item = _defineCurrentSendItem();
|
||||||
|
sendViewModel.removeSendItem(item);
|
||||||
|
controller.jumpToPage(pageToJump);
|
||||||
|
})
|
||||||
|
: TrailButton(
|
||||||
|
caption: S.of(context).clear,
|
||||||
|
onPressed: () {
|
||||||
|
final item = _defineCurrentSendItem();
|
||||||
|
_formKey.currentState.reset();
|
||||||
|
item.reset();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) {
|
Widget body(BuildContext context) {
|
||||||
_setEffects(context);
|
_setEffects(context);
|
||||||
|
|
||||||
return KeyboardActions(
|
return Form(
|
||||||
config: KeyboardActionsConfig(
|
key: _formKey,
|
||||||
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
|
child: ScrollableWithBottomSection(
|
||||||
keyboardBarColor: Theme.of(context).accentTextTheme.body2
|
contentPadding: EdgeInsets.only(bottom: 24),
|
||||||
.backgroundColor,
|
content: Column(
|
||||||
nextFocus: false,
|
children: <Widget>[
|
||||||
actions: [
|
Container(
|
||||||
KeyboardActionsItem(
|
height: 445,
|
||||||
focusNode: _cryptoAmountFocus,
|
child: Observer(
|
||||||
toolbarButtons: [(_) => KeyboardDoneButton()],
|
builder: (_) {
|
||||||
|
return PageView.builder(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
controller: controller,
|
||||||
|
itemCount: sendViewModel.sendItemList.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final item = sendViewModel.sendItemList[index];
|
||||||
|
|
||||||
|
return SendCard(
|
||||||
|
key: item.key,
|
||||||
|
item: item,
|
||||||
|
sendViewModel: sendViewModel,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
),
|
),
|
||||||
KeyboardActionsItem(
|
Padding(
|
||||||
focusNode: _fiatAmountFocus,
|
padding: EdgeInsets.only(top: 10, left: 24, right: 24, bottom: 10),
|
||||||
toolbarButtons: [(_) => KeyboardDoneButton()],
|
child: Container(
|
||||||
)
|
height: 10,
|
||||||
]),
|
child: Observer(builder: (_) {
|
||||||
child: Container(
|
final count = sendViewModel.sendItemList.length;
|
||||||
height: 0,
|
|
||||||
color: Theme.of(context).backgroundColor,
|
|
||||||
child: ScrollableWithBottomSection(
|
|
||||||
contentPadding: EdgeInsets.only(bottom: 24),
|
|
||||||
content: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.only(
|
|
||||||
bottomLeft: Radius.circular(24),
|
|
||||||
bottomRight: Radius.circular(24)),
|
|
||||||
gradient: LinearGradient(colors: [
|
|
||||||
Theme.of(context).primaryTextTheme.subhead.color,
|
|
||||||
Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.subhead
|
|
||||||
.decorationColor,
|
|
||||||
], begin: Alignment.topLeft, end: Alignment.bottomRight),
|
|
||||||
),
|
|
||||||
child: Form(
|
|
||||||
key: _formKey,
|
|
||||||
child: Column(children: <Widget>[
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(24, 100, 24, 32),
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
AddressTextField(
|
|
||||||
focusNode: _addressFocusNode,
|
|
||||||
controller: _addressController,
|
|
||||||
onURIScanned: (uri) {
|
|
||||||
var address = '';
|
|
||||||
var amount = '';
|
|
||||||
|
|
||||||
if (uri != null) {
|
return count > 1
|
||||||
address = uri.path;
|
? SmoothPageIndicator(
|
||||||
amount = uri.queryParameters['tx_amount'] ??
|
controller: controller,
|
||||||
uri.queryParameters['amount'];
|
count: count,
|
||||||
} else {
|
effect: ScrollingDotsEffect(
|
||||||
address = uri.toString();
|
spacing: 6.0,
|
||||||
}
|
radius: 6.0,
|
||||||
|
dotWidth: 6.0,
|
||||||
_addressController.text = address;
|
dotHeight: 6.0,
|
||||||
_cryptoAmountController.text = amount;
|
dotColor: Theme.of(context)
|
||||||
},
|
|
||||||
options: [
|
|
||||||
AddressTextFieldOption.paste,
|
|
||||||
AddressTextFieldOption.qrCode,
|
|
||||||
AddressTextFieldOption.addressBook
|
|
||||||
],
|
|
||||||
buttonColor: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
.display1
|
.display2
|
||||||
.color,
|
.backgroundColor,
|
||||||
borderColor: Theme.of(context)
|
activeDotColor: Theme.of(context)
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
.headline
|
.display3
|
||||||
.color,
|
.backgroundColor
|
||||||
textStyle: TextStyle(
|
)
|
||||||
fontSize: 14,
|
)
|
||||||
fontWeight: FontWeight.w500,
|
: Offstage();
|
||||||
color: Colors.white),
|
})
|
||||||
hintStyle: TextStyle(
|
)
|
||||||
fontSize: 14,
|
),
|
||||||
fontWeight: FontWeight.w500,
|
Padding(
|
||||||
color: Theme.of(context)
|
padding: EdgeInsets.only(left: 24, bottom: 24),
|
||||||
.primaryTextTheme
|
child: Row(
|
||||||
.headline
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
.decorationColor),
|
children: <Widget>[
|
||||||
validator: sendViewModel.addressValidator,
|
Text(
|
||||||
),
|
S.of(context).send_templates,
|
||||||
Observer(
|
style: TextStyle(
|
||||||
builder: (_) => Padding(
|
fontSize: 18,
|
||||||
padding: const EdgeInsets.only(top: 20),
|
fontWeight: FontWeight.w600,
|
||||||
child: Stack(
|
color: Theme.of(context)
|
||||||
children: [
|
.primaryTextTheme
|
||||||
BaseTextFormField(
|
.display4
|
||||||
focusNode: _cryptoAmountFocus,
|
.color),
|
||||||
controller: _cryptoAmountController,
|
)
|
||||||
keyboardType:
|
],
|
||||||
TextInputType.numberWithOptions(
|
),
|
||||||
signed: false, decimal: true),
|
),
|
||||||
prefixIcon: Padding(
|
Container(
|
||||||
padding: EdgeInsets.only(top: 9),
|
height: 40,
|
||||||
child: Text(
|
width: double.infinity,
|
||||||
sendViewModel.currency.title +
|
padding: EdgeInsets.only(left: 24),
|
||||||
':',
|
child: SingleChildScrollView(
|
||||||
style: TextStyle(
|
scrollDirection: Axis.horizontal,
|
||||||
fontSize: 16,
|
child: Row(
|
||||||
fontWeight: FontWeight.w600,
|
children: <Widget>[
|
||||||
color: Colors.white,
|
GestureDetector(
|
||||||
)),
|
onTap: () => Navigator.of(context)
|
||||||
),
|
.pushNamed(Routes.sendTemplate),
|
||||||
suffixIcon: SizedBox(
|
child: Container(
|
||||||
width: prefixIconWidth,
|
padding: EdgeInsets.only(left: 1, right: 10),
|
||||||
),
|
child: DottedBorder(
|
||||||
hintText: '0.0000',
|
borderType: BorderType.RRect,
|
||||||
borderColor: Theme.of(context)
|
dashPattern: [6, 4],
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.color,
|
|
||||||
textStyle: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.white),
|
|
||||||
placeholderTextStyle: TextStyle(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.decorationColor,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
fontSize: 14),
|
|
||||||
validator: sendViewModel.sendAll
|
|
||||||
? sendViewModel.allAmountValidator
|
|
||||||
: sendViewModel
|
|
||||||
.amountValidator),
|
|
||||||
Positioned(
|
|
||||||
top: 2,
|
|
||||||
right: 0,
|
|
||||||
child: Container(
|
|
||||||
width: prefixIconWidth,
|
|
||||||
height: prefixIconHeight,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () async =>
|
|
||||||
sendViewModel.setSendAll(),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.display1
|
|
||||||
.color,
|
|
||||||
borderRadius:
|
|
||||||
BorderRadius.all(
|
|
||||||
Radius.circular(6))),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
S.of(context).all,
|
|
||||||
textAlign:
|
|
||||||
TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight:
|
|
||||||
FontWeight.bold,
|
|
||||||
color:
|
|
||||||
Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.display1
|
|
||||||
.decorationColor))),
|
|
||||||
))))])
|
|
||||||
)),
|
|
||||||
Observer(
|
|
||||||
builder: (_) => Padding(
|
|
||||||
padding: EdgeInsets.only(top: 10),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: <Widget>[
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
S.of(context).available_balance +
|
|
||||||
':',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.decorationColor),
|
|
||||||
)),
|
|
||||||
Text(
|
|
||||||
sendViewModel.balance,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.decorationColor),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 20),
|
|
||||||
child: BaseTextFormField(
|
|
||||||
focusNode: _fiatAmountFocus,
|
|
||||||
controller: _fiatAmountController,
|
|
||||||
keyboardType:
|
|
||||||
TextInputType.numberWithOptions(
|
|
||||||
signed: false, decimal: true),
|
|
||||||
prefixIcon: Padding(
|
|
||||||
padding: EdgeInsets.only(top: 9),
|
|
||||||
child:
|
|
||||||
Text(sendViewModel.fiat.title + ':',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.white,
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
hintText: '0.00',
|
|
||||||
borderColor: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.color,
|
|
||||||
textStyle: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.white),
|
|
||||||
placeholderTextStyle: TextStyle(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.decorationColor,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
fontSize: 14),
|
|
||||||
)),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.only(top: 20),
|
|
||||||
child: BaseTextFormField(
|
|
||||||
controller: _noteController,
|
|
||||||
keyboardType: TextInputType.multiline,
|
|
||||||
maxLines: null,
|
|
||||||
borderColor: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.color,
|
|
||||||
textStyle: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.white),
|
|
||||||
hintText: S.of(context).note_optional,
|
|
||||||
placeholderTextStyle: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.decorationColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Observer(
|
|
||||||
builder: (_) => GestureDetector(
|
|
||||||
onTap: () =>
|
|
||||||
_setTransactionPriority(context),
|
|
||||||
child: Container(
|
|
||||||
padding: EdgeInsets.only(top: 24),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: <Widget>[
|
|
||||||
Text(
|
|
||||||
S
|
|
||||||
.of(context)
|
|
||||||
.send_estimated_fee,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight:
|
|
||||||
FontWeight.w500,
|
|
||||||
//color: Theme.of(context).primaryTextTheme.display2.color,
|
|
||||||
color: Colors.white)),
|
|
||||||
Container(
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: <Widget>[
|
|
||||||
Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
sendViewModel
|
|
||||||
.estimatedFee
|
|
||||||
.toString() +
|
|
||||||
' ' +
|
|
||||||
sendViewModel
|
|
||||||
.currency.title,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight:
|
|
||||||
FontWeight.w600,
|
|
||||||
//color: Theme.of(context).primaryTextTheme.display2.color,
|
|
||||||
color:
|
|
||||||
Colors.white)),
|
|
||||||
Padding(
|
|
||||||
padding:
|
|
||||||
EdgeInsets.only(top: 5),
|
|
||||||
child: Text(
|
|
||||||
sendViewModel
|
|
||||||
.estimatedFeeFiatAmount
|
|
||||||
+ ' ' +
|
|
||||||
sendViewModel
|
|
||||||
.fiat.title,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight:
|
|
||||||
FontWeight.w600,
|
|
||||||
color: Theme
|
|
||||||
.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.headline
|
|
||||||
.decorationColor))
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
top: 2,
|
|
||||||
left: 5),
|
|
||||||
child: Icon(
|
|
||||||
Icons.arrow_forward_ios,
|
|
||||||
size: 12,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.only(top: 30, 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: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
.display4
|
.display2
|
||||||
.color),
|
.decorationColor,
|
||||||
)
|
strokeWidth: 2,
|
||||||
],
|
radius: Radius.circular(20),
|
||||||
),
|
child: Container(
|
||||||
),
|
height: 34,
|
||||||
Container(
|
width: 75,
|
||||||
height: 40,
|
padding:
|
||||||
width: double.infinity,
|
EdgeInsets.only(left: 10, right: 10),
|
||||||
padding: EdgeInsets.only(left: 24),
|
alignment: Alignment.center,
|
||||||
child: SingleChildScrollView(
|
decoration: BoxDecoration(
|
||||||
scrollDirection: Axis.horizontal,
|
borderRadius:
|
||||||
child: Row(
|
BorderRadius.all(Radius.circular(20)),
|
||||||
children: <Widget>[
|
color: Colors.transparent,
|
||||||
GestureDetector(
|
),
|
||||||
onTap: () => Navigator.of(context)
|
child: Text(
|
||||||
.pushNamed(Routes.sendTemplate),
|
S.of(context).send_new,
|
||||||
child: Container(
|
style: TextStyle(
|
||||||
padding: EdgeInsets.only(left: 1, right: 10),
|
fontSize: 14,
|
||||||
child: DottedBorder(
|
fontWeight: FontWeight.w600,
|
||||||
borderType: BorderType.RRect,
|
color: Theme.of(context)
|
||||||
dashPattern: [6, 4],
|
.primaryTextTheme
|
||||||
color: Theme.of(context)
|
.display3
|
||||||
.primaryTextTheme
|
.color),
|
||||||
.display2
|
),
|
||||||
.decorationColor,
|
)),
|
||||||
strokeWidth: 2,
|
),
|
||||||
radius: Radius.circular(20),
|
|
||||||
child: Container(
|
|
||||||
height: 34,
|
|
||||||
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: Theme.of(context)
|
|
||||||
.primaryTextTheme
|
|
||||||
.display3
|
|
||||||
.color),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Observer(builder: (_) {
|
|
||||||
final templates = sendViewModel.templates;
|
|
||||||
final itemCount = templates.length;
|
|
||||||
|
|
||||||
return ListView.builder(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
shrinkWrap: true,
|
|
||||||
physics: NeverScrollableScrollPhysics(),
|
|
||||||
itemCount: itemCount,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final template = templates[index];
|
|
||||||
|
|
||||||
return TemplateTile(
|
|
||||||
key: UniqueKey(),
|
|
||||||
to: template.name,
|
|
||||||
amount: template.amount,
|
|
||||||
from: template.cryptoCurrency,
|
|
||||||
onTap: () {
|
|
||||||
_addressController.text =
|
|
||||||
template.address;
|
|
||||||
_cryptoAmountController.text =
|
|
||||||
template.amount;
|
|
||||||
getOpenaliasRecord(context);
|
|
||||||
},
|
|
||||||
onRemove: () {
|
|
||||||
showPopUp<void>(
|
|
||||||
context: context,
|
|
||||||
builder: (dialogContext) {
|
|
||||||
return AlertWithTwoActions(
|
|
||||||
alertTitle:
|
|
||||||
S.of(context).template,
|
|
||||||
alertContent: S
|
|
||||||
.of(context)
|
|
||||||
.confirm_delete_template,
|
|
||||||
rightButtonText:
|
|
||||||
S.of(context).delete,
|
|
||||||
leftButtonText:
|
|
||||||
S.of(context).cancel,
|
|
||||||
actionRightButton: () {
|
|
||||||
Navigator.of(dialogContext)
|
|
||||||
.pop();
|
|
||||||
sendViewModel.removeTemplate(
|
|
||||||
template: template);
|
|
||||||
sendViewModel
|
|
||||||
.updateTemplate();
|
|
||||||
},
|
|
||||||
actionLeftButton: () =>
|
|
||||||
Navigator.of(dialogContext)
|
|
||||||
.pop());
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
Observer(builder: (_) {
|
||||||
)
|
final templates = sendViewModel.templates;
|
||||||
],
|
final itemCount = templates.length;
|
||||||
|
|
||||||
|
return ListView.builder(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: NeverScrollableScrollPhysics(),
|
||||||
|
itemCount: itemCount,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final template = templates[index];
|
||||||
|
|
||||||
|
return TemplateTile(
|
||||||
|
key: UniqueKey(),
|
||||||
|
to: template.name,
|
||||||
|
amount: template.amount,
|
||||||
|
from: template.cryptoCurrency,
|
||||||
|
onTap: () async {
|
||||||
|
final item = _defineCurrentSendItem();
|
||||||
|
item.address =
|
||||||
|
template.address;
|
||||||
|
item.setCryptoAmount(template.amount);
|
||||||
|
final record =
|
||||||
|
await item.getOpenaliasRecord();
|
||||||
|
|
||||||
|
if (record != null) {
|
||||||
|
showAddressAlert(
|
||||||
|
context,
|
||||||
|
S.current.openalias_alert_title,
|
||||||
|
S.current
|
||||||
|
.openalias_alert_content(record.name));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onRemove: () {
|
||||||
|
showPopUp<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return AlertWithTwoActions(
|
||||||
|
alertTitle:
|
||||||
|
S.of(context).template,
|
||||||
|
alertContent: S
|
||||||
|
.of(context)
|
||||||
|
.confirm_delete_template,
|
||||||
|
rightButtonText:
|
||||||
|
S.of(context).delete,
|
||||||
|
leftButtonText:
|
||||||
|
S.of(context).cancel,
|
||||||
|
actionRightButton: () {
|
||||||
|
Navigator.of(dialogContext)
|
||||||
|
.pop();
|
||||||
|
sendViewModel
|
||||||
|
.sendTemplateViewModel
|
||||||
|
.removeTemplate(
|
||||||
|
template: template);
|
||||||
|
},
|
||||||
|
actionLeftButton: () =>
|
||||||
|
Navigator.of(dialogContext)
|
||||||
|
.pop());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
bottomSectionPadding:
|
||||||
|
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||||
|
bottomSection: Column(
|
||||||
|
children: [
|
||||||
|
PrimaryButton(
|
||||||
|
onPressed: () {
|
||||||
|
sendViewModel.addSendItem();
|
||||||
|
},
|
||||||
|
text: 'Add receiver',
|
||||||
|
color: Colors.green,
|
||||||
|
textColor: Colors.white,
|
||||||
),
|
),
|
||||||
bottomSectionPadding:
|
Padding(
|
||||||
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
padding: EdgeInsets.only(top: 12),
|
||||||
bottomSection: Observer(builder: (_) {
|
child: Observer(builder: (_) {
|
||||||
return LoadingPrimaryButton(
|
return LoadingPrimaryButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (_formKey.currentState.validate()) {
|
if (_formKey.currentState.validate()) {
|
||||||
await sendViewModel.createTransaction();
|
//await sendViewModel.createTransaction();
|
||||||
}
|
// FIXME: for test only
|
||||||
},
|
sendViewModel.clearSendItemList();
|
||||||
text: S.of(context).send,
|
await showPopUp<void>(
|
||||||
color: Theme.of(context).accentTextTheme.body2.color,
|
context: context,
|
||||||
textColor: Colors.white,
|
builder: (BuildContext context) {
|
||||||
isLoading: sendViewModel.state is IsExecutingState ||
|
return AlertWithOneAction(
|
||||||
sendViewModel.state is TransactionCommitting,
|
alertTitle: S.of(context).send,
|
||||||
isDisabled:
|
alertContent: S.of(context).send_success(
|
||||||
false // FIXME !(syncStore.status is SyncedSyncStatus),
|
sendViewModel.currency
|
||||||
|
.toString()),
|
||||||
|
buttonText: S.of(context).ok,
|
||||||
|
buttonAction: () => Navigator.of(context).pop());
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await showPopUp<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertWithOneAction(
|
||||||
|
alertTitle: S.of(context).error,
|
||||||
|
alertContent: 'Please, check your receivers forms',
|
||||||
|
buttonText: S.of(context).ok,
|
||||||
|
buttonAction: () =>
|
||||||
|
Navigator.of(context).pop());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
text: S.of(context).send,
|
||||||
|
color: Theme.of(context).accentTextTheme.body2.color,
|
||||||
|
textColor: Colors.white,
|
||||||
|
isLoading: sendViewModel.state is IsExecutingState ||
|
||||||
|
sendViewModel.state is TransactionCommitting,
|
||||||
|
isDisabled: !sendViewModel.isReadyForSend,
|
||||||
);
|
);
|
||||||
})),
|
},
|
||||||
));
|
))
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setEffects(BuildContext context) {
|
void _setEffects(BuildContext context) {
|
||||||
|
@ -582,78 +326,6 @@ class SendPage extends BasePage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cryptoAmountController.addListener(() {
|
|
||||||
final amount = _cryptoAmountController.text;
|
|
||||||
|
|
||||||
if (sendViewModel.sendAll && amount != S.current.all) {
|
|
||||||
sendViewModel.sendAll = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amount != sendViewModel.cryptoAmount) {
|
|
||||||
sendViewModel.setCryptoAmount(amount);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_fiatAmountController.addListener(() {
|
|
||||||
final amount = _fiatAmountController.text;
|
|
||||||
|
|
||||||
if (amount != sendViewModel.fiatAmount) {
|
|
||||||
sendViewModel.sendAll = false;
|
|
||||||
sendViewModel.setFiatAmount(amount);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_noteController.addListener(() {
|
|
||||||
final note = _noteController.text ?? '';
|
|
||||||
|
|
||||||
if (note != sendViewModel.note) {
|
|
||||||
sendViewModel.note = note;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reaction((_) => sendViewModel.sendAll, (bool all) {
|
|
||||||
if (all) {
|
|
||||||
_cryptoAmountController.text = S.current.all;
|
|
||||||
_fiatAmountController.text = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reaction((_) => sendViewModel.fiatAmount, (String amount) {
|
|
||||||
if (amount != _fiatAmountController.text) {
|
|
||||||
_fiatAmountController.text = amount;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reaction((_) => sendViewModel.cryptoAmount, (String amount) {
|
|
||||||
if (sendViewModel.sendAll && amount != S.current.all) {
|
|
||||||
sendViewModel.sendAll = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amount != _cryptoAmountController.text) {
|
|
||||||
_cryptoAmountController.text = amount;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reaction((_) => sendViewModel.address, (String address) {
|
|
||||||
if (address != _addressController.text) {
|
|
||||||
_addressController.text = address;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_addressController.addListener(() {
|
|
||||||
final address = _addressController.text;
|
|
||||||
|
|
||||||
if (sendViewModel.address != address) {
|
|
||||||
sendViewModel.address = address;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reaction((_) => sendViewModel.note, (String note) {
|
|
||||||
if (note != _noteController.text) {
|
|
||||||
_noteController.text = note;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reaction((_) => sendViewModel.state, (ExecutionState state) {
|
reaction((_) => sendViewModel.state, (ExecutionState state) {
|
||||||
if (state is FailureState) {
|
if (state is FailureState) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
@ -678,7 +350,7 @@ class SendPage extends BasePage {
|
||||||
alertTitle: S.of(context).confirm_sending,
|
alertTitle: S.of(context).confirm_sending,
|
||||||
amount: S.of(context).send_amount,
|
amount: S.of(context).send_amount,
|
||||||
amountValue:
|
amountValue:
|
||||||
sendViewModel.pendingTransaction.amountFormatted,
|
sendViewModel.pendingTransaction.amountFormatted,
|
||||||
fiatAmountValue: sendViewModel.pendingTransactionFiatAmount
|
fiatAmountValue: sendViewModel.pendingTransactionFiatAmount
|
||||||
+ ' ' + sendViewModel.fiat.title,
|
+ ' ' + sendViewModel.fiat.title,
|
||||||
fee: S.of(context).send_fee,
|
fee: S.of(context).send_fee,
|
||||||
|
@ -686,7 +358,7 @@ class SendPage extends BasePage {
|
||||||
feeFiatAmount: sendViewModel.pendingTransactionFeeFiatAmount
|
feeFiatAmount: sendViewModel.pendingTransactionFeeFiatAmount
|
||||||
+ ' ' + sendViewModel.fiat.title,
|
+ ' ' + sendViewModel.fiat.title,
|
||||||
recipientTitle: S.of(context).recipient_address,
|
recipientTitle: S.of(context).recipient_address,
|
||||||
recipientAddress: sendViewModel.address,
|
recipientAddress: '', // FIXME: sendViewModel.address,
|
||||||
rightButtonText: S.of(context).ok,
|
rightButtonText: S.of(context).ok,
|
||||||
leftButtonText: S.of(context).cancel,
|
leftButtonText: S.of(context).cancel,
|
||||||
actionRightButton: () {
|
actionRightButton: () {
|
||||||
|
@ -724,8 +396,7 @@ class SendPage extends BasePage {
|
||||||
|
|
||||||
if (state is TransactionCommitted) {
|
if (state is TransactionCommitted) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_addressController.text = '';
|
sendViewModel.clearSendItemList();
|
||||||
_cryptoAmountController.text = '';
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -733,41 +404,8 @@ class SendPage extends BasePage {
|
||||||
_effectsInstalled = true;
|
_effectsInstalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getOpenaliasRecord(BuildContext context) async {
|
SendItem _defineCurrentSendItem() {
|
||||||
final record =
|
final itemCount = controller.page.round();
|
||||||
await sendViewModel.decodeOpenaliasRecord(_addressController.text);
|
return sendViewModel.sendItemList[itemCount];
|
||||||
|
|
||||||
if (record != null) {
|
|
||||||
_addressController.text = record.address;
|
|
||||||
|
|
||||||
await showPopUp<void>(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return AlertWithOneAction(
|
|
||||||
alertTitle: S.of(context).openalias_alert_title,
|
|
||||||
alertContent:
|
|
||||||
S.of(context).openalias_alert_content(record.name),
|
|
||||||
buttonText: S.of(context).ok,
|
|
||||||
buttonAction: () => Navigator.of(context).pop());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _setTransactionPriority(BuildContext context) async {
|
|
||||||
final items = priorityForWalletType(sendViewModel.walletType);
|
|
||||||
final selectedItem = items.indexOf(sendViewModel.transactionPriority);
|
|
||||||
final isShowScrollThumb = items.length > 3;
|
|
||||||
|
|
||||||
await showPopUp<void>(
|
|
||||||
builder: (_) => Picker(
|
|
||||||
items: items,
|
|
||||||
displayItem: sendViewModel.displayFeeRate,
|
|
||||||
selectedAtIndex: selectedItem,
|
|
||||||
title: S.of(context).please_select,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
onItemSelected: (TransactionPriority priority) =>
|
|
||||||
sendViewModel.setTransactionPriority(priority),
|
|
||||||
),
|
|
||||||
context: context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,10 @@ import 'package:mobx/mobx.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
||||||
import 'package:keyboard_actions/keyboard_actions.dart';
|
import 'package:keyboard_actions/keyboard_actions.dart';
|
||||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:cake_wallet/view_model/send/send_view_model.dart';
|
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
|
||||||
import 'package:cake_wallet/src/widgets/address_text_field.dart';
|
import 'package:cake_wallet/src/widgets/address_text_field.dart';
|
||||||
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
||||||
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
||||||
|
@ -14,9 +13,11 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||||
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
||||||
|
|
||||||
class SendTemplatePage extends BasePage {
|
class SendTemplatePage extends BasePage {
|
||||||
SendTemplatePage({@required this.sendViewModel});
|
SendTemplatePage({@required this.sendTemplateViewModel}) {
|
||||||
|
sendTemplateViewModel.sendItem.reset();
|
||||||
|
}
|
||||||
|
|
||||||
final SendViewModel sendViewModel;
|
final SendTemplateViewModel sendTemplateViewModel;
|
||||||
final _addressController = TextEditingController();
|
final _addressController = TextEditingController();
|
||||||
final _cryptoAmountController = TextEditingController();
|
final _cryptoAmountController = TextEditingController();
|
||||||
final _fiatAmountController = TextEditingController();
|
final _fiatAmountController = TextEditingController();
|
||||||
|
@ -100,7 +101,7 @@ class SendTemplatePage extends BasePage {
|
||||||
.decorationColor,
|
.decorationColor,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
fontSize: 14),
|
fontSize: 14),
|
||||||
validator: sendViewModel.templateValidator,
|
validator: sendTemplateViewModel.templateValidator,
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 20),
|
padding: EdgeInsets.only(top: 20),
|
||||||
|
@ -145,49 +146,49 @@ class SendTemplatePage extends BasePage {
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
.headline
|
.headline
|
||||||
.decorationColor),
|
.decorationColor),
|
||||||
validator: sendViewModel.addressValidator,
|
validator: sendTemplateViewModel.addressValidator,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Observer(builder: (_) {
|
Padding(
|
||||||
return Padding(
|
padding: const EdgeInsets.only(top: 20),
|
||||||
padding: const EdgeInsets.only(top: 20),
|
child: BaseTextFormField(
|
||||||
child: BaseTextFormField(
|
focusNode: _cryptoAmountFocus,
|
||||||
focusNode: _cryptoAmountFocus,
|
controller: _cryptoAmountController,
|
||||||
controller: _cryptoAmountController,
|
keyboardType: TextInputType.numberWithOptions(
|
||||||
keyboardType: TextInputType.numberWithOptions(
|
signed: false, decimal: true),
|
||||||
signed: false, decimal: true),
|
inputFormatters: [
|
||||||
inputFormatters: [
|
BlacklistingTextInputFormatter(
|
||||||
BlacklistingTextInputFormatter(
|
RegExp('[\\-|\\ ]'))
|
||||||
RegExp('[\\-|\\ ]'))
|
],
|
||||||
],
|
prefixIcon: Padding(
|
||||||
prefixIcon: Padding(
|
padding: EdgeInsets.only(top: 9),
|
||||||
padding: EdgeInsets.only(top: 9),
|
child:
|
||||||
child:
|
Text(sendTemplateViewModel
|
||||||
Text(sendViewModel.currency.title + ':',
|
.currency.title + ':',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
hintText: '0.0000',
|
hintText: '0.0000',
|
||||||
borderColor: Theme.of(context)
|
borderColor: Theme.of(context)
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
.headline
|
.headline
|
||||||
.color,
|
.color,
|
||||||
textStyle: TextStyle(
|
textStyle: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
color: Colors.white),
|
color: Colors.white),
|
||||||
placeholderTextStyle: TextStyle(
|
placeholderTextStyle: TextStyle(
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
.headline
|
.headline
|
||||||
.decorationColor,
|
.decorationColor,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
fontSize: 14),
|
fontSize: 14),
|
||||||
validator: sendViewModel.amountValidator));
|
validator: sendTemplateViewModel
|
||||||
}),
|
.amountValidator)),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 20),
|
padding: const EdgeInsets.only(top: 20),
|
||||||
child: BaseTextFormField(
|
child: BaseTextFormField(
|
||||||
|
@ -201,7 +202,8 @@ class SendTemplatePage extends BasePage {
|
||||||
],
|
],
|
||||||
prefixIcon: Padding(
|
prefixIcon: Padding(
|
||||||
padding: EdgeInsets.only(top: 9),
|
padding: EdgeInsets.only(top: 9),
|
||||||
child: Text(sendViewModel.fiat.title + ':',
|
child: Text(sendTemplateViewModel
|
||||||
|
.fiat.title + ':',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
|
@ -236,12 +238,11 @@ class SendTemplatePage extends BasePage {
|
||||||
bottomSection: PrimaryButton(
|
bottomSection: PrimaryButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_formKey.currentState.validate()) {
|
if (_formKey.currentState.validate()) {
|
||||||
sendViewModel.addTemplate(
|
sendTemplateViewModel.addTemplate(
|
||||||
name: _nameController.text,
|
name: _nameController.text,
|
||||||
address: _addressController.text,
|
address: _addressController.text,
|
||||||
cryptoCurrency: sendViewModel.currency.title,
|
cryptoCurrency: sendTemplateViewModel.currency.title,
|
||||||
amount: _cryptoAmountController.text);
|
amount: _cryptoAmountController.text);
|
||||||
sendViewModel.updateTemplate();
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -258,19 +259,21 @@ class SendTemplatePage extends BasePage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reaction((_) => sendViewModel.fiatAmount, (String amount) {
|
final item = sendTemplateViewModel.sendItem;
|
||||||
|
|
||||||
|
reaction((_) => item.fiatAmount, (String amount) {
|
||||||
if (amount != _fiatAmountController.text) {
|
if (amount != _fiatAmountController.text) {
|
||||||
_fiatAmountController.text = amount;
|
_fiatAmountController.text = amount;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reaction((_) => sendViewModel.cryptoAmount, (String amount) {
|
reaction((_) => item.cryptoAmount, (String amount) {
|
||||||
if (amount != _cryptoAmountController.text) {
|
if (amount != _cryptoAmountController.text) {
|
||||||
_cryptoAmountController.text = amount;
|
_cryptoAmountController.text = amount;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reaction((_) => sendViewModel.address, (String address) {
|
reaction((_) => item.address, (String address) {
|
||||||
if (address != _addressController.text) {
|
if (address != _addressController.text) {
|
||||||
_addressController.text = address;
|
_addressController.text = address;
|
||||||
}
|
}
|
||||||
|
@ -279,24 +282,24 @@ class SendTemplatePage extends BasePage {
|
||||||
_cryptoAmountController.addListener(() {
|
_cryptoAmountController.addListener(() {
|
||||||
final amount = _cryptoAmountController.text;
|
final amount = _cryptoAmountController.text;
|
||||||
|
|
||||||
if (amount != sendViewModel.cryptoAmount) {
|
if (amount != item.cryptoAmount) {
|
||||||
sendViewModel.setCryptoAmount(amount);
|
item.setCryptoAmount(amount);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_fiatAmountController.addListener(() {
|
_fiatAmountController.addListener(() {
|
||||||
final amount = _fiatAmountController.text;
|
final amount = _fiatAmountController.text;
|
||||||
|
|
||||||
if (amount != sendViewModel.fiatAmount) {
|
if (amount != item.fiatAmount) {
|
||||||
sendViewModel.setFiatAmount(amount);
|
item.setFiatAmount(amount);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_addressController.addListener(() {
|
_addressController.addListener(() {
|
||||||
final address = _addressController.text;
|
final address = _addressController.text;
|
||||||
|
|
||||||
if (sendViewModel.address != address) {
|
if (item.address != address) {
|
||||||
sendViewModel.address = address;
|
item.address = address;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||||
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
|
||||||
|
void showAddressAlert(BuildContext context, String title, String content) async {
|
||||||
|
await showPopUp<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
|
||||||
|
return AlertWithOneAction(
|
||||||
|
alertTitle: title,
|
||||||
|
alertContent: content,
|
||||||
|
buttonText: S.of(context).ok,
|
||||||
|
buttonAction: () => Navigator.of(context).pop());
|
||||||
|
});
|
||||||
|
}
|
521
lib/src/screens/send/widgets/send_card.dart
Normal file
521
lib/src/screens/send/widgets/send_card.dart
Normal file
|
@ -0,0 +1,521 @@
|
||||||
|
import 'dart:ui';
|
||||||
|
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||||
|
import 'package:cake_wallet/src/screens/send/widgets/parse_address_from_domain_alert.dart';
|
||||||
|
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
||||||
|
import 'package:cake_wallet/src/widgets/picker.dart';
|
||||||
|
import 'package:cake_wallet/view_model/send/send_item.dart';
|
||||||
|
import 'package:cake_wallet/view_model/settings/settings_view_model.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:keyboard_actions/keyboard_actions.dart';
|
||||||
|
import 'package:cake_wallet/view_model/send/send_view_model.dart';
|
||||||
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
|
import 'package:cake_wallet/src/widgets/address_text_field.dart';
|
||||||
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
||||||
|
|
||||||
|
class SendCard extends StatefulWidget {
|
||||||
|
SendCard({Key key, @required this.item, @required this.sendViewModel}) : super(key: key);
|
||||||
|
|
||||||
|
final SendItem item;
|
||||||
|
final SendViewModel sendViewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
SendCardState createState() => SendCardState(
|
||||||
|
item: item,
|
||||||
|
sendViewModel: sendViewModel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SendCardState extends State<SendCard>
|
||||||
|
with AutomaticKeepAliveClientMixin<SendCard> {
|
||||||
|
SendCardState({@required this.item, @required this.sendViewModel})
|
||||||
|
: addressController = TextEditingController(),
|
||||||
|
cryptoAmountController = TextEditingController(),
|
||||||
|
fiatAmountController = TextEditingController(),
|
||||||
|
noteController = TextEditingController(),
|
||||||
|
cryptoAmountFocus = FocusNode(),
|
||||||
|
fiatAmountFocus = FocusNode(),
|
||||||
|
addressFocusNode = FocusNode();
|
||||||
|
|
||||||
|
static const prefixIconWidth = 34.0;
|
||||||
|
static const prefixIconHeight = 34.0;
|
||||||
|
|
||||||
|
final SendItem item;
|
||||||
|
final SendViewModel sendViewModel;
|
||||||
|
|
||||||
|
final TextEditingController addressController;
|
||||||
|
final TextEditingController cryptoAmountController;
|
||||||
|
final TextEditingController fiatAmountController;
|
||||||
|
final TextEditingController noteController;
|
||||||
|
final FocusNode cryptoAmountFocus;
|
||||||
|
final FocusNode fiatAmountFocus;
|
||||||
|
final FocusNode addressFocusNode;
|
||||||
|
|
||||||
|
bool _effectsInstalled = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
|
_setEffects(context);
|
||||||
|
|
||||||
|
return KeyboardActions(
|
||||||
|
config: KeyboardActionsConfig(
|
||||||
|
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
|
||||||
|
keyboardBarColor: Theme.of(context).accentTextTheme.body2
|
||||||
|
.backgroundColor,
|
||||||
|
nextFocus: false,
|
||||||
|
actions: [
|
||||||
|
KeyboardActionsItem(
|
||||||
|
focusNode: cryptoAmountFocus,
|
||||||
|
toolbarButtons: [(_) => KeyboardDoneButton()],
|
||||||
|
),
|
||||||
|
KeyboardActionsItem(
|
||||||
|
focusNode: fiatAmountFocus,
|
||||||
|
toolbarButtons: [(_) => KeyboardDoneButton()],
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
child: Container(
|
||||||
|
height: 445,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.only(
|
||||||
|
bottomLeft: Radius.circular(24),
|
||||||
|
bottomRight: Radius.circular(24)),
|
||||||
|
gradient: LinearGradient(colors: [
|
||||||
|
Theme.of(context).primaryTextTheme.subhead.color,
|
||||||
|
Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.subhead
|
||||||
|
.decorationColor,
|
||||||
|
], begin: Alignment.topLeft, end: Alignment.bottomRight),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(24, 80, 24, 32),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
AddressTextField(
|
||||||
|
focusNode: addressFocusNode,
|
||||||
|
controller: addressController,
|
||||||
|
onURIScanned: (uri) {
|
||||||
|
var address = '';
|
||||||
|
var amount = '';
|
||||||
|
|
||||||
|
if (uri != null) {
|
||||||
|
address = uri.path;
|
||||||
|
amount = uri.queryParameters['tx_amount'] ??
|
||||||
|
uri.queryParameters['amount'];
|
||||||
|
} else {
|
||||||
|
address = uri.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
addressController.text = address;
|
||||||
|
cryptoAmountController.text = amount;
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
AddressTextFieldOption.paste,
|
||||||
|
AddressTextFieldOption.qrCode,
|
||||||
|
AddressTextFieldOption.addressBook
|
||||||
|
],
|
||||||
|
buttonColor: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.display1
|
||||||
|
.color,
|
||||||
|
borderColor: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.color,
|
||||||
|
textStyle: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Colors.white),
|
||||||
|
hintStyle: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.decorationColor),
|
||||||
|
validator: sendViewModel.addressValidator,
|
||||||
|
),
|
||||||
|
Observer(
|
||||||
|
builder: (_) => Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 20),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
BaseTextFormField(
|
||||||
|
focusNode: cryptoAmountFocus,
|
||||||
|
controller: cryptoAmountController,
|
||||||
|
keyboardType:
|
||||||
|
TextInputType.numberWithOptions(
|
||||||
|
signed: false, decimal: true),
|
||||||
|
prefixIcon: Padding(
|
||||||
|
padding: EdgeInsets.only(top: 9),
|
||||||
|
child: Text(
|
||||||
|
sendViewModel.currency.title +
|
||||||
|
':',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.white,
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
suffixIcon: SizedBox(
|
||||||
|
width: prefixIconWidth,
|
||||||
|
),
|
||||||
|
hintText: '0.0000',
|
||||||
|
borderColor: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.color,
|
||||||
|
textStyle: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Colors.white),
|
||||||
|
placeholderTextStyle: TextStyle(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.decorationColor,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontSize: 14),
|
||||||
|
validator: item.sendAll
|
||||||
|
? sendViewModel.allAmountValidator
|
||||||
|
: sendViewModel
|
||||||
|
.amountValidator),
|
||||||
|
Positioned(
|
||||||
|
top: 2,
|
||||||
|
right: 0,
|
||||||
|
child: Container(
|
||||||
|
width: prefixIconWidth,
|
||||||
|
height: prefixIconHeight,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () async =>
|
||||||
|
item.setSendAll(),
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.display1
|
||||||
|
.color,
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.all(
|
||||||
|
Radius.circular(6))),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
S.of(context).all,
|
||||||
|
textAlign:
|
||||||
|
TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight:
|
||||||
|
FontWeight.bold,
|
||||||
|
color:
|
||||||
|
Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.display1
|
||||||
|
.decorationColor))),
|
||||||
|
))))])
|
||||||
|
)),
|
||||||
|
Observer(
|
||||||
|
builder: (_) => Padding(
|
||||||
|
padding: EdgeInsets.only(top: 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
S.of(context).available_balance +
|
||||||
|
':',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.decorationColor),
|
||||||
|
)),
|
||||||
|
Text(
|
||||||
|
sendViewModel.balance,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.decorationColor),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 20),
|
||||||
|
child: BaseTextFormField(
|
||||||
|
focusNode: fiatAmountFocus,
|
||||||
|
controller: fiatAmountController,
|
||||||
|
keyboardType:
|
||||||
|
TextInputType.numberWithOptions(
|
||||||
|
signed: false, decimal: true),
|
||||||
|
prefixIcon: Padding(
|
||||||
|
padding: EdgeInsets.only(top: 9),
|
||||||
|
child:
|
||||||
|
Text(sendViewModel.fiat.title + ':',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.white,
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
hintText: '0.00',
|
||||||
|
borderColor: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.color,
|
||||||
|
textStyle: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Colors.white),
|
||||||
|
placeholderTextStyle: TextStyle(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.decorationColor,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontSize: 14),
|
||||||
|
)),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(top: 20),
|
||||||
|
child: BaseTextFormField(
|
||||||
|
controller: noteController,
|
||||||
|
keyboardType: TextInputType.multiline,
|
||||||
|
maxLines: null,
|
||||||
|
borderColor: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.color,
|
||||||
|
textStyle: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Colors.white),
|
||||||
|
hintText: S.of(context).note_optional,
|
||||||
|
placeholderTextStyle: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.decorationColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Observer(
|
||||||
|
builder: (_) => GestureDetector(
|
||||||
|
onTap: () =>
|
||||||
|
_setTransactionPriority(context),
|
||||||
|
child: Container(
|
||||||
|
padding: EdgeInsets.only(top: 24),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(
|
||||||
|
S
|
||||||
|
.of(context)
|
||||||
|
.send_estimated_fee,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight:
|
||||||
|
FontWeight.w500,
|
||||||
|
//color: Theme.of(context).primaryTextTheme.display2.color,
|
||||||
|
color: Colors.white)),
|
||||||
|
Container(
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
item
|
||||||
|
.estimatedFee
|
||||||
|
.toString() +
|
||||||
|
' ' +
|
||||||
|
sendViewModel
|
||||||
|
.currency.title,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight:
|
||||||
|
FontWeight.w600,
|
||||||
|
//color: Theme.of(context).primaryTextTheme.display2.color,
|
||||||
|
color:
|
||||||
|
Colors.white)),
|
||||||
|
Padding(
|
||||||
|
padding:
|
||||||
|
EdgeInsets.only(top: 5),
|
||||||
|
child: Text(
|
||||||
|
item
|
||||||
|
.estimatedFeeFiatAmount
|
||||||
|
+ ' ' +
|
||||||
|
sendViewModel
|
||||||
|
.fiat.title,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight:
|
||||||
|
FontWeight.w600,
|
||||||
|
color: Theme
|
||||||
|
.of(context)
|
||||||
|
.primaryTextTheme
|
||||||
|
.headline
|
||||||
|
.decorationColor))
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
top: 2,
|
||||||
|
left: 5),
|
||||||
|
child: Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
size: 12,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setEffects(BuildContext context) {
|
||||||
|
addressController.text = item.address;
|
||||||
|
cryptoAmountController.text = item.cryptoAmount;
|
||||||
|
fiatAmountController.text = item.fiatAmount;
|
||||||
|
noteController.text = item.note;
|
||||||
|
|
||||||
|
if (_effectsInstalled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cryptoAmountController.addListener(() {
|
||||||
|
final amount = cryptoAmountController.text;
|
||||||
|
|
||||||
|
if (item.sendAll && amount != S.current.all) {
|
||||||
|
item.sendAll = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount != item.cryptoAmount) {
|
||||||
|
item.setCryptoAmount(amount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fiatAmountController.addListener(() {
|
||||||
|
final amount = fiatAmountController.text;
|
||||||
|
|
||||||
|
if (amount != item.fiatAmount) {
|
||||||
|
item.sendAll = false;
|
||||||
|
item.setFiatAmount(amount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
noteController.addListener(() {
|
||||||
|
final note = noteController.text ?? '';
|
||||||
|
|
||||||
|
if (note != item.note) {
|
||||||
|
item.note = note;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reaction((_) => item.sendAll, (bool all) {
|
||||||
|
if (all) {
|
||||||
|
cryptoAmountController.text = S.current.all;
|
||||||
|
fiatAmountController.text = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reaction((_) => item.fiatAmount, (String amount) {
|
||||||
|
if (amount != fiatAmountController.text) {
|
||||||
|
fiatAmountController.text = amount;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reaction((_) => item.cryptoAmount, (String amount) {
|
||||||
|
if (item.sendAll && amount != S.current.all) {
|
||||||
|
item.sendAll = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount != cryptoAmountController.text) {
|
||||||
|
cryptoAmountController.text = amount;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reaction((_) => item.address, (String address) {
|
||||||
|
if (address != addressController.text) {
|
||||||
|
addressController.text = address;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addressController.addListener(() {
|
||||||
|
final address = addressController.text;
|
||||||
|
|
||||||
|
if (item.address != address) {
|
||||||
|
item.address = address;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reaction((_) => item.note, (String note) {
|
||||||
|
if (note != noteController.text) {
|
||||||
|
noteController.text = note;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addressFocusNode.addListener(() async {
|
||||||
|
if (!addressFocusNode.hasFocus && addressController.text.isNotEmpty) {
|
||||||
|
final record = await item.getOpenaliasRecord();
|
||||||
|
|
||||||
|
if (record != null) {
|
||||||
|
showAddressAlert(
|
||||||
|
context,
|
||||||
|
S.current.openalias_alert_title,
|
||||||
|
S.current.openalias_alert_content(record.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
_effectsInstalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _setTransactionPriority(BuildContext context) async {
|
||||||
|
final items = priorityForWalletType(sendViewModel.walletType);
|
||||||
|
final selectedItem = items.indexOf(sendViewModel.transactionPriority);
|
||||||
|
|
||||||
|
await showPopUp<void>(
|
||||||
|
builder: (_) => Picker(
|
||||||
|
items: items,
|
||||||
|
displayItem: sendViewModel.displayFeeRate,
|
||||||
|
selectedAtIndex: selectedItem,
|
||||||
|
title: S.of(context).please_select,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
onItemSelected: (TransactionPriority priority) =>
|
||||||
|
sendViewModel.setTransactionPriority(priority),
|
||||||
|
),
|
||||||
|
context: context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
|
}
|
|
@ -105,10 +105,12 @@ class BrightTheme extends ThemeBase {
|
||||||
),
|
),
|
||||||
display2: TextStyle(
|
display2: TextStyle(
|
||||||
color: Colors.white.withOpacity(0.5), // estimated fee (send page)
|
color: Colors.white.withOpacity(0.5), // estimated fee (send page)
|
||||||
|
backgroundColor: PaletteDark.darkCyanBlue.withOpacity(0.67), // dot color for indicator on send page
|
||||||
decorationColor: Palette.shadowWhite // template dotted border (send page)
|
decorationColor: Palette.shadowWhite // template dotted border (send page)
|
||||||
),
|
),
|
||||||
display3: TextStyle(
|
display3: TextStyle(
|
||||||
color: Palette.darkBlueCraiola, // template new text (send page)
|
color: Palette.darkBlueCraiola, // template new text (send page)
|
||||||
|
backgroundColor: PaletteDark.darkNightBlue, // active dot color for indicator on send page
|
||||||
decorationColor: Palette.shadowWhite // template background color (send page)
|
decorationColor: Palette.shadowWhite // template background color (send page)
|
||||||
),
|
),
|
||||||
display4: TextStyle(
|
display4: TextStyle(
|
||||||
|
|
|
@ -104,10 +104,12 @@ class DarkTheme extends ThemeBase {
|
||||||
),
|
),
|
||||||
display2: TextStyle(
|
display2: TextStyle(
|
||||||
color: Colors.white, // estimated fee (send page)
|
color: Colors.white, // estimated fee (send page)
|
||||||
|
backgroundColor: PaletteDark.cyanBlue, // dot color for indicator on send page
|
||||||
decorationColor: PaletteDark.darkCyanBlue // template dotted border (send page)
|
decorationColor: PaletteDark.darkCyanBlue // template dotted border (send page)
|
||||||
),
|
),
|
||||||
display3: TextStyle(
|
display3: TextStyle(
|
||||||
color: PaletteDark.darkCyanBlue, // template new text (send page)
|
color: PaletteDark.darkCyanBlue, // template new text (send page)
|
||||||
|
backgroundColor: Colors.white, // active dot color for indicator on send page
|
||||||
decorationColor: PaletteDark.darkVioletBlue // template background color (send page)
|
decorationColor: PaletteDark.darkVioletBlue // template background color (send page)
|
||||||
),
|
),
|
||||||
display4: TextStyle(
|
display4: TextStyle(
|
||||||
|
|
|
@ -105,10 +105,12 @@ class LightTheme extends ThemeBase {
|
||||||
),
|
),
|
||||||
display2: TextStyle(
|
display2: TextStyle(
|
||||||
color: Colors.white.withOpacity(0.5), // estimated fee (send page)
|
color: Colors.white.withOpacity(0.5), // estimated fee (send page)
|
||||||
|
backgroundColor: PaletteDark.darkCyanBlue.withOpacity(0.67), // dot color for indicator on send page
|
||||||
decorationColor: Palette.moderateLavender // template dotted border (send page)
|
decorationColor: Palette.moderateLavender // template dotted border (send page)
|
||||||
),
|
),
|
||||||
display3: TextStyle(
|
display3: TextStyle(
|
||||||
color: Palette.darkBlueCraiola, // template new text (send page)
|
color: Palette.darkBlueCraiola, // template new text (send page)
|
||||||
|
backgroundColor: PaletteDark.darkNightBlue, // active dot color for indicator on send page
|
||||||
decorationColor: Palette.blueAlice // template background color (send page)
|
decorationColor: Palette.blueAlice // template background color (send page)
|
||||||
),
|
),
|
||||||
display4: TextStyle(
|
display4: TextStyle(
|
||||||
|
|
|
@ -79,8 +79,11 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendViewModel.address = trade.inputAddress;
|
sendViewModel.clearSendItemList();
|
||||||
sendViewModel.setCryptoAmount(trade.amount);
|
final item = sendViewModel.sendItemList.first;
|
||||||
|
|
||||||
|
item.address = trade.inputAddress;
|
||||||
|
item.setCryptoAmount(trade.amount);
|
||||||
await sendViewModel.createTransaction();
|
await sendViewModel.createTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
198
lib/view_model/send/send_item.dart
Normal file
198
lib/view_model/send/send_item.dart
Normal file
|
@ -0,0 +1,198 @@
|
||||||
|
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
||||||
|
import 'package:cake_wallet/bitcoin/electrum_wallet.dart';
|
||||||
|
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||||
|
import 'package:cake_wallet/entities/openalias_record.dart';
|
||||||
|
import 'package:cake_wallet/monero/monero_amount_format.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
import 'package:cake_wallet/core/wallet_base.dart';
|
||||||
|
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||||
|
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||||
|
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
|
||||||
|
part 'send_item.g.dart';
|
||||||
|
|
||||||
|
const String cryptoNumberPattern = '0.0';
|
||||||
|
|
||||||
|
class SendItem = SendItemBase with _$SendItem;
|
||||||
|
|
||||||
|
abstract class SendItemBase with Store {
|
||||||
|
SendItemBase(this._wallet, this._settingsStore, this._fiatConversationStore)
|
||||||
|
:_cryptoNumberFormat = NumberFormat(cryptoNumberPattern) {
|
||||||
|
reset();
|
||||||
|
_setCryptoNumMaximumFractionDigits();
|
||||||
|
key = UniqueKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
Key key;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
String fiatAmount;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
String cryptoAmount;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
String address;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
String note;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
bool sendAll;
|
||||||
|
|
||||||
|
@computed
|
||||||
|
double get estimatedFee {
|
||||||
|
int amount;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (cryptoAmount?.isNotEmpty ?? false) {
|
||||||
|
final _cryptoAmount = cryptoAmount.replaceAll(',', '.');
|
||||||
|
int _amount = 0;
|
||||||
|
switch (walletType) {
|
||||||
|
case WalletType.monero:
|
||||||
|
_amount = moneroParseAmount(amount: _cryptoAmount);
|
||||||
|
break;
|
||||||
|
case WalletType.bitcoin:
|
||||||
|
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
|
||||||
|
break;
|
||||||
|
case WalletType.litecoin:
|
||||||
|
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_amount > 0) {
|
||||||
|
amount = _amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final fee = _wallet.calculateEstimatedFee(
|
||||||
|
_settingsStore.priority[_wallet.type], amount);
|
||||||
|
|
||||||
|
if (_wallet is ElectrumWallet) {
|
||||||
|
return bitcoinAmountToDouble(amount: fee);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wallet is MoneroWallet) {
|
||||||
|
return moneroAmountToDouble(amount: fee);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed
|
||||||
|
String get estimatedFeeFiatAmount {
|
||||||
|
try {
|
||||||
|
final fiat = calculateFiatAmountRaw(
|
||||||
|
price: _fiatConversationStore.prices[_wallet.currency],
|
||||||
|
cryptoAmount: estimatedFee);
|
||||||
|
return fiat;
|
||||||
|
} catch (_) {
|
||||||
|
return '0.00';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WalletType get walletType => _wallet.type;
|
||||||
|
final WalletBase _wallet;
|
||||||
|
final SettingsStore _settingsStore;
|
||||||
|
final FiatConversionStore _fiatConversationStore;
|
||||||
|
final NumberFormat _cryptoNumberFormat;
|
||||||
|
|
||||||
|
@action
|
||||||
|
void setSendAll() => sendAll = true;
|
||||||
|
|
||||||
|
@action
|
||||||
|
void reset() {
|
||||||
|
sendAll = false;
|
||||||
|
cryptoAmount = '';
|
||||||
|
fiatAmount = '';
|
||||||
|
address = '';
|
||||||
|
note = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
void setCryptoAmount(String amount) {
|
||||||
|
if (amount.toUpperCase() != S.current.all) {
|
||||||
|
sendAll = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cryptoAmount = amount;
|
||||||
|
_updateFiatAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
void setFiatAmount(String amount) {
|
||||||
|
fiatAmount = amount;
|
||||||
|
_updateCryptoAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
void _updateFiatAmount() {
|
||||||
|
try {
|
||||||
|
final fiat = calculateFiatAmount(
|
||||||
|
price: _fiatConversationStore.prices[_wallet.currency],
|
||||||
|
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
|
||||||
|
if (fiatAmount != fiat) {
|
||||||
|
fiatAmount = fiat;
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
fiatAmount = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
void _updateCryptoAmount() {
|
||||||
|
try {
|
||||||
|
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
|
||||||
|
_fiatConversationStore.prices[_wallet.currency];
|
||||||
|
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
|
||||||
|
|
||||||
|
if (cryptoAmount != cryptoAmountTmp) {
|
||||||
|
cryptoAmount = cryptoAmountTmp;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
cryptoAmount = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setCryptoNumMaximumFractionDigits() {
|
||||||
|
var maximumFractionDigits = 0;
|
||||||
|
|
||||||
|
switch (_wallet.type) {
|
||||||
|
case WalletType.monero:
|
||||||
|
maximumFractionDigits = 12;
|
||||||
|
break;
|
||||||
|
case WalletType.bitcoin:
|
||||||
|
maximumFractionDigits = 8;
|
||||||
|
break;
|
||||||
|
case WalletType.litecoin:
|
||||||
|
maximumFractionDigits = 8;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_cryptoNumberFormat.maximumFractionDigits = maximumFractionDigits;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<OpenaliasRecord> getOpenaliasRecord() async {
|
||||||
|
final formattedName = OpenaliasRecord.formatDomainName(address);
|
||||||
|
final record = await OpenaliasRecord.fetchAddressAndName(formattedName);
|
||||||
|
|
||||||
|
if (record == null || record.address.contains(formattedName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
address = record.address;
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
}
|
66
lib/view_model/send/send_template_view_model.dart
Normal file
66
lib/view_model/send/send_template_view_model.dart
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import 'package:cake_wallet/view_model/send/send_item.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
import 'package:cake_wallet/entities/template.dart';
|
||||||
|
import 'package:cake_wallet/store/templates/send_template_store.dart';
|
||||||
|
import 'package:cake_wallet/core/template_validator.dart';
|
||||||
|
import 'package:cake_wallet/core/address_validator.dart';
|
||||||
|
import 'package:cake_wallet/core/amount_validator.dart';
|
||||||
|
import 'package:cake_wallet/core/validator.dart';
|
||||||
|
import 'package:cake_wallet/core/wallet_base.dart';
|
||||||
|
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||||
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
|
|
||||||
|
part 'send_template_view_model.g.dart';
|
||||||
|
|
||||||
|
class SendTemplateViewModel = SendTemplateViewModelBase
|
||||||
|
with _$SendTemplateViewModel;
|
||||||
|
|
||||||
|
abstract class SendTemplateViewModelBase with Store {
|
||||||
|
SendTemplateViewModelBase(this._wallet, this._settingsStore,
|
||||||
|
this._sendTemplateStore, this._fiatConversationStore) {
|
||||||
|
|
||||||
|
sendItem = SendItem(_wallet, _settingsStore, _fiatConversationStore);
|
||||||
|
}
|
||||||
|
|
||||||
|
SendItem sendItem;
|
||||||
|
|
||||||
|
Validator get amountValidator => AmountValidator(type: _wallet.type);
|
||||||
|
|
||||||
|
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
||||||
|
|
||||||
|
Validator get templateValidator => TemplateValidator();
|
||||||
|
|
||||||
|
CryptoCurrency get currency => _wallet.currency;
|
||||||
|
|
||||||
|
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
||||||
|
|
||||||
|
@computed
|
||||||
|
ObservableList<Template> get templates => _sendTemplateStore.templates;
|
||||||
|
|
||||||
|
final WalletBase _wallet;
|
||||||
|
final SettingsStore _settingsStore;
|
||||||
|
final SendTemplateStore _sendTemplateStore;
|
||||||
|
final FiatConversionStore _fiatConversationStore;
|
||||||
|
|
||||||
|
void updateTemplate() => _sendTemplateStore.update();
|
||||||
|
|
||||||
|
void addTemplate(
|
||||||
|
{String name,
|
||||||
|
String address,
|
||||||
|
String cryptoCurrency,
|
||||||
|
String amount}) {
|
||||||
|
_sendTemplateStore.addTemplate(
|
||||||
|
name: name,
|
||||||
|
address: address,
|
||||||
|
cryptoCurrency: cryptoCurrency,
|
||||||
|
amount: amount);
|
||||||
|
updateTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeTemplate({Template template}) {
|
||||||
|
_sendTemplateStore.remove(template: template);
|
||||||
|
updateTemplate();
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||||
import 'package:cake_wallet/monero/monero_amount_format.dart';
|
import 'package:cake_wallet/monero/monero_amount_format.dart';
|
||||||
|
import 'package:cake_wallet/view_model/send/send_item.dart';
|
||||||
|
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
|
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
@ -37,17 +39,13 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
|
||||||
part 'send_view_model.g.dart';
|
part 'send_view_model.g.dart';
|
||||||
|
|
||||||
const String cryptoNumberPattern = '0.0';
|
|
||||||
|
|
||||||
class SendViewModel = SendViewModelBase with _$SendViewModel;
|
class SendViewModel = SendViewModelBase with _$SendViewModel;
|
||||||
|
|
||||||
abstract class SendViewModelBase with Store {
|
abstract class SendViewModelBase with Store {
|
||||||
SendViewModelBase(this._wallet, this._settingsStore, this._sendTemplateStore,
|
SendViewModelBase(this._wallet, this._settingsStore,
|
||||||
this._fiatConversationStore, this.transactionDescriptionBox)
|
this.sendTemplateViewModel, this._fiatConversationStore,
|
||||||
: state = InitialExecutionState(),
|
this.transactionDescriptionBox)
|
||||||
_cryptoNumberFormat = NumberFormat(cryptoNumberPattern),
|
: state = InitialExecutionState() {
|
||||||
note = '',
|
|
||||||
sendAll = false {
|
|
||||||
final priority = _settingsStore.priority[_wallet.type];
|
final priority = _settingsStore.priority[_wallet.type];
|
||||||
final priorities = priorityForWalletType(_wallet.type);
|
final priorities = priorityForWalletType(_wallet.type);
|
||||||
|
|
||||||
|
@ -55,82 +53,33 @@ abstract class SendViewModelBase with Store {
|
||||||
_settingsStore.priority[_wallet.type] = priorities.first;
|
_settingsStore.priority[_wallet.type] = priorities.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setCryptoNumMaximumFractionDigits();
|
sendItemList = ObservableList<SendItem>()
|
||||||
|
..add(SendItem(_wallet, _settingsStore, _fiatConversationStore));
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
ExecutionState state;
|
ExecutionState state;
|
||||||
|
|
||||||
@observable
|
ObservableList<SendItem> sendItemList;
|
||||||
String fiatAmount;
|
|
||||||
|
|
||||||
@observable
|
@action
|
||||||
String cryptoAmount;
|
void addSendItem() {
|
||||||
|
sendItemList.add(SendItem(_wallet, _settingsStore, _fiatConversationStore));
|
||||||
|
}
|
||||||
|
|
||||||
@observable
|
@action
|
||||||
String address;
|
void removeSendItem(SendItem item) {
|
||||||
|
sendItemList.remove(item);
|
||||||
|
}
|
||||||
|
|
||||||
@observable
|
@action
|
||||||
String note;
|
void clearSendItemList() {
|
||||||
|
sendItemList.clear();
|
||||||
@observable
|
addSendItem();
|
||||||
bool sendAll;
|
|
||||||
|
|
||||||
@computed
|
|
||||||
double get estimatedFee {
|
|
||||||
int amount;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (cryptoAmount?.isNotEmpty ?? false) {
|
|
||||||
final _cryptoAmount = cryptoAmount.replaceAll(',', '.');
|
|
||||||
int _amount = 0;
|
|
||||||
switch (walletType) {
|
|
||||||
case WalletType.monero:
|
|
||||||
_amount = moneroParseAmount(amount: _cryptoAmount);
|
|
||||||
break;
|
|
||||||
case WalletType.bitcoin:
|
|
||||||
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
|
|
||||||
break;
|
|
||||||
case WalletType.litecoin:
|
|
||||||
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_amount > 0) {
|
|
||||||
amount = _amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final fee = _wallet.calculateEstimatedFee(
|
|
||||||
_settingsStore.priority[_wallet.type], amount);
|
|
||||||
|
|
||||||
if (_wallet is ElectrumWallet) {
|
|
||||||
return bitcoinAmountToDouble(amount: fee);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_wallet is MoneroWallet) {
|
|
||||||
return moneroAmountToDouble(amount: fee);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print(e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
String get estimatedFeeFiatAmount {
|
bool get isRemoveButtonShow => sendItemList.length > 1;
|
||||||
try {
|
|
||||||
final fiat = calculateFiatAmountRaw(
|
|
||||||
price: _fiatConversationStore.prices[_wallet.currency],
|
|
||||||
cryptoAmount: estimatedFee);
|
|
||||||
return fiat;
|
|
||||||
} catch (_) {
|
|
||||||
return '0.00';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
String get pendingTransactionFiatAmount {
|
String get pendingTransactionFiatAmount {
|
||||||
|
@ -177,8 +126,6 @@ abstract class SendViewModelBase with Store {
|
||||||
|
|
||||||
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
||||||
|
|
||||||
Validator get templateValidator => TemplateValidator();
|
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
PendingTransaction pendingTransaction;
|
PendingTransaction pendingTransaction;
|
||||||
|
|
||||||
|
@ -189,28 +136,15 @@ abstract class SendViewModelBase with Store {
|
||||||
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
|
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
ObservableList<Template> get templates => _sendTemplateStore.templates;
|
ObservableList<Template> get templates => sendTemplateViewModel.templates;
|
||||||
|
|
||||||
WalletType get walletType => _wallet.type;
|
WalletType get walletType => _wallet.type;
|
||||||
final WalletBase _wallet;
|
final WalletBase _wallet;
|
||||||
final SettingsStore _settingsStore;
|
final SettingsStore _settingsStore;
|
||||||
final SendTemplateStore _sendTemplateStore;
|
final SendTemplateViewModel sendTemplateViewModel;
|
||||||
final FiatConversionStore _fiatConversationStore;
|
final FiatConversionStore _fiatConversationStore;
|
||||||
final NumberFormat _cryptoNumberFormat;
|
|
||||||
final Box<TransactionDescription> transactionDescriptionBox;
|
final Box<TransactionDescription> transactionDescriptionBox;
|
||||||
|
|
||||||
@action
|
|
||||||
void setSendAll() => sendAll = true;
|
|
||||||
|
|
||||||
@action
|
|
||||||
void reset() {
|
|
||||||
sendAll = false;
|
|
||||||
cryptoAmount = '';
|
|
||||||
fiatAmount = '';
|
|
||||||
address = '';
|
|
||||||
note = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> createTransaction() async {
|
Future<void> createTransaction() async {
|
||||||
try {
|
try {
|
||||||
|
@ -224,6 +158,8 @@ abstract class SendViewModelBase with Store {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> commitTransaction() async {
|
Future<void> commitTransaction() async {
|
||||||
|
final address = ''; // FIXME: get it from item
|
||||||
|
final note = ''; // FIXME: get it from item
|
||||||
try {
|
try {
|
||||||
state = TransactionCommitting();
|
state = TransactionCommitting();
|
||||||
await pendingTransaction.commit();
|
await pendingTransaction.commit();
|
||||||
|
@ -244,64 +180,14 @@ abstract class SendViewModelBase with Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
void setCryptoAmount(String amount) {
|
|
||||||
if (amount.toUpperCase() != S.current.all) {
|
|
||||||
sendAll = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cryptoAmount = amount;
|
|
||||||
_updateFiatAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
void setFiatAmount(String amount) {
|
|
||||||
fiatAmount = amount;
|
|
||||||
_updateCryptoAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setTransactionPriority(TransactionPriority priority) =>
|
void setTransactionPriority(TransactionPriority priority) =>
|
||||||
_settingsStore.priority[_wallet.type] = priority;
|
_settingsStore.priority[_wallet.type] = priority;
|
||||||
|
|
||||||
Future<OpenaliasRecord> decodeOpenaliasRecord(String name) async {
|
|
||||||
final record = await OpenaliasRecord.fetchAddressAndName(
|
|
||||||
OpenaliasRecord.formatDomainName(name));
|
|
||||||
|
|
||||||
return record.name != name ? record : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
void _updateFiatAmount() {
|
|
||||||
try {
|
|
||||||
final fiat = calculateFiatAmount(
|
|
||||||
price: _fiatConversationStore.prices[_wallet.currency],
|
|
||||||
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
|
|
||||||
if (fiatAmount != fiat) {
|
|
||||||
fiatAmount = fiat;
|
|
||||||
}
|
|
||||||
} catch (_) {
|
|
||||||
fiatAmount = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
void _updateCryptoAmount() {
|
|
||||||
try {
|
|
||||||
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
|
|
||||||
_fiatConversationStore.prices[_wallet.currency];
|
|
||||||
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
|
|
||||||
|
|
||||||
if (cryptoAmount != cryptoAmountTmp) {
|
|
||||||
cryptoAmount = cryptoAmountTmp;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
cryptoAmount = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object _credentials() {
|
Object _credentials() {
|
||||||
final _amount = cryptoAmount.replaceAll(',', '.');
|
// FIXME: get it from item
|
||||||
|
return null;
|
||||||
|
/*final _amount = cryptoAmount.replaceAll(',', '.');
|
||||||
|
|
||||||
switch (_wallet.type) {
|
switch (_wallet.type) {
|
||||||
case WalletType.bitcoin:
|
case WalletType.bitcoin:
|
||||||
|
@ -327,45 +213,9 @@ abstract class SendViewModelBase with Store {
|
||||||
amount: amount);
|
amount: amount);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCryptoNumMaximumFractionDigits() {
|
|
||||||
var maximumFractionDigits = 0;
|
|
||||||
|
|
||||||
switch (_wallet.type) {
|
|
||||||
case WalletType.monero:
|
|
||||||
maximumFractionDigits = 12;
|
|
||||||
break;
|
|
||||||
case WalletType.bitcoin:
|
|
||||||
maximumFractionDigits = 8;
|
|
||||||
break;
|
|
||||||
case WalletType.litecoin:
|
|
||||||
maximumFractionDigits = 8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
_cryptoNumberFormat.maximumFractionDigits = maximumFractionDigits;
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateTemplate() => _sendTemplateStore.update();
|
|
||||||
|
|
||||||
void addTemplate(
|
|
||||||
{String name,
|
|
||||||
String address,
|
|
||||||
String cryptoCurrency,
|
|
||||||
String amount}) =>
|
|
||||||
_sendTemplateStore.addTemplate(
|
|
||||||
name: name,
|
|
||||||
address: address,
|
|
||||||
cryptoCurrency: cryptoCurrency,
|
|
||||||
amount: amount);
|
|
||||||
|
|
||||||
void removeTemplate({Template template}) =>
|
|
||||||
_sendTemplateStore.remove(template: template);
|
|
||||||
|
|
||||||
String displayFeeRate(dynamic priority) {
|
String displayFeeRate(dynamic priority) {
|
||||||
final _priority = priority as TransactionPriority;
|
final _priority = priority as TransactionPriority;
|
||||||
final wallet = _wallet;
|
final wallet = _wallet;
|
||||||
|
|
Loading…
Reference in a new issue