2020-08-25 16:32:40 +00:00
|
|
|
import 'dart:ui';
|
2021-07-16 09:32:36 +00:00
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/parse_address_from_domain_alert.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/send_card.dart';
|
2020-10-07 05:58:22 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/template_tile.dart';
|
2021-08-10 14:52:35 +00:00
|
|
|
import 'package:cake_wallet/view_model/send/output.dart';
|
2020-09-29 17:56:11 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/routes.dart';
|
|
|
|
import 'package:cake_wallet/view_model/send/send_view_model.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/core/execution_state.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/base_page.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/trail_button.dart';
|
2020-09-25 15:32:44 +00:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:dotted_border/dotted_border.dart';
|
2020-05-07 17:10:04 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
2020-09-22 19:26:20 +00:00
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart';
|
2021-07-16 09:32:36 +00:00
|
|
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
2020-08-25 16:32:40 +00:00
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
class SendPage extends BasePage {
|
2021-07-16 09:32:36 +00:00
|
|
|
SendPage({@required this.sendViewModel}) :_formKey = GlobalKey<FormState>();
|
2021-01-13 16:27:30 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
final SendViewModel sendViewModel;
|
2020-10-02 17:28:29 +00:00
|
|
|
final GlobalKey<FormState> _formKey;
|
2021-07-16 09:32:36 +00:00
|
|
|
final controller = PageController(initialPage: 0);
|
2020-09-21 19:01:45 +00:00
|
|
|
|
|
|
|
bool _effectsInstalled = false;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
@override
|
2020-09-21 19:01:45 +00:00
|
|
|
String get title => S.current.send;
|
2020-01-08 12:26:34 +00:00
|
|
|
|
|
|
|
@override
|
2020-08-20 17:43:54 +00:00
|
|
|
Color get titleColor => Colors.white;
|
2020-05-29 15:10:11 +00:00
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
@override
|
2021-04-12 18:22:22 +00:00
|
|
|
bool get resizeToAvoidBottomInset => false;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-05-11 08:22:03 +00:00
|
|
|
@override
|
2020-09-22 18:32:43 +00:00
|
|
|
bool get extendBodyBehindAppBar => true;
|
2020-09-01 11:18:07 +00:00
|
|
|
|
2020-09-02 08:47:41 +00:00
|
|
|
@override
|
2020-09-22 18:32:43 +00:00
|
|
|
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
2020-09-02 08:47:41 +00:00
|
|
|
|
|
|
|
@override
|
2021-07-16 09:32:36 +00:00
|
|
|
Widget trailing(context) => Observer(builder: (_) {
|
2021-08-06 07:55:50 +00:00
|
|
|
return sendViewModel.isBatchSending
|
2021-07-16 09:32:36 +00:00
|
|
|
? TrailButton(
|
|
|
|
caption: S.of(context).remove,
|
|
|
|
onPressed: () {
|
|
|
|
var pageToJump = controller.page.round() - 1;
|
|
|
|
pageToJump = pageToJump > 0 ? pageToJump : 0;
|
2021-08-10 14:52:35 +00:00
|
|
|
final output = _defineCurrentOutput();
|
|
|
|
sendViewModel.removeOutput(output);
|
2021-07-16 09:32:36 +00:00
|
|
|
controller.jumpToPage(pageToJump);
|
|
|
|
})
|
|
|
|
: TrailButton(
|
|
|
|
caption: S.of(context).clear,
|
|
|
|
onPressed: () {
|
2021-08-10 14:52:35 +00:00
|
|
|
final output = _defineCurrentOutput();
|
2021-07-16 09:32:36 +00:00
|
|
|
_formKey.currentState.reset();
|
2021-08-10 14:52:35 +00:00
|
|
|
output.reset();
|
2021-07-16 09:32:36 +00:00
|
|
|
});
|
|
|
|
});
|
2020-09-02 08:47:41 +00:00
|
|
|
|
2020-09-21 19:01:45 +00:00
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
|
|
|
_setEffects(context);
|
|
|
|
|
2021-07-16 09:32:36 +00:00
|
|
|
return Form(
|
|
|
|
key: _formKey,
|
|
|
|
child: ScrollableWithBottomSection(
|
|
|
|
contentPadding: EdgeInsets.only(bottom: 24),
|
|
|
|
content: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
2021-08-11 15:08:06 +00:00
|
|
|
height: sendViewModel.isElectrumWallet ? 490 : 465,
|
2021-07-16 09:32:36 +00:00
|
|
|
child: Observer(
|
|
|
|
builder: (_) {
|
|
|
|
return PageView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
controller: controller,
|
2021-08-10 14:52:35 +00:00
|
|
|
itemCount: sendViewModel.outputs.length,
|
2021-07-16 09:32:36 +00:00
|
|
|
itemBuilder: (context, index) {
|
2021-08-10 14:52:35 +00:00
|
|
|
final output = sendViewModel.outputs[index];
|
2021-07-16 09:32:36 +00:00
|
|
|
|
|
|
|
return SendCard(
|
2021-08-10 14:52:35 +00:00
|
|
|
key: output.key,
|
|
|
|
output: output,
|
2021-07-16 09:32:36 +00:00
|
|
|
sendViewModel: sendViewModel,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
2020-09-29 17:56:11 +00:00
|
|
|
),
|
2021-07-16 09:32:36 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 10, left: 24, right: 24, bottom: 10),
|
|
|
|
child: Container(
|
|
|
|
height: 10,
|
|
|
|
child: Observer(builder: (_) {
|
2021-08-10 14:52:35 +00:00
|
|
|
final count = sendViewModel.outputs.length;
|
2021-07-16 09:32:36 +00:00
|
|
|
|
|
|
|
return count > 1
|
|
|
|
? SmoothPageIndicator(
|
|
|
|
controller: controller,
|
|
|
|
count: count,
|
|
|
|
effect: ScrollingDotsEffect(
|
|
|
|
spacing: 6.0,
|
|
|
|
radius: 6.0,
|
|
|
|
dotWidth: 6.0,
|
|
|
|
dotHeight: 6.0,
|
|
|
|
dotColor: Theme.of(context)
|
2020-09-22 18:32:43 +00:00
|
|
|
.primaryTextTheme
|
2021-07-16 09:32:36 +00:00
|
|
|
.display2
|
|
|
|
.backgroundColor,
|
|
|
|
activeDotColor: Theme.of(context)
|
2020-09-21 19:01:45 +00:00
|
|
|
.primaryTextTheme
|
2021-07-16 09:32:36 +00:00
|
|
|
.display3
|
|
|
|
.backgroundColor
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: Offstage();
|
|
|
|
})
|
|
|
|
)
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(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)
|
|
|
|
.primaryTextTheme
|
|
|
|
.display4
|
|
|
|
.color),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 40,
|
|
|
|
width: double.infinity,
|
|
|
|
padding: EdgeInsets.only(left: 24),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () => Navigator.of(context)
|
|
|
|
.pushNamed(Routes.sendTemplate),
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(left: 1, right: 10),
|
|
|
|
child: DottedBorder(
|
|
|
|
borderType: BorderType.RRect,
|
|
|
|
dashPattern: [6, 4],
|
2020-09-22 18:32:43 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
2021-07-16 09:32:36 +00:00
|
|
|
.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),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
),
|
2020-09-29 17:56:11 +00:00
|
|
|
),
|
2021-07-16 09:32:36 +00:00
|
|
|
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 {
|
2021-08-10 14:52:35 +00:00
|
|
|
final output = _defineCurrentOutput();
|
|
|
|
output.address =
|
2021-07-16 09:32:36 +00:00
|
|
|
template.address;
|
2021-08-10 14:52:35 +00:00
|
|
|
output.setCryptoAmount(template.amount);
|
|
|
|
final parsedAddress = await output
|
2021-07-22 16:48:26 +00:00
|
|
|
.applyOpenaliasOrUnstoppableDomains();
|
|
|
|
showAddressAlert(context, parsedAddress);
|
2021-07-16 09:32:36 +00:00
|
|
|
},
|
|
|
|
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: [
|
2021-08-04 14:38:03 +00:00
|
|
|
Padding(
|
2021-07-20 15:03:49 +00:00
|
|
|
padding: EdgeInsets.only(bottom: 12),
|
|
|
|
child: PrimaryButton(
|
|
|
|
onPressed: () {
|
2021-08-10 14:52:35 +00:00
|
|
|
sendViewModel.addOutput();
|
2021-07-20 15:03:49 +00:00
|
|
|
},
|
|
|
|
text: S.of(context).add_receiver,
|
|
|
|
color: Colors.green,
|
|
|
|
textColor: Colors.white,
|
|
|
|
)
|
2020-09-29 17:56:11 +00:00
|
|
|
),
|
2021-07-20 15:03:49 +00:00
|
|
|
Observer(builder: (_) {
|
|
|
|
return LoadingPrimaryButton(
|
|
|
|
onPressed: () async {
|
|
|
|
if (!_formKey.currentState.validate()) {
|
2021-08-10 14:52:35 +00:00
|
|
|
if (sendViewModel.outputs.length > 1) {
|
2021-07-20 15:03:49 +00:00
|
|
|
showErrorValidationAlert(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
final notValidItems = sendViewModel.outputs
|
2021-07-20 15:03:49 +00:00
|
|
|
.where((item) =>
|
2021-08-10 14:52:35 +00:00
|
|
|
item.address.isEmpty || item.cryptoAmount.isEmpty)
|
2021-07-20 15:03:49 +00:00
|
|
|
.toList();
|
|
|
|
|
|
|
|
if (notValidItems?.isNotEmpty ?? false) {
|
|
|
|
showErrorValidationAlert(context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await sendViewModel.createTransaction();
|
2021-07-16 09:32:36 +00:00
|
|
|
},
|
2021-07-20 15:03:49 +00:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
2021-07-16 09:32:36 +00:00
|
|
|
],
|
|
|
|
)),
|
|
|
|
);
|
2020-09-21 19:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _setEffects(BuildContext context) {
|
|
|
|
if (_effectsInstalled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-22 19:26:20 +00:00
|
|
|
reaction((_) => sendViewModel.state, (ExecutionState state) {
|
|
|
|
if (state is FailureState) {
|
2020-09-21 19:01:45 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-09-25 15:32:44 +00:00
|
|
|
showPopUp<void>(
|
2020-09-21 19:01:45 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).error,
|
|
|
|
alertContent: state.error,
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-22 19:26:20 +00:00
|
|
|
if (state is ExecutedSuccessfullyState) {
|
2020-09-21 19:01:45 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2020-09-25 15:32:44 +00:00
|
|
|
showPopUp<void>(
|
2020-09-21 19:01:45 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ConfirmSendingAlert(
|
|
|
|
alertTitle: S.of(context).confirm_sending,
|
|
|
|
amount: S.of(context).send_amount,
|
|
|
|
amountValue:
|
2021-07-16 09:32:36 +00:00
|
|
|
sendViewModel.pendingTransaction.amountFormatted,
|
2020-12-29 18:48:57 +00:00
|
|
|
fiatAmountValue: sendViewModel.pendingTransactionFiatAmount
|
|
|
|
+ ' ' + sendViewModel.fiat.title,
|
2020-09-21 19:01:45 +00:00
|
|
|
fee: S.of(context).send_fee,
|
|
|
|
feeValue: sendViewModel.pendingTransaction.feeFormatted,
|
2020-12-30 14:54:55 +00:00
|
|
|
feeFiatAmount: sendViewModel.pendingTransactionFeeFiatAmount
|
|
|
|
+ ' ' + sendViewModel.fiat.title,
|
2021-08-10 14:52:35 +00:00
|
|
|
outputs: sendViewModel.outputs,
|
2020-10-01 17:51:30 +00:00
|
|
|
rightButtonText: S.of(context).ok,
|
|
|
|
leftButtonText: S.of(context).cancel,
|
|
|
|
actionRightButton: () {
|
2020-09-21 19:01:45 +00:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
sendViewModel.commitTransaction();
|
2020-09-25 15:32:44 +00:00
|
|
|
showPopUp<void>(
|
2020-09-21 19:01:45 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return Observer(builder: (_) {
|
|
|
|
final state = sendViewModel.state;
|
|
|
|
|
2020-11-06 18:54:00 +00:00
|
|
|
if (state is FailureState) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:01:45 +00:00
|
|
|
if (state is TransactionCommitted) {
|
2020-12-29 18:48:57 +00:00
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: '',
|
|
|
|
alertContent: S.of(context).send_success(
|
|
|
|
sendViewModel.currency
|
|
|
|
.toString()),
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () =>
|
|
|
|
Navigator.of(context).pop());
|
2020-11-06 18:54:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 18:48:57 +00:00
|
|
|
return Offstage();
|
2020-09-21 19:01:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2020-10-01 17:51:30 +00:00
|
|
|
actionLeftButton: () => Navigator.of(context).pop());
|
2020-09-21 19:01:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state is TransactionCommitted) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2021-08-10 14:52:35 +00:00
|
|
|
sendViewModel.clearOutputs();
|
2020-09-21 19:01:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_effectsInstalled = true;
|
|
|
|
}
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
Output _defineCurrentOutput() {
|
2021-07-16 09:32:36 +00:00
|
|
|
final itemCount = controller.page.round();
|
2021-08-10 14:52:35 +00:00
|
|
|
return sendViewModel.outputs[itemCount];
|
2020-09-21 19:01:45 +00:00
|
|
|
}
|
2021-07-20 15:03:49 +00:00
|
|
|
|
|
|
|
void showErrorValidationAlert(BuildContext context) async {
|
|
|
|
await showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).error,
|
|
|
|
alertContent: 'Please, check receiver forms',
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () =>
|
|
|
|
Navigator.of(context).pop());
|
|
|
|
});
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|