Skip to content

Commit

Permalink
Remove P2P swap warning banner and add a warning modal
Browse files Browse the repository at this point in the history
  • Loading branch information
vilkris4 committed Aug 19, 2023
1 parent 22d0fb7 commit 7b265dc
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 84 deletions.
2 changes: 2 additions & 0 deletions lib/utils/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,5 @@ const Duration kMaxAllowedInitialHtlcDuration = Duration(hours: 24);
const Duration kMinSafeTimeToFindPreimage = Duration(hours: 7);
const Duration kMinSafeTimeToCompleteSwap = Duration(minutes: 10);
const Duration kHtlcExpirationWarningThreshold = Duration(minutes: 20);
const String kHasReadP2pSwapWarningKey = 'has_read_p2p_swap_warning';
const bool kHasReadP2pSwapWarningDefaultValue = false;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/reusable_widgets/modals/base_modal.dart';

class P2PSwapWarningModal extends StatefulWidget {
final Function() onAccepted;

const P2PSwapWarningModal({
required this.onAccepted,
Key? key,
}) : super(key: key);

@override
State<P2PSwapWarningModal> createState() => _P2PSwapWarningModalState();
}

class _P2PSwapWarningModalState extends State<P2PSwapWarningModal> {
@override
Widget build(BuildContext context) {
return BaseModal(
title: 'Before continuing',
child: _getContent(),
);
}

Widget _getContent() {
return Column(
children: [
const SizedBox(
height: 20.0,
),
const Text(
'''Please note that the P2P swap is an experimental feature and may result in funds being lost.\n\n'''
'''Use the feature with caution and consider splitting large swaps into multiple smaller ones.''',
style: TextStyle(
fontSize: 14.0,
),
),
const SizedBox(
height: 30.0,
),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => widget.onAccepted.call(),
child: Text(
'Continue',
style: Theme.of(context).textTheme.headlineSmall,
),
),
),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import 'package:flutter/material.dart';
import 'package:zenon_syrius_wallet_flutter/blocs/pow_generating_status_bloc.dart';
import 'package:zenon_syrius_wallet_flutter/main.dart';
import 'package:zenon_syrius_wallet_flutter/utils/app_colors.dart';
import 'package:zenon_syrius_wallet_flutter/utils/constants.dart';
import 'package:zenon_syrius_wallet_flutter/utils/toast_utils.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/modular_widgets/p2p_swap_widgets/modals/join_native_swap_modal.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/modular_widgets/p2p_swap_widgets/modals/native_p2p_swap_modal.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/modular_widgets/p2p_swap_widgets/modals/start_native_swap_modal.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/modular_widgets/p2p_swap_widgets/modals/p2p_swap_warning_modal.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/modular_widgets/p2p_swap_widgets/p2p_swap_options_button.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/reusable_widgets/dialogs.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/reusable_widgets/error_widget.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/reusable_widgets/important_text_container.dart';
import 'package:zenon_syrius_wallet_flutter/widgets/reusable_widgets/layout_scaffold/card_scaffold.dart';
import 'package:znn_sdk_dart/znn_sdk_dart.dart';

Expand Down Expand Up @@ -55,6 +56,25 @@ class _P2pSwapOptionsCardState extends State<P2pSwapOptionsCard> {
);
}

void _showUserWarningModalIfNeeded({required Function() onContinue}) {
final hasReadWarning = sharedPrefsService!.get(
kHasReadP2pSwapWarningKey,
defaultValue: kHasReadP2pSwapWarningDefaultValue,
);
if (!hasReadWarning) {
showCustomDialog(
context: context,
content: P2PSwapWarningModal(onAccepted: () {
Navigator.pop(context);
sharedPrefsService!.put(kHasReadP2pSwapWarningKey, true);
Timer.run(onContinue);
}),
);
} else {
onContinue();
}
}

void _showNativeSwapModal(String swapId) {
Navigator.pop(context);
Timer.run(
Expand All @@ -75,11 +95,12 @@ class _P2pSwapOptionsCardState extends State<P2pSwapOptionsCard> {
secondaryText: 'Start a native swap with a counterparty.',
onClick: () => isGeneratingPlasma
? _showGeneratingPlasmaToast()
: showCustomDialog(
context: context,
content:
StartNativeSwapModal(onSwapStarted: _showNativeSwapModal),
),
: _showUserWarningModalIfNeeded(
onContinue: () => showCustomDialog(
context: context,
content: StartNativeSwapModal(
onSwapStarted: _showNativeSwapModal),
)),
),
const SizedBox(
height: 25.0,
Expand All @@ -89,10 +110,12 @@ class _P2pSwapOptionsCardState extends State<P2pSwapOptionsCard> {
secondaryText: 'Join a native swap started by a counterparty.',
onClick: () => isGeneratingPlasma
? _showGeneratingPlasmaToast()
: showCustomDialog(
context: context,
content:
JoinNativeSwapModal(onJoinedSwap: _showNativeSwapModal),
: _showUserWarningModalIfNeeded(
onContinue: () => showCustomDialog(
context: context,
content:
JoinNativeSwapModal(onJoinedSwap: _showNativeSwapModal),
),
),
),
const SizedBox(
Expand Down Expand Up @@ -128,14 +151,6 @@ class _P2pSwapOptionsCardState extends State<P2pSwapOptionsCard> {
const SizedBox(
height: 40.0,
),
const ImportantTextContainer(
text: '''The P2P swap is an experimental feature. '''
'''Please use the feature with caution and only swap small '''
'''amounts. There is absolutely no warranty for this '''
'''software.''',
showBorder: true,
animateBorder: true,
),
],
);
}
Expand Down
98 changes: 32 additions & 66 deletions lib/widgets/reusable_widgets/important_text_container.dart
Original file line number Diff line number Diff line change
@@ -1,87 +1,53 @@
import 'package:flutter/material.dart';
import 'package:zenon_syrius_wallet_flutter/utils/app_colors.dart';

class ImportantTextContainer extends StatefulWidget {
class ImportantTextContainer extends StatelessWidget {
final String text;
final bool showBorder;
final bool animateBorder;
final bool isSelectable;

const ImportantTextContainer({
required this.text,
this.showBorder = false,
this.animateBorder = false,
this.isSelectable = false,
Key? key,
}) : super(key: key);

@override
State<ImportantTextContainer> createState() => _ImportantTextContainerState();
}

class _ImportantTextContainerState extends State<ImportantTextContainer>
with TickerProviderStateMixin {
double _animationValue = 8.0;

@override
Widget build(BuildContext context) {
return TweenAnimationBuilder<double>(
duration: const Duration(milliseconds: 2500),
tween: Tween(begin: 2.0, end: _animationValue),
curve: Curves.easeInOut,
onEnd: () {
if (widget.animateBorder) {
setState(() {
_animationValue = _animationValue == 8.0 ? 2.0 : 8.0;
});
}
},
builder: (_, double value, __) {
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
border: widget.showBorder
? Border.all(
width: 1.0,
color: AppColors.errorColor,
)
: null,
boxShadow: widget.showBorder && widget.animateBorder
? [
BoxShadow(
color: AppColors.errorColor.withOpacity(0.35),
blurRadius: value,
spreadRadius: value)
]
: null,
borderRadius: const BorderRadius.all(
Radius.circular(8.0),
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
border: showBorder
? Border.all(
width: 1.0,
color: AppColors.errorColor,
)
: null,
borderRadius: const BorderRadius.all(
Radius.circular(8.0),
),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(15.0, 20.0, 15.0, 20.0),
child: Row(
children: [
const Icon(
Icons.info,
size: 20.0,
color: Colors.white,
),
const SizedBox(
width: 15.0,
),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(15.0, 20.0, 15.0, 20.0),
child: Row(
children: [
const Icon(
Icons.info,
size: 20.0,
color: Colors.white,
),
const SizedBox(
width: 15.0,
),
Expanded(
child: widget.isSelectable
? SelectableText(widget.text,
style: const TextStyle(fontSize: 14.0))
: Text(widget.text,
style: const TextStyle(fontSize: 14.0)),
),
],
Expanded(
child: isSelectable
? SelectableText(text, style: const TextStyle(fontSize: 14.0))
: Text(text, style: const TextStyle(fontSize: 14.0)),
),
),
);
},
],
),
),
);
}
}

0 comments on commit 7b265dc

Please sign in to comment.