2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
|
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
2023-01-20 18:25:32 +00:00
|
|
|
import 'package:stackwallet/exceptions/wallet/insufficient_balance_exception.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
|
2023-01-09 19:57:12 +00:00
|
|
|
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/pages/paynym/dialogs/confirm_paynym_connect_dialog.dart';
|
|
|
|
import 'package:stackwallet/pages/paynym/subwidgets/paynym_bot.dart';
|
|
|
|
import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart';
|
2023-02-10 18:07:57 +00:00
|
|
|
import 'package:stackwallet/pages_desktop_specific/my_stack_view/paynym/desktop_paynym_send_dialog.dart';
|
2023-04-05 22:06:31 +00:00
|
|
|
import 'package:stackwallet/providers/global/locale_provider.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
2023-11-03 19:46:55 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2023-11-03 19:46:55 +00:00
|
|
|
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
|
|
|
import 'package:stackwallet/wallets/models/tx_data.dart';
|
2023-11-16 22:25:20 +00:00
|
|
|
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/paynym_interface.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/custom_buttons/paynym_follow_toggle_button.dart';
|
2023-01-09 21:47:40 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
2023-01-09 19:57:12 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
2023-01-09 19:15:15 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
|
|
|
|
class DesktopPaynymDetails extends ConsumerStatefulWidget {
|
|
|
|
const DesktopPaynymDetails({
|
|
|
|
Key? key,
|
|
|
|
required this.walletId,
|
|
|
|
required this.accountLite,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String walletId;
|
|
|
|
final PaynymAccountLite accountLite;
|
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<DesktopPaynymDetails> createState() =>
|
|
|
|
_PaynymDetailsPopupState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PaynymDetailsPopupState extends ConsumerState<DesktopPaynymDetails> {
|
2023-01-09 19:57:12 +00:00
|
|
|
bool _showInsufficientFundsInfo = false;
|
|
|
|
|
2023-01-09 19:15:15 +00:00
|
|
|
Future<void> _onConnectPressed() async {
|
|
|
|
bool canPop = false;
|
|
|
|
unawaited(
|
|
|
|
showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => WillPopScope(
|
|
|
|
onWillPop: () async => canPop,
|
|
|
|
child: const LoadingIndicator(
|
|
|
|
width: 200,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-11-03 19:46:55 +00:00
|
|
|
final wallet =
|
2023-11-16 16:54:57 +00:00
|
|
|
ref.read(pWallets).getWallet(widget.walletId) as PaynymInterface;
|
2023-01-09 19:15:15 +00:00
|
|
|
|
2023-01-23 21:39:05 +00:00
|
|
|
if (await wallet.hasConnected(widget.accountLite.code)) {
|
2023-01-09 19:15:15 +00:00
|
|
|
canPop = true;
|
2023-01-09 19:57:12 +00:00
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
2023-01-09 19:15:15 +00:00
|
|
|
// TODO show info popup
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-03 19:46:55 +00:00
|
|
|
final rates = await ref.read(pWallets).getWallet(widget.walletId).fees;
|
2023-01-09 19:15:15 +00:00
|
|
|
|
2023-11-03 19:46:55 +00:00
|
|
|
TxData preparedTx;
|
2023-01-09 19:15:15 +00:00
|
|
|
|
|
|
|
try {
|
2023-01-23 18:19:13 +00:00
|
|
|
preparedTx = await wallet.prepareNotificationTx(
|
2023-01-09 19:15:15 +00:00
|
|
|
selectedTxFeeRate: rates.medium,
|
|
|
|
targetPaymentCodeString: widget.accountLite.code,
|
|
|
|
);
|
|
|
|
} on InsufficientBalanceException catch (e) {
|
|
|
|
if (mounted) {
|
|
|
|
canPop = true;
|
2023-01-09 19:57:12 +00:00
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
2023-01-09 19:15:15 +00:00
|
|
|
}
|
2023-01-09 19:57:12 +00:00
|
|
|
setState(() {
|
|
|
|
_showInsufficientFundsInfo = true;
|
|
|
|
});
|
2023-01-09 19:15:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
// We have enough balance and prepared tx should be good to go.
|
|
|
|
|
|
|
|
canPop = true;
|
|
|
|
// close loading
|
2023-01-09 19:57:12 +00:00
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
2023-01-09 19:15:15 +00:00
|
|
|
|
|
|
|
// show info pop up
|
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ConfirmPaynymConnectDialog(
|
|
|
|
nymName: widget.accountLite.nymName,
|
2023-04-05 22:06:31 +00:00
|
|
|
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
2023-01-09 19:15:15 +00:00
|
|
|
onConfirmPressed: () {
|
2023-01-09 21:47:40 +00:00
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
unawaited(
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => DesktopDialog(
|
|
|
|
maxHeight: double.infinity,
|
|
|
|
maxWidth: 580,
|
|
|
|
child: ConfirmTransactionView(
|
2023-11-03 19:46:55 +00:00
|
|
|
walletId: widget.walletId,
|
2023-01-09 21:47:40 +00:00
|
|
|
isPaynymNotificationTransaction: true,
|
2023-11-03 19:46:55 +00:00
|
|
|
txData: preparedTx,
|
2024-01-04 18:52:00 +00:00
|
|
|
onSuccess: () {
|
|
|
|
// do nothing extra
|
|
|
|
},
|
2023-01-09 21:47:40 +00:00
|
|
|
onSuccessInsteadOfRouteOnSuccess: () {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
unawaited(
|
|
|
|
showFloatingFlushBar(
|
|
|
|
type: FlushBarType.success,
|
|
|
|
message:
|
|
|
|
"Connection initiated to ${widget.accountLite.nymName}",
|
|
|
|
iconAsset: Assets.svg.copy,
|
|
|
|
context: context,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-01-09 19:15:15 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-11-03 19:46:55 +00:00
|
|
|
amount: preparedTx.amount! + preparedTx.fee!,
|
|
|
|
coin: ref.read(pWalletCoin(widget.walletId)),
|
2023-01-09 19:15:15 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-09 21:48:32 +00:00
|
|
|
Future<void> _onSend() async {
|
2023-02-10 18:07:57 +00:00
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => DesktopPaynymSendDialog(
|
|
|
|
walletId: widget.walletId,
|
|
|
|
accountLite: widget.accountLite,
|
|
|
|
),
|
|
|
|
);
|
2023-01-09 21:48:32 +00:00
|
|
|
}
|
|
|
|
|
2023-01-09 19:15:15 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-11-03 19:46:55 +00:00
|
|
|
final wallet = ref.watch(pWallets).getWallet(widget.walletId);
|
2023-01-26 16:59:15 +00:00
|
|
|
|
2023-11-16 16:54:57 +00:00
|
|
|
final paynymWallet = wallet as PaynymInterface;
|
2023-01-26 16:59:15 +00:00
|
|
|
|
2023-01-09 19:15:15 +00:00
|
|
|
return RoundedWhiteContainer(
|
|
|
|
padding: const EdgeInsets.all(0),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
PayNymBot(
|
|
|
|
paymentCodeString: widget.accountLite.code,
|
2023-02-01 21:02:41 +00:00
|
|
|
size: 36,
|
2023-01-09 19:15:15 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
2023-01-31 23:46:30 +00:00
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
widget.accountLite.nymName,
|
|
|
|
style: STextStyles.desktopTextSmall(context),
|
|
|
|
),
|
|
|
|
FutureBuilder(
|
2023-11-03 19:46:55 +00:00
|
|
|
future: paynymWallet
|
|
|
|
.hasConnected(widget.accountLite.code),
|
2023-01-31 23:46:30 +00:00
|
|
|
builder: (context, AsyncSnapshot<bool> snapshot) {
|
|
|
|
if (snapshot.connectionState ==
|
|
|
|
ConnectionState.done &&
|
|
|
|
snapshot.data == true) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"Connected",
|
|
|
|
style: STextStyles.desktopTextSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorGreen,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2023-01-09 19:15:15 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
2023-01-23 21:39:05 +00:00
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder(
|
2023-11-03 19:46:55 +00:00
|
|
|
future:
|
|
|
|
paynymWallet.hasConnected(widget.accountLite.code),
|
2023-01-23 21:39:05 +00:00
|
|
|
builder: (context, AsyncSnapshot<bool> snapshot) {
|
|
|
|
if (snapshot.connectionState ==
|
|
|
|
ConnectionState.done &&
|
|
|
|
snapshot.hasData) {
|
|
|
|
if (snapshot.data!) {
|
|
|
|
return PrimaryButton(
|
|
|
|
label: "Send",
|
|
|
|
buttonHeight: ButtonHeight.s,
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.circleArrowUpRight,
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextPrimary,
|
|
|
|
),
|
|
|
|
iconSpacing: 6,
|
|
|
|
onPressed: _onSend,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return PrimaryButton(
|
|
|
|
label: "Connect",
|
|
|
|
buttonHeight: ButtonHeight.s,
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.circlePlusFilled,
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextPrimary,
|
|
|
|
),
|
|
|
|
iconSpacing: 6,
|
|
|
|
onPressed: _onConnectPressed,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return const SizedBox(
|
|
|
|
height: 100,
|
|
|
|
child: LoadingIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2023-01-09 19:15:15 +00:00
|
|
|
),
|
2023-01-23 21:39:05 +00:00
|
|
|
),
|
2023-01-09 19:15:15 +00:00
|
|
|
const SizedBox(
|
|
|
|
width: 20,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: PaynymFollowToggleButton(
|
|
|
|
walletId: widget.walletId,
|
|
|
|
paymentCodeStringToFollow: widget.accountLite.code,
|
|
|
|
style: PaynymFollowToggleButtonStyle.detailsDesktop,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-01-09 19:57:12 +00:00
|
|
|
if (_showInsufficientFundsInfo)
|
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
const SizedBox(
|
|
|
|
height: 24,
|
|
|
|
),
|
|
|
|
RoundedContainer(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.warningBackground,
|
|
|
|
child: Text(
|
|
|
|
"Adding a PayNym to your contacts requires a one-time "
|
|
|
|
"transaction fee for creating the record on the "
|
|
|
|
"blockchain. Please deposit more "
|
2023-11-03 19:46:55 +00:00
|
|
|
"${ref.watch(pWalletCoin(widget.walletId)).ticker} "
|
2023-01-09 19:57:12 +00:00
|
|
|
"into your wallet and try again.",
|
|
|
|
style: STextStyles.desktopTextExtraExtraSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.warningForeground,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-01-09 19:15:15 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.backgroundAppBar,
|
|
|
|
height: 1,
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"PayNym address",
|
|
|
|
style: STextStyles.desktopTextExtraExtraSmall(context),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(minHeight: 100),
|
|
|
|
child: Text(
|
|
|
|
widget.accountLite.code,
|
|
|
|
style: STextStyles.desktopTextExtraExtraSmall(context)
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textDark,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 20,
|
|
|
|
),
|
2023-06-05 13:40:56 +00:00
|
|
|
QrImageView(
|
2023-01-09 19:15:15 +00:00
|
|
|
padding: const EdgeInsets.all(0),
|
|
|
|
size: 100,
|
|
|
|
data: widget.accountLite.code,
|
|
|
|
foregroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.textDark,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
2023-01-30 21:34:21 +00:00
|
|
|
CustomTextButton(
|
2023-01-09 19:15:15 +00:00
|
|
|
text: "Copy",
|
|
|
|
onTap: () async {
|
|
|
|
await Clipboard.setData(
|
|
|
|
ClipboardData(
|
|
|
|
text: widget.accountLite.code,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
unawaited(
|
|
|
|
showFloatingFlushBar(
|
|
|
|
type: FlushBarType.info,
|
|
|
|
message: "Copied to clipboard",
|
|
|
|
iconAsset: Assets.svg.copy,
|
|
|
|
context: context,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|