2023-08-04 14:49:26 +01:00
|
|
|
import 'package:cake_wallet/core/auth_service.dart';
|
2022-05-03 13:44:13 +03:00
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
2023-08-01 19:19:04 -03:00
|
|
|
import 'package:cake_wallet/entities/template.dart';
|
2022-03-15 10:11:53 +01:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.dart';
|
2021-07-16 12:32:36 +03:00
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/send_card.dart';
|
2023-04-14 06:39:08 +02:00
|
|
|
import 'package:cake_wallet/src/widgets/add_template_button.dart';
|
2020-10-07 08:58:22 +03:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
2022-03-30 17:57:04 +02:00
|
|
|
import 'package:cake_wallet/src/widgets/picker.dart';
|
2020-10-07 08:58:22 +03:00
|
|
|
import 'package:cake_wallet/src/widgets/template_tile.dart';
|
2023-04-26 14:59:27 +02:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
2022-08-09 15:47:41 +02:00
|
|
|
import 'package:cake_wallet/utils/payment_request.dart';
|
2023-04-17 21:06:58 +03:00
|
|
|
import 'package:cake_wallet/utils/request_review_handler.dart';
|
2023-04-14 06:39:08 +02:00
|
|
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
2021-08-10 17:52:35 +03:00
|
|
|
import 'package:cake_wallet/view_model/send/output.dart';
|
2020-09-29 20:56:11 +03:00
|
|
|
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 22:26:20 +03: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 18:32:44 +03:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-09-22 22:26:20 +03:00
|
|
|
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
2020-01-04 21:31:52 +02:00
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2020-05-07 20:10:04 +03:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
2020-09-22 22:26:20 +03:00
|
|
|
import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart';
|
2021-07-16 12:32:36 +03:00
|
|
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
2022-03-30 17:57:04 +02:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2020-08-25 19:32:40 +03:00
|
|
|
|
2020-01-04 21:31:52 +02:00
|
|
|
class SendPage extends BasePage {
|
2022-08-09 15:47:41 +02:00
|
|
|
SendPage({
|
2022-11-08 14:44:58 +02:00
|
|
|
required this.sendViewModel,
|
2023-08-04 14:49:26 +01:00
|
|
|
required this.authService,
|
2022-08-09 15:47:41 +02:00
|
|
|
this.initialPaymentRequest,
|
2022-12-12 18:01:42 +02:00
|
|
|
}) : _formKey = GlobalKey<FormState>();
|
2021-01-13 18:27:30 +02:00
|
|
|
|
2020-07-06 23:09:03 +03:00
|
|
|
final SendViewModel sendViewModel;
|
2023-08-04 14:49:26 +01:00
|
|
|
final AuthService authService;
|
2020-10-02 20:28:29 +03:00
|
|
|
final GlobalKey<FormState> _formKey;
|
2021-07-16 12:32:36 +03:00
|
|
|
final controller = PageController(initialPage: 0);
|
2022-11-08 14:44:58 +02:00
|
|
|
final PaymentRequest? initialPaymentRequest;
|
2020-09-21 22:01:45 +03:00
|
|
|
|
|
|
|
bool _effectsInstalled = false;
|
2020-07-06 23:09:03 +03:00
|
|
|
|
2020-01-08 14:26:34 +02:00
|
|
|
@override
|
2020-09-21 22:01:45 +03:00
|
|
|
String get title => S.current.send;
|
2020-01-08 14:26:34 +02:00
|
|
|
|
|
|
|
@override
|
2020-08-20 20:43:54 +03:00
|
|
|
Color get titleColor => Colors.white;
|
2020-05-29 18:10:11 +03:00
|
|
|
|
2020-01-08 14:26:34 +02:00
|
|
|
@override
|
2021-04-12 21:22:22 +03:00
|
|
|
bool get resizeToAvoidBottomInset => false;
|
2020-01-04 21:31:52 +02:00
|
|
|
|
2020-05-11 11:22:03 +03:00
|
|
|
@override
|
2020-09-22 21:32:43 +03:00
|
|
|
bool get extendBodyBehindAppBar => true;
|
2020-09-01 14:18:07 +03:00
|
|
|
|
2023-04-14 06:39:08 +02:00
|
|
|
@override
|
2023-04-26 14:59:27 +02:00
|
|
|
Widget? leading(BuildContext context) {
|
2023-08-04 14:49:26 +01:00
|
|
|
final _backButton = Icon(
|
|
|
|
Icons.arrow_back_ios,
|
2023-04-26 14:59:27 +02:00
|
|
|
color: titleColor,
|
|
|
|
size: 16,
|
|
|
|
);
|
|
|
|
final _closeButton = currentTheme.type == ThemeType.dark
|
2023-08-04 14:49:26 +01:00
|
|
|
? closeButtonImageDarkTheme
|
|
|
|
: closeButtonImage;
|
2023-04-26 14:59:27 +02:00
|
|
|
|
2023-06-14 02:04:52 +03:00
|
|
|
bool isMobileView = ResponsiveLayoutUtil.instance.isMobile;
|
2023-04-26 14:59:27 +02:00
|
|
|
|
|
|
|
return MergeSemantics(
|
|
|
|
child: SizedBox(
|
|
|
|
height: isMobileView ? 37 : 45,
|
|
|
|
width: isMobileView ? 37 : 45,
|
|
|
|
child: ButtonTheme(
|
|
|
|
minWidth: double.minPositive,
|
|
|
|
child: Semantics(
|
2023-07-11 18:21:59 -03:00
|
|
|
label: !isMobileView
|
|
|
|
? S.of(context).close
|
|
|
|
: S.of(context).seed_alert_back,
|
2023-04-26 14:59:27 +02:00
|
|
|
child: TextButton(
|
|
|
|
style: ButtonStyle(
|
|
|
|
overlayColor: MaterialStateColor.resolveWith(
|
2023-08-04 14:49:26 +01:00
|
|
|
(states) => Colors.transparent),
|
2023-04-26 14:59:27 +02:00
|
|
|
),
|
|
|
|
onPressed: () => onClose(context),
|
|
|
|
child: !isMobileView ? _closeButton : _backButton,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-04-14 06:39:08 +02:00
|
|
|
|
2020-09-02 11:47:41 +03:00
|
|
|
@override
|
2020-09-22 21:32:43 +03:00
|
|
|
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
2020-09-02 11:47:41 +03:00
|
|
|
|
2023-04-14 06:39:08 +02:00
|
|
|
double _sendCardHeight(BuildContext context) {
|
|
|
|
final double initialHeight = sendViewModel.isElectrumWallet ? 490 : 465;
|
|
|
|
|
2023-06-14 02:04:52 +03:00
|
|
|
if (!ResponsiveLayoutUtil.instance.isMobile) {
|
2023-04-14 06:39:08 +02:00
|
|
|
return initialHeight - 66;
|
|
|
|
}
|
|
|
|
return initialHeight;
|
|
|
|
}
|
|
|
|
|
2022-05-03 13:44:13 +03:00
|
|
|
@override
|
|
|
|
void onClose(BuildContext context) {
|
2022-11-25 22:51:07 +02:00
|
|
|
sendViewModel.onClose();
|
2022-05-03 13:44:13 +03:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
|
2022-02-21 16:30:48 +02:00
|
|
|
@override
|
2022-10-12 13:09:57 -04:00
|
|
|
Widget? middle(BuildContext context) {
|
|
|
|
final supMiddle = super.middle(context);
|
|
|
|
return Row(
|
2022-02-21 16:30:48 +02:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Padding(
|
2023-08-04 14:49:26 +01:00
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) =>
|
|
|
|
SyncIndicatorIcon(isSynced: sendViewModel.isReadyForSend),
|
|
|
|
),
|
2022-10-12 13:09:57 -04:00
|
|
|
),
|
2023-08-04 14:49:26 +01:00
|
|
|
if (supMiddle != null) supMiddle
|
2022-02-21 16:30:48 +02:00
|
|
|
],
|
|
|
|
);
|
2022-10-12 13:09:57 -04:00
|
|
|
}
|
2022-02-21 16:30:48 +02:00
|
|
|
|
2020-09-02 11:47:41 +03:00
|
|
|
@override
|
2021-07-16 12:32:36 +03:00
|
|
|
Widget trailing(context) => Observer(builder: (_) {
|
2022-01-12 18:58:54 +01:00
|
|
|
return sendViewModel.isBatchSending
|
|
|
|
? TrailButton(
|
|
|
|
caption: S.of(context).remove,
|
|
|
|
onPressed: () {
|
2022-10-12 13:09:57 -04:00
|
|
|
var pageToJump = (controller.page?.round() ?? 0) - 1;
|
2022-01-12 18:58:54 +01:00
|
|
|
pageToJump = pageToJump > 0 ? pageToJump : 0;
|
|
|
|
final output = _defineCurrentOutput();
|
|
|
|
sendViewModel.removeOutput(output);
|
|
|
|
controller.jumpToPage(pageToJump);
|
|
|
|
})
|
|
|
|
: TrailButton(
|
|
|
|
caption: S.of(context).clear,
|
|
|
|
onPressed: () {
|
|
|
|
final output = _defineCurrentOutput();
|
2022-10-12 13:09:57 -04:00
|
|
|
_formKey.currentState?.reset();
|
2022-01-12 18:58:54 +01:00
|
|
|
output.reset();
|
|
|
|
});
|
|
|
|
});
|
2020-09-02 11:47:41 +03:00
|
|
|
|
2020-09-21 22:01:45 +03:00
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
|
|
|
_setEffects(context);
|
|
|
|
|
2023-06-09 19:29:34 -03:00
|
|
|
return GestureDetector(
|
|
|
|
onLongPress: () => sendViewModel.balanceViewModel.isReversing =
|
|
|
|
!sendViewModel.balanceViewModel.isReversing,
|
|
|
|
onLongPressUp: () => sendViewModel.balanceViewModel.isReversing =
|
|
|
|
!sendViewModel.balanceViewModel.isReversing,
|
|
|
|
child: Form(
|
|
|
|
key: _formKey,
|
|
|
|
child: ScrollableWithBottomSection(
|
|
|
|
contentPadding: EdgeInsets.only(bottom: 24),
|
|
|
|
content: FocusTraversalGroup(
|
|
|
|
policy: OrderedTraversalPolicy(),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
height: _sendCardHeight(context),
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) {
|
|
|
|
return PageView.builder(
|
2023-04-14 06:39:08 +02:00
|
|
|
scrollDirection: Axis.horizontal,
|
2023-06-09 19:29:34 -03:00
|
|
|
controller: controller,
|
|
|
|
itemCount: sendViewModel.outputs.length,
|
2023-04-14 06:39:08 +02:00
|
|
|
itemBuilder: (context, index) {
|
2023-06-09 19:29:34 -03:00
|
|
|
final output = sendViewModel.outputs[index];
|
|
|
|
|
|
|
|
return SendCard(
|
|
|
|
key: output.key,
|
|
|
|
output: output,
|
|
|
|
sendViewModel: sendViewModel,
|
|
|
|
initialPaymentRequest: initialPaymentRequest,
|
2023-04-14 06:39:08 +02:00
|
|
|
);
|
2023-06-09 19:29:34 -03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: 10, left: 24, right: 24, bottom: 10),
|
|
|
|
child: Container(
|
|
|
|
height: 10,
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) {
|
|
|
|
final count = sendViewModel.outputs.length;
|
|
|
|
|
|
|
|
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)
|
2023-08-04 14:49:26 +01:00
|
|
|
.primaryTextTheme!
|
|
|
|
.displaySmall!
|
2023-06-09 19:29:34 -03:00
|
|
|
.backgroundColor!,
|
|
|
|
activeDotColor: Theme.of(context)
|
2023-08-04 14:49:26 +01:00
|
|
|
.primaryTextTheme!
|
|
|
|
.displayMedium!
|
2023-06-09 19:29:34 -03:00
|
|
|
.backgroundColor!),
|
|
|
|
)
|
|
|
|
: Offstage();
|
|
|
|
},
|
|
|
|
),
|
2023-04-14 06:39:08 +02:00
|
|
|
),
|
|
|
|
),
|
2023-08-04 20:01:49 +03:00
|
|
|
Container(
|
|
|
|
height: 40,
|
|
|
|
width: double.infinity,
|
|
|
|
padding: EdgeInsets.only(left: 24),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Observer(
|
|
|
|
builder: (_) {
|
|
|
|
final templates = sendViewModel.templates;
|
|
|
|
final itemCount = templates.length;
|
|
|
|
|
|
|
|
return Row(
|
|
|
|
children: <Widget>[
|
|
|
|
AddTemplateButton(
|
|
|
|
onTap: () => Navigator.of(context)
|
|
|
|
.pushNamed(Routes.sendTemplate),
|
|
|
|
currentTemplatesLength: templates.length,
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
hasMultipleRecipients:
|
|
|
|
template.additionalRecipients != null &&
|
|
|
|
template.additionalRecipients!.length > 1,
|
|
|
|
amount: template.isCurrencySelected
|
|
|
|
? template.amount
|
|
|
|
: template.amountFiat,
|
|
|
|
from: template.isCurrencySelected
|
|
|
|
? template.cryptoCurrency
|
|
|
|
: template.fiatCurrency,
|
|
|
|
onTap: () async {
|
|
|
|
if (template.additionalRecipients?.isNotEmpty ?? false) {
|
|
|
|
sendViewModel.clearOutputs();
|
|
|
|
|
|
|
|
for (int i = 0;i < template.additionalRecipients!.length;i++) {
|
|
|
|
Output output;
|
|
|
|
try {
|
|
|
|
output = sendViewModel.outputs[i];
|
|
|
|
} catch (e) {
|
|
|
|
sendViewModel.addOutput();
|
|
|
|
output = sendViewModel.outputs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
await _setInputsFromTemplate(
|
|
|
|
context,
|
|
|
|
output: output,
|
|
|
|
template: template.additionalRecipients![i],
|
|
|
|
);
|
2023-06-09 19:29:34 -03:00
|
|
|
}
|
2023-08-04 20:01:49 +03:00
|
|
|
} else {
|
|
|
|
final output = _defineCurrentOutput();
|
|
|
|
await _setInputsFromTemplate(
|
|
|
|
context,
|
|
|
|
output: output,
|
|
|
|
template: template,
|
2023-06-09 19:29:34 -03:00
|
|
|
);
|
2023-08-04 20:01:49 +03: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());
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2023-06-09 19:29:34 -03:00
|
|
|
),
|
2023-08-04 20:01:49 +03:00
|
|
|
),
|
|
|
|
),
|
2023-06-09 19:29:34 -03:00
|
|
|
],
|
|
|
|
),
|
2023-04-14 06:39:08 +02:00
|
|
|
),
|
2023-06-09 19:29:34 -03:00
|
|
|
bottomSectionPadding:
|
|
|
|
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
|
|
|
bottomSection: Column(
|
|
|
|
children: [
|
|
|
|
if (sendViewModel.hasCurrecyChanger)
|
|
|
|
Observer(
|
|
|
|
builder: (_) => Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 12),
|
|
|
|
child: PrimaryButton(
|
|
|
|
onPressed: () => presentCurrencyPicker(context),
|
|
|
|
text:
|
|
|
|
'Change your asset (${sendViewModel.selectedCryptoCurrency})',
|
|
|
|
color: Colors.transparent,
|
|
|
|
textColor: Theme.of(context)
|
2023-08-04 14:49:26 +01:00
|
|
|
.accentTextTheme!
|
|
|
|
.displaySmall!
|
2023-06-09 19:29:34 -03:00
|
|
|
.decorationColor!,
|
|
|
|
))),
|
2023-08-04 20:01:49 +03:00
|
|
|
if (sendViewModel.sendTemplateViewModel.hasMultiRecipient)
|
2022-03-30 17:57:04 +02:00
|
|
|
Padding(
|
2023-06-09 19:29:34 -03:00
|
|
|
padding: EdgeInsets.only(bottom: 12),
|
|
|
|
child: PrimaryButton(
|
|
|
|
onPressed: () {
|
|
|
|
sendViewModel.addOutput();
|
|
|
|
Future.delayed(const Duration(milliseconds: 250), () {
|
|
|
|
controller
|
|
|
|
.jumpToPage(sendViewModel.outputs.length - 1);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
text: S.of(context).add_receiver,
|
|
|
|
color: Colors.transparent,
|
|
|
|
textColor: Theme.of(context)
|
2023-08-04 14:49:26 +01:00
|
|
|
.accentTextTheme!
|
|
|
|
.displaySmall!
|
2023-06-09 19:29:34 -03:00
|
|
|
.decorationColor!,
|
|
|
|
isDottedBorder: true,
|
|
|
|
borderColor: Theme.of(context)
|
2023-08-04 14:49:26 +01:00
|
|
|
.primaryTextTheme!
|
|
|
|
.displaySmall!
|
2023-06-09 19:29:34 -03:00
|
|
|
.decorationColor!,
|
|
|
|
)),
|
|
|
|
Observer(
|
|
|
|
builder: (_) {
|
|
|
|
return LoadingPrimaryButton(
|
|
|
|
onPressed: () async {
|
|
|
|
if (_formKey.currentState != null &&
|
|
|
|
!_formKey.currentState!.validate()) {
|
|
|
|
if (sendViewModel.outputs.length > 1) {
|
|
|
|
showErrorValidationAlert(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final notValidItems = sendViewModel.outputs
|
|
|
|
.where((item) =>
|
|
|
|
item.address.isEmpty ||
|
|
|
|
item.cryptoAmount.isEmpty)
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
if (notValidItems.isNotEmpty ?? false) {
|
2022-01-12 18:58:54 +01:00
|
|
|
showErrorValidationAlert(context);
|
2023-06-09 19:29:34 -03:00
|
|
|
return;
|
2022-01-12 18:58:54 +01:00
|
|
|
}
|
2021-07-20 18:03:49 +03:00
|
|
|
|
2023-08-04 14:49:26 +01:00
|
|
|
final check = sendViewModel.shouldDisplayTotp();
|
|
|
|
authService.authenticateAction(
|
|
|
|
context,
|
|
|
|
conditionToDetermineIfToUse2FA: check,
|
|
|
|
onAuthSuccess: (value) async {
|
|
|
|
if (value) {
|
|
|
|
await sendViewModel.createTransaction();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2023-06-09 19:29:34 -03:00
|
|
|
},
|
|
|
|
text: S.of(context).send,
|
|
|
|
color:
|
|
|
|
Theme.of(context).accentTextTheme!.bodyLarge!.color!,
|
|
|
|
textColor: Colors.white,
|
|
|
|
isLoading: sendViewModel.state is IsExecutingState ||
|
|
|
|
sendViewModel.state is TransactionCommitting,
|
|
|
|
isDisabled: !sendViewModel.isReadyForSend,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
),
|
2021-07-16 12:32:36 +03:00
|
|
|
);
|
2020-09-21 22:01:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void _setEffects(BuildContext context) {
|
|
|
|
if (_effectsInstalled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-22 22:26:20 +03:00
|
|
|
reaction((_) => sendViewModel.state, (ExecutionState state) {
|
|
|
|
if (state is FailureState) {
|
2020-09-21 22:01:45 +03:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2023-02-07 18:03:31 +02:00
|
|
|
showPopUp<void>(
|
|
|
|
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-21 22:01:45 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-01 13:48:55 +01:00
|
|
|
if (state is ExecutedSuccessfullyState) {
|
2020-09-21 22:01:45 +03:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2023-02-27 15:59:20 +02:00
|
|
|
if (context.mounted) {
|
|
|
|
showPopUp<void>(
|
2023-06-09 19:29:34 -03:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ConfirmSendingAlert(
|
|
|
|
alertTitle: S.of(context).confirm_sending,
|
|
|
|
amount: S.of(context).send_amount,
|
|
|
|
amountValue:
|
|
|
|
sendViewModel.pendingTransaction!.amountFormatted,
|
|
|
|
fiatAmountValue:
|
|
|
|
sendViewModel.pendingTransactionFiatAmountFormatted,
|
|
|
|
fee: S.of(context).send_fee,
|
|
|
|
feeValue: sendViewModel.pendingTransaction!.feeFormatted,
|
|
|
|
feeFiatAmount: sendViewModel
|
|
|
|
.pendingTransactionFeeFiatAmountFormatted,
|
|
|
|
outputs: sendViewModel.outputs,
|
|
|
|
rightButtonText: S.of(context).ok,
|
|
|
|
leftButtonText: S.of(context).cancel,
|
|
|
|
actionRightButton: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
sendViewModel.commitTransaction();
|
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return Observer(builder: (_) {
|
|
|
|
final state = sendViewModel.state;
|
|
|
|
|
|
|
|
if (state is FailureState) {
|
|
|
|
Navigator.of(context).pop();
|
2023-04-17 21:06:58 +03:00
|
|
|
}
|
2020-11-06 20:54:00 +02:00
|
|
|
|
2023-06-09 19:29:34 -03:00
|
|
|
if (state is TransactionCommitted) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: '',
|
|
|
|
alertContent: S.of(context).send_success(
|
|
|
|
sendViewModel.selectedCryptoCurrency
|
|
|
|
.toString()),
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
RequestReviewHandler.requestReview();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Offstage();
|
|
|
|
});
|
2020-09-21 22:01:45 +03:00
|
|
|
});
|
2023-06-09 19:29:34 -03:00
|
|
|
},
|
|
|
|
actionLeftButton: () => Navigator.of(context).pop());
|
|
|
|
});
|
2023-02-27 15:59:20 +02:00
|
|
|
}
|
2020-09-21 22:01:45 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state is TransactionCommitted) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
2021-08-10 17:52:35 +03:00
|
|
|
sendViewModel.clearOutputs();
|
2020-09-21 22:01:45 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_effectsInstalled = true;
|
|
|
|
}
|
|
|
|
|
2023-08-01 19:19:04 -03:00
|
|
|
Future<void> _setInputsFromTemplate(BuildContext context,
|
|
|
|
{required Output output, required Template template}) async {
|
|
|
|
final fiatFromTemplate = FiatCurrency.all
|
|
|
|
.singleWhere((element) => element.title == template.fiatCurrency);
|
|
|
|
|
|
|
|
output.address = template.address;
|
|
|
|
|
|
|
|
if (template.isCurrencySelected) {
|
2023-08-04 20:01:49 +03:00
|
|
|
sendViewModel.setSelectedCryptoCurrency(template.cryptoCurrency);
|
2023-08-01 19:19:04 -03:00
|
|
|
output.setCryptoAmount(template.amount);
|
|
|
|
} else {
|
|
|
|
sendViewModel.setFiatCurrency(fiatFromTemplate);
|
|
|
|
output.setFiatAmount(template.amountFiat);
|
|
|
|
}
|
|
|
|
|
|
|
|
output.resetParsedAddress();
|
|
|
|
await output.fetchParsedAddress(context);
|
|
|
|
}
|
|
|
|
|
2021-08-10 17:52:35 +03:00
|
|
|
Output _defineCurrentOutput() {
|
2022-10-12 13:09:57 -04:00
|
|
|
if (controller.page == null) {
|
|
|
|
throw Exception('Controller page is null');
|
|
|
|
}
|
|
|
|
final itemCount = controller.page!.round();
|
2021-08-10 17:52:35 +03:00
|
|
|
return sendViewModel.outputs[itemCount];
|
2020-09-21 22:01:45 +03:00
|
|
|
}
|
2021-07-20 18:03:49 +03: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,
|
2022-01-12 18:58:54 +01:00
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
2021-07-20 18:03:49 +03:00
|
|
|
});
|
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
|
2023-06-09 19:29:34 -03:00
|
|
|
void presentCurrencyPicker(BuildContext context) async {
|
2022-03-30 17:57:04 +02:00
|
|
|
await showPopUp<CryptoCurrency>(
|
|
|
|
builder: (_) => Picker(
|
2023-06-09 19:29:34 -03:00
|
|
|
items: sendViewModel.currencies,
|
|
|
|
displayItem: (Object item) => item.toString(),
|
|
|
|
selectedAtIndex: sendViewModel.currencies
|
|
|
|
.indexOf(sendViewModel.selectedCryptoCurrency),
|
|
|
|
title: S.of(context).please_select,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
onItemSelected: (CryptoCurrency cur) =>
|
|
|
|
sendViewModel.selectedCryptoCurrency = cur,
|
|
|
|
),
|
2022-03-30 17:57:04 +02:00
|
|
|
context: context);
|
|
|
|
}
|
2020-01-04 21:31:52 +02:00
|
|
|
}
|