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-08-17 12:28:31 -03:00
|
|
|
import 'package:cake_wallet/themes/extensions/seed_widget_theme.dart';
|
|
|
|
import 'package:cake_wallet/themes/extensions/send_page_theme.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';
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 14:39:19 +01:00
|
|
|
import 'package:cw_core/wallet_type.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
|
2023-08-17 12:28:31 -03:00
|
|
|
bool get gradientAll => true;
|
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-08-17 12:28:31 -03:00
|
|
|
color: titleColor(context),
|
2023-04-26 14:59:27 +02:00
|
|
|
size: 16,
|
|
|
|
);
|
2023-09-18 14:57:57 -04:00
|
|
|
final _closeButton =
|
|
|
|
currentTheme.type == ThemeType.dark ? closeButtonImageDarkTheme : closeButtonImage;
|
2023-04-26 14:59:27 +02:00
|
|
|
|
2023-11-03 07:42:18 +02:00
|
|
|
bool isMobileView = responsiveLayoutUtil.shouldRenderMobileUI;
|
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-09-18 14:57:57 -04: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(
|
2023-09-18 14:57:57 -04:00
|
|
|
overlayColor: MaterialStateColor.resolveWith((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) {
|
2023-09-14 22:14:16 +03:00
|
|
|
final double initialHeight = sendViewModel.hasCoinControl ? 500 : 465;
|
2023-04-14 06:39:08 +02:00
|
|
|
|
2023-11-03 07:42:18 +02:00
|
|
|
if (!responsiveLayoutUtil.shouldRenderMobileUI) {
|
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(
|
2023-09-18 14:57:57 -04:00
|
|
|
builder: (_) => SyncIndicatorIcon(isSynced: sendViewModel.isReadyForSend),
|
2023-08-04 14:49:26 +01:00
|
|
|
),
|
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(
|
2023-09-18 14:57:57 -04:00
|
|
|
onLongPress: () =>
|
|
|
|
sendViewModel.balanceViewModel.isReversing = !sendViewModel.balanceViewModel.isReversing,
|
|
|
|
onLongPressUp: () =>
|
|
|
|
sendViewModel.balanceViewModel.isReversing = !sendViewModel.balanceViewModel.isReversing,
|
2023-06-09 19:29:34 -03:00
|
|
|
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(
|
2023-09-18 14:57:57 -04:00
|
|
|
padding: EdgeInsets.only(top: 10, left: 24, right: 24, bottom: 10),
|
2023-06-09 19:29:34 -03:00
|
|
|
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,
|
2023-09-18 14:57:57 -04:00
|
|
|
dotColor: Theme.of(context)
|
|
|
|
.extension<SendPageTheme>()!
|
|
|
|
.indicatorDotColor,
|
|
|
|
activeDotColor: Theme.of(context)
|
|
|
|
.extension<SendPageTheme>()!
|
|
|
|
.templateBackgroundColor),
|
2023-06-09 19:29:34 -03:00
|
|
|
)
|
|
|
|
: 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(
|
2023-09-18 14:57:57 -04:00
|
|
|
onTap: () => Navigator.of(context).pushNamed(Routes.sendTemplate),
|
2023-08-04 20:01:49 +03:00
|
|
|
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,
|
2023-09-18 14:57:57 -04:00
|
|
|
hasMultipleRecipients: template.additionalRecipients != null &&
|
|
|
|
template.additionalRecipients!.length > 1,
|
2023-08-04 20:01:49 +03:00
|
|
|
amount: template.isCurrencySelected
|
|
|
|
? template.amount
|
|
|
|
: template.amountFiat,
|
|
|
|
from: template.isCurrencySelected
|
|
|
|
? template.cryptoCurrency
|
|
|
|
: template.fiatCurrency,
|
|
|
|
onTap: () async {
|
|
|
|
if (template.additionalRecipients?.isNotEmpty ?? false) {
|
|
|
|
sendViewModel.clearOutputs();
|
|
|
|
|
2023-09-18 14:57:57 -04:00
|
|
|
for (int i = 0;
|
|
|
|
i < template.additionalRecipients!.length;
|
|
|
|
i++) {
|
2023-08-04 20:01:49 +03:00
|
|
|
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(
|
2023-09-18 14:57:57 -04:00
|
|
|
alertTitle: S.of(context).template,
|
|
|
|
alertContent: S.of(context).confirm_delete_template,
|
|
|
|
rightButtonText: S.of(context).delete,
|
|
|
|
leftButtonText: S.of(context).cancel,
|
2023-08-04 20:01:49 +03:00
|
|
|
actionRightButton: () {
|
2023-09-18 14:57:57 -04:00
|
|
|
Navigator.of(dialogContext).pop();
|
|
|
|
sendViewModel.sendTemplateViewModel
|
|
|
|
.removeTemplate(template: template);
|
2023-08-04 20:01:49 +03:00
|
|
|
},
|
|
|
|
actionLeftButton: () =>
|
2023-09-18 14:57:57 -04:00
|
|
|
Navigator.of(dialogContext).pop());
|
2023-08-04 20:01:49 +03:00
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
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-09-18 14:57:57 -04:00
|
|
|
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
2023-06-09 19:29:34 -03:00
|
|
|
bottomSection: Column(
|
|
|
|
children: [
|
|
|
|
if (sendViewModel.hasCurrecyChanger)
|
|
|
|
Observer(
|
|
|
|
builder: (_) => Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 12),
|
|
|
|
child: PrimaryButton(
|
|
|
|
onPressed: () => presentCurrencyPicker(context),
|
2023-09-18 14:57:57 -04:00
|
|
|
text: 'Change your asset (${sendViewModel.selectedCryptoCurrency})',
|
2023-06-09 19:29:34 -03:00
|
|
|
color: Colors.transparent,
|
2023-09-18 14:57:57 -04:00
|
|
|
textColor:
|
|
|
|
Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
|
2023-06-09 19:29:34 -03:00
|
|
|
))),
|
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), () {
|
2023-09-18 14:57:57 -04:00
|
|
|
controller.jumpToPage(sendViewModel.outputs.length - 1);
|
2023-06-09 19:29:34 -03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
text: S.of(context).add_receiver,
|
|
|
|
color: Colors.transparent,
|
2023-08-18 18:37:17 +03:00
|
|
|
textColor: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
|
2023-06-09 19:29:34 -03:00
|
|
|
isDottedBorder: true,
|
2023-09-18 14:57:57 -04:00
|
|
|
borderColor:
|
|
|
|
Theme.of(context).extension<SendPageTheme>()!.templateDottedBorderColor,
|
2023-06-09 19:29:34 -03:00
|
|
|
)),
|
|
|
|
Observer(
|
|
|
|
builder: (_) {
|
|
|
|
return LoadingPrimaryButton(
|
|
|
|
onPressed: () async {
|
2023-09-18 14:57:57 -04:00
|
|
|
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
|
2023-06-09 19:29:34 -03:00
|
|
|
if (sendViewModel.outputs.length > 1) {
|
|
|
|
showErrorValidationAlert(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final notValidItems = sendViewModel.outputs
|
2023-09-18 14:57:57 -04:00
|
|
|
.where((item) => item.address.isEmpty || item.cryptoAmount.isEmpty)
|
2023-06-09 19:29:34 -03:00
|
|
|
.toList();
|
|
|
|
|
2023-08-18 18:37:17 +03:00
|
|
|
if (notValidItems.isNotEmpty) {
|
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,
|
2023-09-18 14:57:57 -04:00
|
|
|
color: Theme.of(context).primaryColor,
|
2023-06-09 19:29:34 -03:00
|
|
|
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,
|
2023-11-03 21:24:45 +02:00
|
|
|
builder: (BuildContext _dialogContext) {
|
2023-06-09 19:29:34 -03:00
|
|
|
return ConfirmSendingAlert(
|
2023-11-03 21:24:45 +02:00
|
|
|
alertTitle: S.of(_dialogContext).confirm_sending,
|
|
|
|
amount: S.of(_dialogContext).send_amount,
|
2023-09-18 14:57:57 -04:00
|
|
|
amountValue: sendViewModel.pendingTransaction!.amountFormatted,
|
|
|
|
fiatAmountValue: sendViewModel.pendingTransactionFiatAmountFormatted,
|
2023-11-03 21:24:45 +02:00
|
|
|
fee: S.of(_dialogContext).send_fee,
|
2023-06-09 19:29:34 -03:00
|
|
|
feeValue: sendViewModel.pendingTransaction!.feeFormatted,
|
2023-09-18 14:57:57 -04:00
|
|
|
feeFiatAmount: sendViewModel.pendingTransactionFeeFiatAmountFormatted,
|
2023-06-09 19:29:34 -03:00
|
|
|
outputs: sendViewModel.outputs,
|
2024-01-08 16:05:35 +02:00
|
|
|
rightButtonText: S.of(_dialogContext).send,
|
2023-11-03 21:24:45 +02:00
|
|
|
leftButtonText: S.of(_dialogContext).cancel,
|
2023-06-09 19:29:34 -03:00
|
|
|
actionRightButton: () {
|
2023-11-03 21:24:45 +02:00
|
|
|
Navigator.of(_dialogContext).pop();
|
2023-06-09 19:29:34 -03:00
|
|
|
sendViewModel.commitTransaction();
|
|
|
|
showPopUp<void>(
|
|
|
|
context: context,
|
2023-11-03 21:24:45 +02:00
|
|
|
builder: (BuildContext _dialogContext) {
|
2023-06-09 19:29:34 -03:00
|
|
|
return Observer(builder: (_) {
|
|
|
|
final state = sendViewModel.state;
|
|
|
|
|
|
|
|
if (state is FailureState) {
|
2023-11-03 21:24:45 +02:00
|
|
|
Navigator.of(_dialogContext).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) {
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 14:39:19 +01:00
|
|
|
String alertContent;
|
|
|
|
if (sendViewModel.walletType == WalletType.solana) {
|
|
|
|
alertContent =
|
|
|
|
'${S.of(_dialogContext).send_success(sendViewModel.selectedCryptoCurrency.toString())}. ${S.of(_dialogContext).waitFewSecondForTxUpdate}';
|
|
|
|
} else {
|
|
|
|
alertContent = S.of(_dialogContext).send_success(
|
|
|
|
sendViewModel.selectedCryptoCurrency.toString());
|
|
|
|
}
|
2023-06-09 19:29:34 -03:00
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: '',
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 14:39:19 +01:00
|
|
|
alertContent: alertContent,
|
2023-11-03 21:24:45 +02:00
|
|
|
buttonText: S.of(_dialogContext).ok,
|
2023-06-09 19:29:34 -03:00
|
|
|
buttonAction: () {
|
2023-11-03 21:24:45 +02:00
|
|
|
Navigator.of(_dialogContext).pop();
|
2023-06-09 19:29:34 -03:00
|
|
|
RequestReviewHandler.requestReview();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Offstage();
|
|
|
|
});
|
2020-09-21 22:01:45 +03:00
|
|
|
});
|
2023-06-09 19:29:34 -03:00
|
|
|
},
|
2023-11-03 21:24:45 +02:00
|
|
|
actionLeftButton: () => Navigator.of(_dialogContext).pop());
|
2023-06-09 19:29:34 -03:00
|
|
|
});
|
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 {
|
|
|
|
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 {
|
2023-11-03 21:24:45 +02:00
|
|
|
final fiatFromTemplate =
|
|
|
|
FiatCurrency.all.singleWhere((element) => element.title == template.fiatCurrency);
|
|
|
|
|
2023-08-01 19:19:04 -03:00
|
|
|
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(),
|
2023-09-18 14:57:57 -04:00
|
|
|
selectedAtIndex:
|
|
|
|
sendViewModel.currencies.indexOf(sendViewModel.selectedCryptoCurrency),
|
2023-06-09 19:29:34 -03:00
|
|
|
title: S.of(context).please_select,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2023-09-18 14:57:57 -04:00
|
|
|
onItemSelected: (CryptoCurrency cur) => sendViewModel.selectedCryptoCurrency = cur,
|
2023-06-09 19:29:34 -03:00
|
|
|
),
|
2022-03-30 17:57:04 +02:00
|
|
|
context: context);
|
|
|
|
}
|
2020-01-04 21:31:52 +02:00
|
|
|
}
|