Merge redesign part 2.

This commit is contained in:
M 2020-09-02 11:47:41 +03:00
parent 2627945e00
commit 9074bee6db
6 changed files with 570 additions and 440 deletions

View file

@ -95,16 +95,26 @@ class SendPage extends BasePage {
// } // }
} }
@override
Widget body(BuildContext context) {
return super.build(context);
}
// @override // @override
// Widget build(BuildContext context) { // Widget body(BuildContext context) {
// return BaseSendWidget(sendViewModel: sendViewModel); // return super.build(context);
// } // }
@override
Widget body(BuildContext context) => BaseSendWidget(
sendViewModel: sendViewModel,
leading: leading(context),
middle: middle(context),
);
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
body: Container(
color: Theme.of(context).backgroundColor, child: body(context)));
}
// @override // @override
// Widget build(BuildContext context) { // Widget build(BuildContext context) {
// _setEffects(context); // _setEffects(context);

View file

@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.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_view_model.dart'; import 'package:cake_wallet/view_model/send/send_view_model.dart';
import 'package:cake_wallet/src/screens/send/widgets/base_send_widget.dart'; import 'package:cake_wallet/src/screens/send/widgets/base_send_widget.dart';
class SendTemplatePage extends BasePage { class SendTemplatePage extends BasePage {
@ -26,22 +26,17 @@ class SendTemplatePage extends BasePage {
bool get resizeToAvoidBottomPadding => false; bool get resizeToAvoidBottomPadding => false;
@override @override
Widget body(BuildContext context) => Widget body(BuildContext context) => BaseSendWidget(
BaseSendWidget(
sendViewModel: sendViewModel, sendViewModel: sendViewModel,
leading: leading(context), leading: leading(context),
middle: middle(context), middle: middle(context),
isTemplate: true isTemplate: true);
);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding, resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
body: Container( body: Container(
color: Theme.of(context).backgroundColor, color: Theme.of(context).backgroundColor, child: body(context)));
child: body(context)
)
);
} }
} }

View file

