2022-09-21 21:59:52 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-10-03 00:54:35 +00:00
|
|
|
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/models/trade_wallet_lookup.dart';
|
|
|
|
import 'package:stackwallet/pages/pinpad_views/lock_screen_view.dart';
|
|
|
|
import 'package:stackwallet/pages/send_view/sub_widgets/sending_transaction_dialog.dart';
|
|
|
|
import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
|
|
|
import 'package:stackwallet/providers/exchange/trade_sent_from_stack_lookup_provider.dart';
|
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
|
|
|
import 'package:stackwallet/route_generator.dart';
|
2022-11-07 17:46:17 +00:00
|
|
|
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/format.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
|
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
|
|
|
|
class ConfirmChangeNowSendView extends ConsumerStatefulWidget {
|
|
|
|
const ConfirmChangeNowSendView({
|
|
|
|
Key? key,
|
|
|
|
required this.transactionInfo,
|
|
|
|
required this.walletId,
|
|
|
|
this.routeOnSuccessName = WalletView.routeName,
|
|
|
|
required this.trade,
|
2022-11-07 17:46:17 +00:00
|
|
|
this.shouldSendPublicFiroFunds,
|
2022-08-26 08:11:35 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
static const String routeName = "/confirmChangeNowSend";
|
|
|
|
|
|
|
|
final Map<String, dynamic> transactionInfo;
|
|
|
|
final String walletId;
|
|
|
|
final String routeOnSuccessName;
|
2022-10-03 00:54:35 +00:00
|
|
|
final Trade trade;
|
2022-11-07 17:46:17 +00:00
|
|
|
final bool? shouldSendPublicFiroFunds;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<ConfirmChangeNowSendView> createState() =>
|
|
|
|
_ConfirmChangeNowSendViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ConfirmChangeNowSendViewState
|
|
|
|
extends ConsumerState<ConfirmChangeNowSendView> {
|
|
|
|
late final Map<String, dynamic> transactionInfo;
|
|
|
|
late final String walletId;
|
|
|
|
late final String routeOnSuccessName;
|
2022-10-03 00:54:35 +00:00
|
|
|
late final Trade trade;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
Future<void> _attemptSend(BuildContext context) async {
|
2022-09-21 21:59:52 +00:00
|
|
|
unawaited(showDialog<void>(
|
2022-08-26 08:11:35 +00:00
|
|
|
context: context,
|
|
|
|
useSafeArea: false,
|
|
|
|
barrierDismissible: false,
|
|
|
|
builder: (context) {
|
|
|
|
return const SendingTransactionDialog();
|
|
|
|
},
|
2022-09-21 21:59:52 +00:00
|
|
|
));
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
final String note = transactionInfo["note"] as String? ?? "";
|
|
|
|
final manager =
|
|
|
|
ref.read(walletsChangeNotifierProvider).getManager(walletId);
|
|
|
|
|
|
|
|
try {
|
2022-11-07 17:46:17 +00:00
|
|
|
late final String txid;
|
|
|
|
|
|
|
|
if (widget.shouldSendPublicFiroFunds == true) {
|
|
|
|
txid = await (manager.wallet as FiroWallet)
|
|
|
|
.confirmSendPublic(txData: transactionInfo);
|
|
|
|
} else {
|
|
|
|
txid = await manager.confirmSend(txData: transactionInfo);
|
|
|
|
}
|
|
|
|
|
2022-09-21 21:59:52 +00:00
|
|
|
unawaited(manager.refresh());
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
// save note
|
2022-09-21 21:59:52 +00:00
|
|
|
await ref
|
2022-08-26 08:11:35 +00:00
|
|
|
.read(notesServiceChangeNotifierProvider(walletId))
|
|
|
|
.editOrAddNote(txid: txid, note: note);
|
|
|
|
|
|
|
|
await ref.read(tradeSentFromStackLookupProvider).save(
|
|
|
|
tradeWalletLookup: TradeWalletLookup(
|
|
|
|
uuid: const Uuid().v1(),
|
|
|
|
txid: txid,
|
2022-10-03 00:54:35 +00:00
|
|
|
tradeId: trade.tradeId,
|
2022-08-26 08:11:35 +00:00
|
|
|
walletIds: [walletId],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
// pop back to wallet
|
|
|
|
if (mounted) {
|
|
|
|
Navigator.of(context).popUntil(ModalRoute.withName(routeOnSuccessName));
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// pop sending dialog
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
2022-09-21 00:46:07 +00:00
|
|
|
await showDialog<dynamic>(
|
2022-08-26 08:11:35 +00:00
|
|
|
context: context,
|
|
|
|
useSafeArea: false,
|
|
|
|
barrierDismissible: true,
|
|
|
|
builder: (context) {
|
|
|
|
return StackDialog(
|
|
|
|
title: "Broadcast transaction failed",
|
|
|
|
message: e.toString(),
|
|
|
|
rightButton: TextButton(
|
2022-09-22 23:48:50 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.getSecondaryEnabledButtonColor(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
child: Text(
|
|
|
|
"Ok",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.button(context).copyWith(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondary,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
transactionInfo = widget.transactionInfo;
|
|
|
|
walletId = widget.walletId;
|
|
|
|
routeOnSuccessName = widget.routeOnSuccessName;
|
|
|
|
trade = widget.trade;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final managerProvider = ref.watch(walletsChangeNotifierProvider
|
|
|
|
.select((value) => value.getManagerProvider(walletId)));
|
|
|
|
return Scaffold(
|
2022-09-29 18:05:11 +00:00
|
|
|
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
|
2022-08-26 08:11:35 +00:00
|
|
|
appBar: AppBar(
|
2022-09-22 23:48:50 +00:00
|
|
|
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
|
2022-08-26 08:11:35 +00:00
|
|
|
leading: AppBarBackButton(
|
|
|
|
onPressed: () async {
|
|
|
|
// if (FocusScope.of(context).hasFocus) {
|
|
|
|
// FocusScope.of(context).unfocus();
|
|
|
|
// await Future<void>.delayed(Duration(milliseconds: 50));
|
|
|
|
// }
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
"Confirm transaction",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.navBarTitle(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
body: LayoutBuilder(
|
|
|
|
builder: (builderContext, constraints) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 12,
|
|
|
|
top: 12,
|
|
|
|
right: 12,
|
|
|
|
),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minHeight: constraints.maxHeight - 24,
|
|
|
|
),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Send ${ref.watch(managerProvider.select((value) => value.coin)).ticker}",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.pageTitleH1(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Send from",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.smallMed12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
ref
|
|
|
|
.watch(walletsChangeNotifierProvider)
|
|
|
|
.getManager(walletId)
|
|
|
|
.walletName,
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-10-04 22:10:50 +00:00
|
|
|
"${trade.exchangeName} address",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.smallMed12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${transactionInfo["address"] ?? "ERROR"}",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Amount",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.smallMed12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${Format.satoshiAmountToPrettyString(
|
|
|
|
transactionInfo["recipientAmt"] as int,
|
|
|
|
ref.watch(
|
|
|
|
localeServiceChangeNotifierProvider
|
|
|
|
.select((value) => value.locale),
|
|
|
|
),
|
|
|
|
)} ${ref.watch(
|
|
|
|
managerProvider
|
|
|
|
.select((value) => value.coin),
|
|
|
|
).ticker}",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
textAlign: TextAlign.right,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Transaction fee",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.smallMed12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${Format.satoshiAmountToPrettyString(
|
|
|
|
transactionInfo["fee"] as int,
|
|
|
|
ref.watch(
|
|
|
|
localeServiceChangeNotifierProvider
|
|
|
|
.select((value) => value.locale),
|
|
|
|
),
|
|
|
|
)} ${ref.watch(
|
|
|
|
managerProvider
|
|
|
|
.select((value) => value.coin),
|
|
|
|
).ticker}",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
textAlign: TextAlign.right,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Note",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.smallMed12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
transactionInfo["note"] as String? ?? "",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Trade ID",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.smallMed12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
Text(
|
2022-10-03 00:54:35 +00:00
|
|
|
trade.tradeId,
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
textAlign: TextAlign.right,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
RoundedContainer(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.snackBarBackSuccess,
|
2022-08-26 08:11:35 +00:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Total amount",
|
2022-09-30 22:43:45 +00:00
|
|
|
style:
|
|
|
|
STextStyles.titleBold12(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textConfirmTotalAmount,
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${Format.satoshiAmountToPrettyString(
|
|
|
|
(transactionInfo["fee"] as int) +
|
|
|
|
(transactionInfo["recipientAmt"] as int),
|
|
|
|
ref.watch(
|
|
|
|
localeServiceChangeNotifierProvider
|
|
|
|
.select((value) => value.locale),
|
|
|
|
),
|
|
|
|
)} ${ref.watch(
|
|
|
|
managerProvider
|
|
|
|
.select((value) => value.coin),
|
|
|
|
).ticker}",
|
2022-09-30 22:43:45 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textConfirmTotalAmount,
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
textAlign: TextAlign.right,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 16,
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
TextButton(
|
2022-09-22 23:48:50 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-09-21 21:59:52 +00:00
|
|
|
.getPrimaryEnabledButtonColor(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
onPressed: () async {
|
|
|
|
final unlocked = await Navigator.push(
|
|
|
|
context,
|
|
|
|
RouteGenerator.getRoute(
|
|
|
|
shouldUseMaterialRoute:
|
|
|
|
RouteGenerator.useMaterialPageRoute,
|
|
|
|
builder: (_) => const LockscreenView(
|
|
|
|
showBackButton: true,
|
|
|
|
popOnSuccess: true,
|
|
|
|
routeOnSuccessArguments: true,
|
|
|
|
routeOnSuccess: "",
|
|
|
|
biometricsCancelButtonString: "CANCEL",
|
|
|
|
biometricsLocalizedReason:
|
|
|
|
"Authenticate to send transaction",
|
|
|
|
biometricsAuthenticationTitle:
|
|
|
|
"Confirm Transaction",
|
|
|
|
),
|
|
|
|
settings: const RouteSettings(
|
|
|
|
name: "/confirmsendlockscreen"),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (unlocked is bool && unlocked && mounted) {
|
2022-09-21 21:59:52 +00:00
|
|
|
await _attemptSend(context);
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
"Send",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.button(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|