2023-01-05 22:19:02 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2023-01-06 22:31:36 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-01-05 22:19:02 +00:00
|
|
|
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-05 22:19:02 +00:00
|
|
|
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
|
|
|
|
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
2023-01-06 22:31:36 +00:00
|
|
|
import 'package:stackwallet/pages/paynym/dialogs/confirm_paynym_connect_dialog.dart';
|
2023-01-09 21:46:52 +00:00
|
|
|
import 'package:stackwallet/pages/paynym/paynym_home_view.dart';
|
2023-01-05 22:19:02 +00:00
|
|
|
import 'package:stackwallet/pages/paynym/subwidgets/paynym_bot.dart';
|
2023-01-06 22:31:36 +00:00
|
|
|
import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart';
|
2023-01-26 17:46:16 +00:00
|
|
|
import 'package:stackwallet/pages/send_view/send_view.dart';
|
2023-04-05 22:06:31 +00:00
|
|
|
import 'package:stackwallet/providers/global/locale_provider.dart';
|
2023-01-06 22:31:36 +00:00
|
|
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
|
|
|
import 'package:stackwallet/route_generator.dart';
|
2023-01-26 16:59:15 +00:00
|
|
|
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
|
2023-04-06 21:24:56 +00:00
|
|
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
2023-01-05 22:19:02 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
2023-01-09 19:57:12 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
2023-01-05 22:19:02 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
|
|
|
import 'package:stackwallet/widgets/custom_buttons/paynym_follow_toggle_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
|
|
|
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
2023-01-06 22:31:36 +00:00
|
|
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
2023-01-09 19:57:12 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
2023-02-22 21:06:45 +00:00
|
|
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
2023-01-26 17:46:16 +00:00
|
|
|
import 'package:tuple/tuple.dart';
|
2023-01-05 22:19:02 +00:00
|
|
|
|
2023-01-06 22:31:36 +00:00
|
|
|
class PaynymDetailsPopup extends ConsumerStatefulWidget {
|
2023-01-05 22:19:02 +00:00
|
|
|
const PaynymDetailsPopup({
|
|
|
|
Key? key,
|
|
|
|
required this.walletId,
|
|
|
|
required this.accountLite,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String walletId;
|
|
|
|
final PaynymAccountLite accountLite;
|
|
|
|
|
|
|
|
@override
|
2023-01-06 22:31:36 +00:00
|
|
|
ConsumerState<PaynymDetailsPopup> createState() => _PaynymDetailsPopupState();
|
2023-01-05 22:19:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-06 22:31:36 +00:00
|
|
|
class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
|
2023-01-09 19:57:12 +00:00
|
|
|
bool _showInsufficientFundsInfo = false;
|
|
|
|
|
2023-01-23 21:39:05 +00:00
|
|
|
Future<void> _onSend() async {
|
2023-01-26 17:46:16 +00:00
|
|
|
final manager =
|
|
|
|
ref.read(walletsChangeNotifierProvider).getManager(widget.walletId);
|
|
|
|
await Navigator.of(context).pushNamed(
|
|
|
|
SendView.routeName,
|
|
|
|
arguments: Tuple3(
|
|
|
|
manager.walletId,
|
|
|
|
manager.coin,
|
|
|
|
widget.accountLite,
|
|
|
|
),
|
|
|
|
);
|
2023-01-23 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
2023-01-06 22:31:36 +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-01-26 16:59:15 +00:00
|
|
|
final manager =
|
|
|
|
ref.read(walletsChangeNotifierProvider).getManager(widget.walletId);
|
|
|
|
|
|
|
|
final wallet = manager.wallet as PaynymWalletInterface;
|
2023-01-06 22:31:36 +00:00
|
|
|
|
2023-01-23 21:39:05 +00:00
|
|
|
if (await wallet.hasConnected(widget.accountLite.code)) {
|
2023-01-06 22:31:36 +00:00
|
|
|
canPop = true;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
// TODO show info popup
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-26 16:59:15 +00:00
|
|
|
final rates = await manager.fees;
|
2023-01-06 22:31:36 +00:00
|
|
|
|
|
|
|
Map<String, dynamic> preparedTx;
|
|
|
|
|
|
|
|
try {
|
2023-01-23 18:19:13 +00:00
|
|
|
preparedTx = await wallet.prepareNotificationTx(
|
2023-01-06 22:31:36 +00:00
|
|
|
selectedTxFeeRate: rates.medium,
|
|
|
|
targetPaymentCodeString: widget.accountLite.code,
|
|
|
|
);
|
2023-01-09 19:57:12 +00:00
|
|
|
} on InsufficientBalanceException catch (_) {
|
2023-01-06 22:31:36 +00:00
|
|
|
if (mounted) {
|
|
|
|
canPop = true;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
2023-01-09 19:57:12 +00:00
|
|
|
setState(() {
|
|
|
|
_showInsufficientFundsInfo = true;
|
|
|
|
});
|
2023-01-06 22:31:36 +00:00
|
|
|
return;
|
2023-02-22 21:06:45 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (mounted) {
|
|
|
|
canPop = true;
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => StackOkDialog(
|
|
|
|
title: "Error",
|
|
|
|
message: e.toString(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return;
|
2023-01-06 22:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
// We have enough balance and prepared tx should be good to go.
|
|
|
|
|
|
|
|
canPop = true;
|
|
|
|
// close loading
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
|
|
|
// Close details
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
|
|
|
// 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-06 22:31:36 +00:00
|
|
|
onConfirmPressed: () {
|
|
|
|
//
|
|
|
|
print("CONFIRM NOTIF TX: $preparedTx");
|
|
|
|
|
|
|
|
Navigator.of(context).push(
|
|
|
|
RouteGenerator.getRoute(
|
|
|
|
builder: (_) => ConfirmTransactionView(
|
2023-01-26 16:59:15 +00:00
|
|
|
walletId: manager.walletId,
|
2023-01-09 21:46:52 +00:00
|
|
|
routeOnSuccessName: PaynymHomeView.routeName,
|
|
|
|
isPaynymNotificationTransaction: true,
|
2023-01-06 22:31:36 +00:00
|
|
|
transactionInfo: {
|
|
|
|
"hex": preparedTx["hex"],
|
2023-01-09 21:46:52 +00:00
|
|
|
"address": preparedTx["recipientPaynym"],
|
2023-01-06 22:31:36 +00:00
|
|
|
"recipientAmt": preparedTx["amount"],
|
|
|
|
"fee": preparedTx["fee"],
|
|
|
|
"vSize": preparedTx["vSize"],
|
|
|
|
"note": "PayNym connect"
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-04-05 22:06:31 +00:00
|
|
|
amount: (preparedTx["amount"] as Amount) +
|
2023-04-06 20:21:49 +00:00
|
|
|
(preparedTx["fee"] as int).toAmountAsRaw(
|
2023-04-05 22:06:31 +00:00
|
|
|
fractionDigits: manager.coin.decimals,
|
|
|
|
),
|
2023-01-26 16:59:15 +00:00
|
|
|
coin: manager.coin,
|
2023-01-06 22:31:36 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 22:19:02 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-01-26 16:59:15 +00:00
|
|
|
final manager = ref.watch(walletsChangeNotifierProvider
|
|
|
|
.select((value) => value.getManager(widget.walletId)));
|
|
|
|
|
|
|
|
final wallet = manager.wallet as PaynymWalletInterface;
|
2023-01-23 21:39:05 +00:00
|
|
|
|
2023-01-05 22:19:02 +00:00
|
|
|
return DesktopDialog(
|
|
|
|
maxWidth: MediaQuery.of(context).size.width - 32,
|
|
|
|
maxHeight: double.infinity,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
top: 24,
|
|
|
|
right: 24,
|
|
|
|
bottom: 16,
|
|
|
|
),
|
2023-01-09 19:57:12 +00:00
|
|
|
child: Column(
|
2023-01-05 22:19:02 +00:00
|
|
|
children: [
|
|
|
|
Row(
|
2023-01-09 19:57:12 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2023-01-05 22:19:02 +00:00
|
|
|
children: [
|
2023-01-09 19:57:12 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
PayNymBot(
|
|
|
|
paymentCodeString: widget.accountLite.code,
|
2023-02-01 21:02:41 +00:00
|
|
|
size: 36,
|
2023-01-09 19:57:12 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
2023-01-31 23:46:30 +00:00
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
widget.accountLite.nymName,
|
2023-02-01 21:02:41 +00:00
|
|
|
style: STextStyles.w600_14(context),
|
2023-01-31 23:46:30 +00:00
|
|
|
),
|
|
|
|
FutureBuilder(
|
|
|
|
future:
|
|
|
|
wallet.hasConnected(widget.accountLite.code),
|
|
|
|
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",
|
2023-02-01 21:02:41 +00:00
|
|
|
style: STextStyles.w500_12(context)
|
2023-01-31 23:46:30 +00:00
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorGreen,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2023-01-09 19:57:12 +00:00
|
|
|
),
|
|
|
|
],
|
2023-01-05 22:19:02 +00:00
|
|
|
),
|
2023-01-23 21:39:05 +00:00
|
|
|
FutureBuilder(
|
|
|
|
future: wallet.hasConnected(widget.accountLite.code),
|
|
|
|
builder: (context, AsyncSnapshot<bool> snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.done &&
|
|
|
|
snapshot.hasData) {
|
|
|
|
if (snapshot.data!) {
|
|
|
|
return PrimaryButton(
|
|
|
|
label: "Send",
|
2023-02-01 21:02:41 +00:00
|
|
|
buttonHeight: ButtonHeight.xl,
|
2023-01-23 21:39:05 +00:00
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.circleArrowUpRight,
|
2023-02-01 21:02:41 +00:00
|
|
|
width: 14,
|
|
|
|
height: 14,
|
2023-01-23 21:39:05 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextPrimary,
|
|
|
|
),
|
2023-02-01 21:02:41 +00:00
|
|
|
iconSpacing: 8,
|
|
|
|
width: 100,
|
2023-01-23 21:39:05 +00:00
|
|
|
onPressed: _onSend,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return PrimaryButton(
|
|
|
|
label: "Connect",
|
2023-02-01 21:02:41 +00:00
|
|
|
buttonHeight: ButtonHeight.xl,
|
2023-01-23 21:39:05 +00:00
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.circlePlusFilled,
|
2023-02-01 21:02:41 +00:00
|
|
|
width: 13,
|
|
|
|
height: 13,
|
2023-01-23 21:39:05 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextPrimary,
|
|
|
|
),
|
2023-02-01 21:02:41 +00:00
|
|
|
iconSpacing: 8,
|
|
|
|
width: 128,
|
2023-01-23 21:39:05 +00:00
|
|
|
onPressed: _onConnectPressed,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return const SizedBox(
|
2023-01-23 21:42:39 +00:00
|
|
|
height: 32,
|
2023-01-23 21:39:05 +00:00
|
|
|
child: LoadingIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2023-01-05 22:19:02 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
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 "
|
|
|
|
"${ref.read(walletsChangeNotifierProvider).getManager(widget.walletId).wallet.coin.ticker} "
|
|
|
|
"into your wallet and try again.",
|
|
|
|
style: STextStyles.infoSmall(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.warningForeground,
|
2023-02-01 21:02:41 +00:00
|
|
|
fontSize: 12,
|
2023-01-09 19:57:12 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-01-05 22:19:02 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.backgroundAppBar,
|
|
|
|
height: 1,
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
top: 16,
|
|
|
|
right: 24,
|
|
|
|
bottom: 16,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(minHeight: 86),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"PayNym address",
|
2023-02-01 21:02:41 +00:00
|
|
|
style: STextStyles.infoSmall(context).copyWith(
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
2023-01-05 22:19:02 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 6,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
widget.accountLite.code,
|
|
|
|
style: STextStyles.infoSmall(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textDark,
|
2023-02-01 21:02:41 +00:00
|
|
|
fontSize: 12,
|
2023-01-05 22:19:02 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 6,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 20,
|
|
|
|
),
|
|
|
|
QrImage(
|
|
|
|
padding: const EdgeInsets.all(0),
|
2023-02-01 21:02:41 +00:00
|
|
|
size: 100,
|
2023-01-05 22:19:02 +00:00
|
|
|
data: widget.accountLite.code,
|
|
|
|
foregroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.textDark,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
right: 24,
|
|
|
|
bottom: 24,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: PaynymFollowToggleButton(
|
|
|
|
walletId: widget.walletId,
|
|
|
|
paymentCodeStringToFollow: widget.accountLite.code,
|
|
|
|
style: PaynymFollowToggleButtonStyle.detailsPopup,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: SecondaryButton(
|
|
|
|
label: "Copy",
|
2023-02-01 21:02:41 +00:00
|
|
|
buttonHeight: ButtonHeight.xl,
|
|
|
|
iconSpacing: 8,
|
2023-01-05 22:19:02 +00:00
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.copy,
|
2023-02-01 21:02:41 +00:00
|
|
|
width: 12,
|
|
|
|
height: 12,
|
2023-01-05 22:19:02 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondary,
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
await Clipboard.setData(
|
|
|
|
ClipboardData(
|
|
|
|
text: widget.accountLite.code,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
unawaited(
|
|
|
|
showFloatingFlushBar(
|
|
|
|
type: FlushBarType.info,
|
|
|
|
message: "Copied to clipboard",
|
|
|
|
iconAsset: Assets.svg.copy,
|
|
|
|
context: context,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|