@ -1,10 +1,12 @@
import 'dart:ui';
import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
import 'package:cake_wallet/src/widgets/picker.dart'; import 'package:cake_wallet/src/widgets/picker.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart'; 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';
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cake_wallet/view_model/send_view_model.dart'; import 'package:cake_wallet/view_model/send/send_view_model.dart';
import 'package:flutter/services.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';
@ -22,12 +24,11 @@ import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
class BaseSendWidget extends StatelessWidget { class BaseSendWidget extends StatelessWidget {
BaseSendWidget({ BaseSendWidget(
@required this.sendViewModel, {@required this.sendViewModel,
@required this.leading, @required this.leading,
@required this.middle, @required this.middle,
this.isTemplate = false this.isTemplate = false});
});
final SendViewModel sendViewModel; final SendViewModel sendViewModel;
final bool isTemplate; final bool isTemplate;
@ -45,7 +46,6 @@ class BaseSendWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_setEffects(context); _setEffects(context);
return ScrollableWithBottomSection( return ScrollableWithBottomSection(
@ -57,9 +57,7 @@ class BaseSendWidget extends StatelessWidget {
gradient: LinearGradient(colors: [ gradient: LinearGradient(colors: [
Theme.of(context).primaryTextTheme.subhead.color, Theme.of(context).primaryTextTheme.subhead.color,
Theme.of(context).primaryTextTheme.subhead.decorationColor, Theme.of(context).primaryTextTheme.subhead.decorationColor,
], ], begin: Alignment.topLeft, end: Alignment.bottomRight),
begin: Alignment.topLeft,
end: Alignment.bottomRight),
widget: Form( widget: Form(
key: _formKey, key: _formKey,
child: Column(children: <Widget>[ child: Column(children: <Widget>[
@ -77,14 +75,19 @@ class BaseSendWidget extends StatelessWidget {
? BaseTextFormField( ? BaseTextFormField(
controller: _nameController, controller: _nameController,
hintText: S.of(context).send_name, hintText: S.of(context).send_name,
borderColor: Theme.of(context).primaryTextTheme.headline.color, borderColor: Theme.of(context)
.primaryTextTheme
.headline
.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).primaryTextTheme.headline.decorationColor, color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: 14), fontSize: 14),
validator: sendViewModel.templateValidator, validator: sendViewModel.templateValidator,
@ -94,8 +97,9 @@ class BaseSendWidget extends StatelessWidget {
padding: EdgeInsets.only(top: isTemplate ? 20 : 0), padding: EdgeInsets.only(top: isTemplate ? 20 : 0),
child: AddressTextField( child: AddressTextField(
controller: _addressController, controller: _addressController,
placeholder: S.of(context).send_address( // placeholder: S
sendViewModel.cryptoCurrencyTitle), // .of(context)
// .send_address(sendViewModel.cryptoCurrencyTitle),
focusNode: _focusNode, focusNode: _focusNode,
onURIScanned: (uri) { onURIScanned: (uri) {
var address = ''; var address = '';
@ -116,23 +120,25 @@ class BaseSendWidget extends StatelessWidget {
AddressTextFieldOption.qrCode, AddressTextFieldOption.qrCode,
AddressTextFieldOption.addressBook AddressTextFieldOption.addressBook
], ],
buttonColor: Theme.of(context).primaryTextTheme.display1.color, buttonColor:
borderColor: Theme.of(context).primaryTextTheme.headline.color, Theme.of(context).primaryTextTheme.display1.color,
borderColor:
Theme.of(context).primaryTextTheme.headline.color,
textStyle: TextStyle( textStyle: TextStyle(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: Colors.white color: Colors.white),
),
hintStyle: TextStyle( hintStyle: TextStyle(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: Theme.of(context).primaryTextTheme.headline.decorationColor color: Theme.of(context)
), .primaryTextTheme
.headline
.decorationColor),
validator: sendViewModel.addressValidator, validator: sendViewModel.addressValidator,
), ),
), ),
Observer( Observer(builder: (_) {
builder: (_) {
return Padding( return Padding(
padding: const EdgeInsets.only(top: 20), padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField( child: BaseTextFormField(
@ -145,7 +151,8 @@ class BaseSendWidget extends StatelessWidget {
], ],
prefixIcon: Padding( prefixIcon: Padding(
padding: EdgeInsets.only(top: 9), padding: EdgeInsets.only(top: 9),
child: Text(sendViewModel.currency.title + ':', child:
Text(sendViewModel.currency.title + ':',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@ -157,41 +164,49 @@ class BaseSendWidget extends StatelessWidget {
: Container( : Container(
height: 32, height: 32,
width: 32, width: 32,
margin: EdgeInsets.only(left: 14, top: 4, bottom: 10), margin: EdgeInsets.only(
left: 14, top: 4, bottom: 10),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).primaryTextTheme.display1.color, color: Theme.of(context)
borderRadius: BorderRadius.all(Radius.circular(6)) .primaryTextTheme
), .display1
.color,
borderRadius: BorderRadius.all(
Radius.circular(6))),
child: InkWell( child: InkWell(
onTap: () => sendViewModel.setSendAll(), onTap: () =>
sendViewModel.setSendAll(),
child: Center( child: Center(
child: Text(S.of(context).all, child: Text(S.of(context).all,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Theme.of(context).primaryTextTheme.display1.decorationColor color: Theme.of(context)
) .primaryTextTheme
), .display1
.decorationColor)),
), ),
), ),
), ),
hintText: '0.0000', hintText: '0.0000',
borderColor: Theme.of(context).primaryTextTheme.headline.color, borderColor: Theme.of(context)
.primaryTextTheme
.headline
.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).primaryTextTheme.headline.decorationColor, color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: 14), fontSize: 14),
validator: sendViewModel.amountValidator validator: sendViewModel.amountValidator));
) }),
);
}
),
isTemplate isTemplate
? Offstage() ? Offstage()
: Observer( : Observer(
@ -199,7 +214,8 @@ class BaseSendWidget extends StatelessWidget {
padding: EdgeInsets.only(top: 10), padding: EdgeInsets.only(top: 10),
child: Row( child: Row(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Text( child: Text(
@ -207,22 +223,24 @@ class BaseSendWidget extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Theme.of(context).primaryTextTheme.headline.decorationColor color: Theme.of(context)
), .primaryTextTheme
) .headline
), .decorationColor),
)),
Text( Text(
sendViewModel.balance, sendViewModel.balance,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Theme.of(context).primaryTextTheme.headline.decorationColor color: Theme.of(context)
), .primaryTextTheme
.headline
.decorationColor),
) )
], ],
), ),
) )),
),
Padding( Padding(
padding: const EdgeInsets.only(top: 20), padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField( child: BaseTextFormField(
@ -235,8 +253,7 @@ class BaseSendWidget extends StatelessWidget {
], ],
prefixIcon: Padding( prefixIcon: Padding(
padding: EdgeInsets.only(top: 9), padding: EdgeInsets.only(top: 9),
child: Text( child: Text(sendViewModel.fiat.title + ':',
sendViewModel.fiat.title + ':',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@ -244,53 +261,63 @@ class BaseSendWidget extends StatelessWidget {
)), )),
), ),
hintText: '0.00', hintText: '0.00',
borderColor: Theme.of(context).primaryTextTheme.headline.color, borderColor: Theme.of(context)
.primaryTextTheme
.headline
.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).primaryTextTheme.headline.decorationColor, color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: 14), fontSize: 14),
) )),
),
isTemplate isTemplate
? Offstage() ? Offstage()
: Observer( : Observer(
builder: (_) => GestureDetector( builder: (_) => GestureDetector(
onTap: () => _setTransactionPriority(context), onTap: () =>
_setTransactionPriority(context),
child: Container( child: Container(
padding: EdgeInsets.only(top: 24), padding: EdgeInsets.only(top: 24),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Text(S.of(context).send_estimated_fee, Text(S.of(context).send_estimated_fee,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
//color: Theme.of(context).primaryTextTheme.display2.color, //color: Theme.of(context).primaryTextTheme.display2.color,
color: Colors.white color: Colors.white)),
)),
Container( Container(
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Text( Text(
sendViewModel.estimatedFee.toString() + ' ' sendViewModel.estimatedFee
+ sendViewModel.currency.title, .toString() +
' ' +
sendViewModel
.currency.title,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.w600, fontWeight:
FontWeight.w600,
//color: Theme.of(context).primaryTextTheme.display2.color, //color: Theme.of(context).primaryTextTheme.display2.color,
color: Colors.white color: Colors.white)),
)),
Padding( Padding(
padding: EdgeInsets.only(left: 5), padding:
EdgeInsets.only(left: 5),
child: Icon( child: Icon(
Icons.arrow_forward_ios, Icons.arrow_forward_ios,
size: 12, size: 12,
color: Colors.white,), color: Colors.white,
),
) )
], ],
), ),
@ -298,8 +325,7 @@ class BaseSendWidget extends StatelessWidget {
], ],
), ),
), ),
) ))
)
], ],
), ),
) )
@ -309,11 +335,7 @@ class BaseSendWidget extends StatelessWidget {
isTemplate isTemplate
? Offstage() ? Offstage()
: Padding( : Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(top: 30, left: 24, bottom: 24),
top: 30,
left: 24,
bottom: 24
),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[ children: <Widget>[
@ -322,8 +344,10 @@ class BaseSendWidget extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Theme.of(context).primaryTextTheme.display4.color color: Theme.of(context)
), .primaryTextTheme
.display4
.color),
) )
], ],
), ),
@ -346,7 +370,10 @@ class BaseSendWidget extends StatelessWidget {
child: DottedBorder( child: DottedBorder(
borderType: BorderType.RRect, borderType: BorderType.RRect,
dashPattern: [6, 4], dashPattern: [6, 4],
color: Theme.of(context).primaryTextTheme.display2.decorationColor, color: Theme.of(context)
.primaryTextTheme
.display2
.decorationColor,
strokeWidth: 2, strokeWidth: 2,
radius: Radius.circular(20), radius: Radius.circular(20),
child: Container( child: Container(
@ -355,7 +382,8 @@ class BaseSendWidget extends StatelessWidget {
padding: EdgeInsets.only(left: 10, right: 10), padding: EdgeInsets.only(left: 10, right: 10),
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)), borderRadius:
BorderRadius.all(Radius.circular(20)),
color: Colors.transparent, color: Colors.transparent,
), ),
child: Text( child: Text(
@ -363,60 +391,61 @@ class BaseSendWidget extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Theme.of(context).primaryTextTheme.display3.color color: Theme.of(context)
.primaryTextTheme
.display3
.color),
),
)),
), ),
), ),
) // Observer(
), // builder: (_) {
), // final templates = sendViewModel.templates;
), // final itemCount = templates.length;
Observer(
builder: (_) {
final templates = sendViewModel.templates;
final itemCount = templates.length;
return ListView.builder( // return ListView.builder(
scrollDirection: Axis.horizontal, // scrollDirection: Axis.horizontal,
shrinkWrap: true, // shrinkWrap: true,
physics: NeverScrollableScrollPhysics(), // physics: NeverScrollableScrollPhysics(),
itemCount: itemCount, // itemCount: itemCount,
itemBuilder: (context, index) { // itemBuilder: (context, index) {
final template = templates[index]; // final template = templates[index];
return TemplateTile( // return TemplateTile(
key: UniqueKey(), // key: UniqueKey(),
to: template.name, // to: template.name,
amount: template.amount, // amount: template.amount,
from: template.cryptoCurrency, // from: template.cryptoCurrency,
onTap: () { // onTap: () {
_addressController.text = template.address; // _addressController.text = template.address;
_cryptoAmountController.text = template.amount; // _cryptoAmountController.text = template.amount;
getOpenaliasRecord(context); // getOpenaliasRecord(context);
}, // },
onRemove: () { // onRemove: () {
showDialog<void>( // showDialog<void>(
context: context, // context: context,
builder: (dialogContext) { // builder: (dialogContext) {
return AlertWithTwoActions( // return AlertWithTwoActions(
alertTitle: S.of(context).template, // alertTitle: S.of(context).template,
alertContent: S.of(context).confirm_delete_template, // alertContent: S.of(context).confirm_delete_template,
leftButtonText: S.of(context).delete, // leftButtonText: S.of(context).delete,
rightButtonText: S.of(context).cancel, // rightButtonText: S.of(context).cancel,
actionLeftButton: () { // actionLeftButton: () {
Navigator.of(dialogContext).pop(); // Navigator.of(dialogContext).pop();
sendViewModel.sendTemplateStore.remove(template: template); // sendViewModel.sendTemplateStore.remove(template: template);
sendViewModel.sendTemplateStore.update(); // sendViewModel.sendTemplateStore.update();
}, // },
actionRightButton: () => Navigator.of(dialogContext).pop() // actionRightButton: () => Navigator.of(dialogContext).pop()
); // );
} // }
); // );
}, // },
); // );
} // }
); // );
} // }
) // )
], ],
), ),
), ),
@ -428,13 +457,12 @@ class BaseSendWidget extends StatelessWidget {
? PrimaryButton( ? PrimaryButton(
onPressed: () { onPressed: () {
if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
sendViewModel.sendTemplateStore.addTemplate( // sendViewModel.sendTemplateStore.addTemplate(
name: _nameController.text, // name: _nameController.text,
address: _addressController.text, // address: _addressController.text,
cryptoCurrency: sendViewModel.currency.title, // cryptoCurrency: sendViewModel.currency.title,
amount: _cryptoAmountController.text // amount: _cryptoAmountController.text);
); // sendViewModel.sendTemplateStore.update();
sendViewModel.sendTemplateStore.update();
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
}, },
@ -465,6 +493,13 @@ class BaseSendWidget extends StatelessWidget {
return; return;
} }
reaction((_) => sendViewModel.sendAll, (bool all) {
if (all) {
_cryptoAmountController.text = S.current.all;
_fiatAmountController.text = null;
}
});
reaction((_) => sendViewModel.fiatAmount, (String amount) { reaction((_) => sendViewModel.fiatAmount, (String amount) {
if (amount != _fiatAmountController.text) { if (amount != _fiatAmountController.text) {
_fiatAmountController.text = amount; _fiatAmountController.text = amount;
@ -472,6 +507,10 @@ class BaseSendWidget extends StatelessWidget {
}); });
reaction((_) => sendViewModel.cryptoAmount, (String amount) { reaction((_) => sendViewModel.cryptoAmount, (String amount) {
if (sendViewModel.sendAll && amount != S.current.all) {
sendViewModel.sendAll = false;
}
if (amount != _cryptoAmountController.text) { if (amount != _cryptoAmountController.text) {
_cryptoAmountController.text = amount; _cryptoAmountController.text = amount;
} }
@ -487,29 +526,7 @@ class BaseSendWidget extends StatelessWidget {
final address = _addressController.text; final address = _addressController.text;
if (sendViewModel.address != address) { if (sendViewModel.address != address) {
sendViewModel.changeAddress(address); sendViewModel.address = address;
}
});
_fiatAmountController.addListener(() {
final fiatAmount = _fiatAmountController.text;
if (sendViewModel.fiatAmount != fiatAmount) {
sendViewModel.changeFiatAmount(fiatAmount);
}
});
_cryptoAmountController.addListener(() {
final cryptoAmount = _cryptoAmountController.text;
if (sendViewModel.cryptoAmount != cryptoAmount) {
sendViewModel.changeCryptoAmount(cryptoAmount);
}
});
_focusNode.addListener(() {
if (!_focusNode.hasFocus && _addressController.text.isNotEmpty) {
getOpenaliasRecord(context);
} }
}); });
@ -519,44 +536,126 @@ class BaseSendWidget extends StatelessWidget {
showDialog<void>( showDialog<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertWithOneAction(
title: Text(S.of(context).error), alertTitle: S.of(context).error,
content: Text(state.error), alertContent: state.error,
actions: <Widget>[ buttonText: S.of(context).ok,
FlatButton( buttonAction: () => Navigator.of(context).pop());
child: Text(S.of(context).ok),
onPressed: () => Navigator.of(context).pop())
],
);
}); });
}); });
} }
if (state is TransactionCreatedSuccessfully) { if (state is TransactionCreatedSuccessfully) {
// WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
// showDialog<void>( showDialog<void>(
// context: context, context: context,
// builder: (BuildContext context) { builder: (BuildContext context) {
// return ConfirmSendingAlert( return ConfirmSendingAlert(
// 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: sendStore.pendingTransaction.amount, amountValue:
// fee: S.of(context).send_fee, sendViewModel.pendingTransaction.amountFormatted,
// feeValue: sendStore.pendingTransaction.fee, fee: S.of(context).send_fee,
// leftButtonText: S.of(context).ok, feeValue: sendViewModel.pendingTransaction.feeFormatted,
// rightButtonText: S.of(context).cancel, leftButtonText: S.of(context).ok,
// actionLeftButton: () { rightButtonText: S.of(context).cancel,
// Navigator.of(context).pop(); actionLeftButton: () {
// sendStore.commitTransaction(); Navigator.of(context).pop();
// showDialog<void>( sendViewModel.commitTransaction();
// context: context, showDialog<void>(
// builder: (BuildContext context) { context: context,
// return SendingAlert(sendStore: sendStore); builder: (BuildContext context) {
// }); return Observer(builder: (_) {
// }, final state = sendViewModel.state;
// actionRightButton: () => Navigator.of(context).pop());
// }); 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) { if (state is TransactionCommitted) {
@ -571,22 +670,24 @@ class BaseSendWidget extends StatelessWidget {
} }
Future<void> getOpenaliasRecord(BuildContext context) async { Future<void> getOpenaliasRecord(BuildContext context) async {
final isOpenalias = await sendViewModel.isOpenaliasRecord(_addressController.text); // final isOpenalias =
// await sendViewModel.isOpenaliasRecord(_addressController.text);
if (isOpenalias) { // if (isOpenalias) {
_addressController.text = sendViewModel.recordAddress; // _addressController.text = sendViewModel.recordAddress;
await showDialog<void>( // await showDialog<void>(
context: context, // context: context,
builder: (BuildContext context) { // builder: (BuildContext context) {
return AlertWithOneAction( // return AlertWithOneAction(
alertTitle: S.of(context).openalias_alert_title, // alertTitle: S.of(context).openalias_alert_title,
alertContent: S.of(context).openalias_alert_content(sendViewModel.recordName), // alertContent: S
buttonText: S.of(context).ok, // .of(context)
buttonAction: () => Navigator.of(context).pop() // .openalias_alert_content(sendViewModel.recordName),
); // buttonText: S.of(context).ok,
}); // buttonAction: () => Navigator.of(context).pop());
} // });
// }
} }
Future<void> _setTransactionPriority(BuildContext context) async { Future<void> _setTransactionPriority(BuildContext context) async {
@ -599,8 +700,8 @@ class BaseSendWidget extends StatelessWidget {
selectedAtIndex: selectedItem, selectedAtIndex: selectedItem,
title: S.of(context).please_select, title: S.of(context).please_select,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
onItemSelected: (TransactionPriority priority) => onItemSelected: (TransactionPriority priority) => null,
sendViewModel.setTransactionPriority(priority), // sendViewModel.setTransactionPriority(priority),
isAlwaysShowScrollThumb: true, isAlwaysShowScrollThumb: true,
), ),
context: context); context: context);

