Skip to content

Commit

Permalink
add transaction success info page
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii-Borodenko committed Dec 13, 2024
1 parent 489a409 commit 1f8db52
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 90 deletions.
4 changes: 4 additions & 0 deletions lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import 'package:cake_wallet/entities/wallet_manager.dart';
import 'package:cake_wallet/src/screens/buy/buy_sell_options_page.dart';
import 'package:cake_wallet/src/screens/buy/payment_method_options_page.dart';
import 'package:cake_wallet/src/screens/receive/address_list_page.dart';
import 'package:cake_wallet/src/screens/send/transaction_success_info_page.dart';
import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart';
import 'package:cake_wallet/src/screens/settings/mweb_logs_page.dart';
import 'package:cake_wallet/src/screens/settings/mweb_node_page.dart';
Expand Down Expand Up @@ -1175,6 +1176,9 @@ Future<void> setup({
getIt.registerFactoryParam<PreSeedPage, int, void>(
(seedPhraseLength, _) => PreSeedPage(seedPhraseLength));

getIt.registerFactoryParam<TransactionSuccessPage, String, void>(
(content, _) => TransactionSuccessPage(content: content));

getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) =>
TradeDetailsViewModel(
tradeForDetails: trade,
Expand Down
5 changes: 5 additions & 0 deletions lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import 'package:cake_wallet/src/screens/seed/pre_seed_page.dart';
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
import 'package:cake_wallet/src/screens/send/send_page.dart';
import 'package:cake_wallet/src/screens/send/send_template_page.dart';
import 'package:cake_wallet/src/screens/send/transaction_success_info_page.dart';
import 'package:cake_wallet/src/screens/settings/connection_sync_page.dart';
import 'package:cake_wallet/src/screens/settings/desktop_settings/desktop_settings_page.dart';
import 'package:cake_wallet/src/screens/settings/display_settings_page.dart';
Expand Down Expand Up @@ -585,6 +586,10 @@ Route<dynamic> createRoute(RouteSettings settings) {
return MaterialPageRoute<void>(
builder: (_) => getIt.get<PreSeedPage>(param1: settings.arguments as int));

case Routes.transactionSuccessPage:
return MaterialPageRoute<void>(
builder: (_) => getIt.get<TransactionSuccessPage>(param1: settings.arguments as String));

case Routes.backup:
return CupertinoPageRoute<void>(
fullscreenDialog: true, builder: (_) => getIt.get<BackupPage>());
Expand Down
1 change: 1 addition & 0 deletions lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Routes {
static const restoreWalletType = '/restore_wallet_type';
static const restoreWallet = '/restore_wallet';
static const preSeedPage = '/pre_seed_page';
static const transactionSuccessPage = '/transaction_success_info_page';
static const backup = '/backup';
static const editBackupPassword = '/edit_backup_passowrd';
static const restoreFromBackup = '/restore_from_backup';
Expand Down
148 changes: 58 additions & 90 deletions lib/src/screens/send/send_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -500,95 +500,6 @@ class SendPage extends BasePage {
actionRightButton: () async {
Navigator.of(_dialogContext).pop();
sendViewModel.commitTransaction(context);
await showPopUp<void>(
context: context,
builder: (BuildContext _dialogContext) {
return Observer(builder: (_) {
final state = sendViewModel.state;

if (state is FailureState) {
Navigator.of(_dialogContext).pop();
}

if (state is TransactionCommitted) {
newContactAddress =
newContactAddress ?? sendViewModel.newContactAddress();

if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) {
newContactAddress = null;
}

final successMessage = S.of(_dialogContext).send_success(
sendViewModel.selectedCryptoCurrency.toString());

final waitMessage = sendViewModel.walletType == WalletType.solana
? '. ${S.of(_dialogContext).waitFewSecondForTxUpdate}'
: '';

final newContactMessage = newContactAddress != null && sendViewModel.showAddressBookPopup
? '\n${S.of(_dialogContext).add_contact_to_address_book}'
: '';

String alertContent =
"$successMessage$waitMessage$newContactMessage";

if (newContactMessage.isNotEmpty) {
return AlertWithTwoActions(
alertDialogKey: ValueKey('send_page_sent_dialog_key'),
alertTitle: '',
alertContent: alertContent,
rightButtonText: S.of(_dialogContext).add_contact,
leftButtonText: S.of(_dialogContext).ignor,
alertLeftActionButtonKey:
ValueKey('send_page_sent_dialog_ignore_button_key'),
alertRightActionButtonKey: ValueKey(
'send_page_sent_dialog_add_contact_button_key'),
actionRightButton: () {
Navigator.of(_dialogContext).pop();
RequestReviewHandler.requestReview();
Navigator.of(context).pushNamed(
Routes.addressBookAddContact,
arguments: newContactAddress);
newContactAddress = null;
},
actionLeftButton: () {
Navigator.of(_dialogContext).pop();
RequestReviewHandler.requestReview();
newContactAddress = null;
});
} else {
if (initialPaymentRequest?.callbackMessage?.isNotEmpty ??
false) {
alertContent = initialPaymentRequest!.callbackMessage!;
}
return AlertWithOneAction(
alertTitle: '',
alertContent: alertContent,
buttonText: S.of(_dialogContext).ok,
buttonAction: () {
Navigator.of(_dialogContext).pop();
RequestReviewHandler.requestReview();
});
}
}

return Offstage();
});
});
if (state is TransactionCommitted) {
if (initialPaymentRequest?.callbackUrl?.isNotEmpty ?? false) {
// wait a second so it's not as jarring:
await Future.delayed(Duration(seconds: 1));
try {
launchUrl(
Uri.parse(initialPaymentRequest!.callbackUrl!),
mode: LaunchMode.externalApplication,
);
} catch (e) {
printV(e);
}
}
}
},
actionLeftButton: () => Navigator.of(_dialogContext).pop());
});
Expand All @@ -597,7 +508,64 @@ class SendPage extends BasePage {
}

if (state is TransactionCommitted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) async {

final successMessage = S.of(context).send_success(
sendViewModel.selectedCryptoCurrency.toString());

final waitMessage = sendViewModel.walletType == WalletType.solana
? '. ${S.of(context).waitFewSecondForTxUpdate}'
: '';

String alertContent = "$successMessage$waitMessage";

await Navigator.of(context).pushNamed(
Routes.transactionSuccessPage,
arguments: alertContent
);

newContactAddress = newContactAddress ?? sendViewModel.newContactAddress();
if (sendViewModel.coinTypeToSpendFrom != UnspentCoinType.any) newContactAddress = null;

if (newContactAddress != null && sendViewModel.showAddressBookPopup) {
await showPopUp<void>(
context: context,
builder: (BuildContext _dialogContext) => AlertWithTwoActions(
alertDialogKey: ValueKey('send_page_sent_dialog_key'),
alertTitle: '',
alertContent: S.of(_dialogContext).add_contact_to_address_book,
rightButtonText: S.of(_dialogContext).add_contact,
leftButtonText: S.of(_dialogContext).ignor,
alertLeftActionButtonKey: ValueKey('send_page_sent_dialog_ignore_button_key'),
alertRightActionButtonKey:
ValueKey('send_page_sent_dialog_add_contact_button_key'),
actionRightButton: () {
Navigator.of(_dialogContext).pop();
RequestReviewHandler.requestReview();
Navigator.of(context)
.pushNamed(Routes.addressBookAddContact, arguments: newContactAddress);
newContactAddress = null;
},
actionLeftButton: () {
Navigator.of(_dialogContext).pop();
RequestReviewHandler.requestReview();
newContactAddress = null;
}));
}

if (initialPaymentRequest?.callbackUrl?.isNotEmpty ?? false) {
// wait a second so it's not as jarring:
await Future.delayed(Duration(seconds: 1));
try {
launchUrl(
Uri.parse(initialPaymentRequest!.callbackUrl!),
mode: LaunchMode.externalApplication,
);
} catch (e) {
printV(e);
}
}

sendViewModel.clearOutputs();
});
}
Expand Down
32 changes: 32 additions & 0 deletions lib/src/screens/send/transaction_success_info_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/Info_page.dart';
import 'package:flutter/cupertino.dart';

class TransactionSuccessPage extends InfoPage {
TransactionSuccessPage({required this.content})
: super(
imageLightPath: 'assets/images/birthday_cake.png',
imageDarkPath: 'assets/images/birthday_cake.png',
);

final String content;

@override
bool get onWillPop => false;

@override
String get pageTitle => 'Transaction Sent Successfully';

@override
String get pageDescription => content;

@override
String get buttonText => S.current.ok;

@override
Key? get buttonKey => ValueKey('transaction_success_info_page_button_key');

@override
void Function(BuildContext) get onPressed =>
(BuildContext context) => Navigator.of(context).pop();
}

0 comments on commit 1f8db52

Please sign in to comment.