View file

@ -138,7 +138,7 @@ abstract class SettingsStoreBase with Store {
sharedPreferences.getBool(shouldSaveRecipientAddressKey); sharedPreferences.getBool(shouldSaveRecipientAddressKey);
final allowBiometricalAuthentication = final allowBiometricalAuthentication =
sharedPreferences.getBool(allowBiometricalAuthenticationKey) ?? false; sharedPreferences.getBool(allowBiometricalAuthenticationKey) ?? false;
final savedDarkTheme = sharedPreferences.getBool(currentDarkTheme) ?? true; final savedDarkTheme = sharedPreferences.getBool(currentDarkTheme) ?? false;
final actionListDisplayMode = ObservableList<ActionListDisplayMode>(); final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
actionListDisplayMode.addAll(deserializeActionlistDisplayModes( actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
sharedPreferences.getInt(displayActionListModeKey) ?? sharedPreferences.getInt(displayActionListModeKey) ??

View file

@ -1,5 +1,6 @@
import 'package:cake_wallet/core/wallet_base.dart'; import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart'; import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart'; import 'package:cake_wallet/src/domain/exchange/exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/limits.dart'; import 'package:cake_wallet/src/domain/exchange/limits.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart'; import 'package:cake_wallet/src/domain/exchange/trade.dart';
@ -25,22 +26,18 @@ part 'exchange_view_model.g.dart';
class ExchangeViewModel = ExchangeViewModelBase with _$ExchangeViewModel; class ExchangeViewModel = ExchangeViewModelBase with _$ExchangeViewModel;
abstract class ExchangeViewModelBase with Store { abstract class ExchangeViewModelBase with Store {
ExchangeViewModelBase({ ExchangeViewModelBase(
this.wallet, {this.wallet,
this.trades, this.trades,
this.exchangeTemplateStore, this.exchangeTemplateStore,
this.tradesStore}) { this.tradesStore}) {
providerList = [ providerList = [
XMRTOExchangeProvider(), XMRTOExchangeProvider(),
ChangeNowExchangeProvider(), ChangeNowExchangeProvider(),
MorphTokenExchangeProvider(trades: trades) MorphTokenExchangeProvider(trades: trades)
]; ];
provider = providerList[ 0 ]; _initialPairBasedOnWallet();
depositCurrency = CryptoCurrency.xmr;
receiveCurrency = CryptoCurrency.btc;
isDepositAddressEnabled = !(depositCurrency == wallet.currency); isDepositAddressEnabled = !(depositCurrency == wallet.currency);
isReceiveAddressEnabled = !(receiveCurrency == wallet.currency); isReceiveAddressEnabled = !(receiveCurrency == wallet.currency);
depositAmount = ''; depositAmount = '';
@ -50,6 +47,7 @@ abstract class ExchangeViewModelBase with Store {
limitsState = LimitsInitialState(); limitsState = LimitsInitialState();
tradeState = ExchangeTradeStateInitial(); tradeState = ExchangeTradeStateInitial();
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12; _cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12;
provider = providersForCurrentPair().first;
loadLimits(); loadLimits();
} }
@ -141,7 +139,10 @@ abstract class ExchangeViewModelBase with Store {
provider provider
.calculateAmount( .calculateAmount(
from: depositCurrency, to: receiveCurrency, amount: _amount) from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), "")) .then((amount) => _cryptoNumberFormat
.format(amount)
.toString()
.replaceAll(RegExp('\\,'), ''))
.then((amount) => depositAmount = amount); .then((amount) => depositAmount = amount);
} }
@ -159,7 +160,10 @@ abstract class ExchangeViewModelBase with Store {
provider provider
.calculateAmount( .calculateAmount(
from: depositCurrency, to: receiveCurrency, amount: _amount) from: depositCurrency, to: receiveCurrency, amount: _amount)
.then((amount) => _cryptoNumberFormat.format(amount).toString().replaceAll(RegExp("\\,"), "")) .then((amount) => _cryptoNumberFormat
.format(amount)
.toString()
.replaceAll(RegExp('\\,'), ''))
.then((amount) => receiveAmount = amount); .then((amount) => receiveAmount = amount);
} }
@ -217,10 +221,12 @@ abstract class ExchangeViewModelBase with Store {
if (limitsState is LimitsLoadedSuccessfully && amount != null) { if (limitsState is LimitsLoadedSuccessfully && amount != null) {
if (double.parse(amount) < limits.min) { if (double.parse(amount) < limits.min) {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_minimal_limit('${provider.description}', tradeState = TradeIsCreatedFailure(
error: S.current.error_text_minimal_limit('${provider.description}',
'${limits.min}', currency.toString())); '${limits.min}', currency.toString()));
} else if (limits.max != null && double.parse(amount) > limits.max) { } else if (limits.max != null && double.parse(amount) > limits.max) {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_maximum_limit('${provider.description}', tradeState = TradeIsCreatedFailure(
error: S.current.error_text_maximum_limit('${provider.description}',
'${limits.max}', currency.toString())); '${limits.max}', currency.toString()));
} else { } else {
try { try {
@ -235,9 +241,10 @@ abstract class ExchangeViewModelBase with Store {
} }
} }
} else { } else {
tradeState = TradeIsCreatedFailure(error: S.current.error_text_limits_loading_failed('${provider.description}')); tradeState = TradeIsCreatedFailure(
error: S.current
.error_text_limits_loading_failed('${provider.description}'));
} }
} }
@action @action
@ -295,4 +302,18 @@ abstract class ExchangeViewModelBase with Store {
return providers.isNotEmpty ? providers[0] : null; return providers.isNotEmpty ? providers[0] : null;
} }
void _initialPairBasedOnWallet() {
switch (wallet.type) {
case WalletType.monero:
depositCurrency = CryptoCurrency.xmr;
receiveCurrency = CryptoCurrency.btc;
break;
case WalletType.bitcoin:
depositCurrency = CryptoCurrency.btc;
receiveCurrency = CryptoCurrency.xmr;
break;
default:
break;
}
}
} }

View file

@ -1,7 +1,8 @@
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart';
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/template_validator.dart';
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart';
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
import 'package:cake_wallet/core/address_validator.dart'; import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/core/amount_validator.dart'; import 'package:cake_wallet/core/amount_validator.dart';
import 'package:cake_wallet/core/pending_transaction.dart'; import 'package:cake_wallet/core/pending_transaction.dart';
@ -28,7 +29,7 @@ abstract class SendViewModelBase with Store {
: state = InitialSendViewModelState(), : state = InitialSendViewModelState(),
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12, _cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12,
// FIXME: need to be based on wallet type. // FIXME: need to be based on wallet type.
all = false; sendAll = false;
@observable @observable
SendViewModelState state; SendViewModelState state;
@ -43,7 +44,7 @@ abstract class SendViewModelBase with Store {
String address; String address;
@observable @observable
bool all; bool sendAll;
FiatCurrency get fiat => _settingsStore.fiatCurrency; FiatCurrency get fiat => _settingsStore.fiatCurrency;
@ -59,6 +60,8 @@ abstract class SendViewModelBase with Store {
Validator get addressValidator => AddressValidator(type: _wallet.currency); Validator get addressValidator => AddressValidator(type: _wallet.currency);
Validator get templateValidator => TemplateValidator();
PendingTransaction pendingTransaction; PendingTransaction pendingTransaction;
@computed @computed
@ -83,7 +86,7 @@ abstract class SendViewModelBase with Store {
final NumberFormat _cryptoNumberFormat; final NumberFormat _cryptoNumberFormat;
@action @action
void setAll() => all = true; void setSendAll() => sendAll = true;
@action @action
void reset() { void reset() {
@ -118,7 +121,7 @@ abstract class SendViewModelBase with Store {
void setCryptoAmount(String amount) { void setCryptoAmount(String amount) {
// FIXME: hardcoded value. // FIXME: hardcoded value.
if (amount.toUpperCase() != 'ALL') { if (amount.toUpperCase() != 'ALL') {
all = false; sendAll = false;
} }
cryptoAmount = amount; cryptoAmount = amount;
@ -162,7 +165,7 @@ abstract class SendViewModelBase with Store {
Object _credentials() { Object _credentials() {
final amount = final amount =
!all ? double.parse(cryptoAmount.replaceAll(',', '.')) : null; !sendAll ? double.parse(cryptoAmount.replaceAll(',', '.')) : null;
switch (_wallet.type) { switch (_wallet.type) {
case WalletType.bitcoin: case WalletType.bitcoin: