From 625f9421fce27d17d67b96522c120119692066c6 Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Tue, 28 May 2024 20:56:45 +0200 Subject: [PATCH 1/2] fix: Set qr code sub title to clipboard on click --- .../trade/channel_creation_flow/channel_funding_screen.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart b/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart index 8aa99cea2..756496039 100644 --- a/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart +++ b/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart @@ -200,7 +200,8 @@ class _ChannelFunding extends State { padding: const EdgeInsets.only(left: 10.0, right: 10.0), child: GestureDetector( onTap: () { - Clipboard.setData(ClipboardData(text: qrCode.data)).then((_) { + Clipboard.setData(ClipboardData(text: qrCodeSubTitle)) + .then((_) { showSnackBar(ScaffoldMessenger.of(context), "Copied: $qrCodeSubTitle"); }); From cdcdc3897f6f32454473b1a45a3c96ea5c90d4af Mon Sep 17 00:00:00 2001 From: Richard Holzeis Date: Tue, 28 May 2024 20:57:24 +0200 Subject: [PATCH 2/2] feat: Add invoice expiry countdown to lighting qr code --- mobile/lib/common/countdown.dart | 52 +++++++++++++++++++ .../channel_funding_screen.dart | 28 +++++++--- 2 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 mobile/lib/common/countdown.dart diff --git a/mobile/lib/common/countdown.dart b/mobile/lib/common/countdown.dart new file mode 100644 index 000000000..d37539527 --- /dev/null +++ b/mobile/lib/common/countdown.dart @@ -0,0 +1,52 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; + +class Countdown extends StatefulWidget { + final int start; + + const Countdown({super.key, required this.start}); + + @override + CountdownState createState() => CountdownState(); +} + +class CountdownState extends State { + Timer? _timer; + int _start = 0; + + @override + void initState() { + super.initState(); + _start = widget.start; + _timer = Timer.periodic(const Duration(seconds: 1), (timer) { + setState(() { + if (_start > 0) { + _start--; + } else { + _timer?.cancel(); + } + }); + }); + } + + @override + void dispose() { + _timer?.cancel(); + super.dispose(); + } + + String get _formattedTime { + final minutes = _start ~/ 60; + final seconds = _start % 60; + return '${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}'; + } + + @override + Widget build(BuildContext context) { + return Text( + _formattedTime, + style: const TextStyle(fontSize: 14), + ); + } +} diff --git a/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart b/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart index 756496039..1e9329265 100644 --- a/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart +++ b/mobile/lib/features/trade/channel_creation_flow/channel_funding_screen.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get_10101/common/bitcoin_balance_field.dart'; import 'package:get_10101/common/color.dart'; +import 'package:get_10101/common/countdown.dart'; import 'package:get_10101/common/custom_qr_code.dart'; import 'package:get_10101/common/domain/funding_channel_task.dart'; import 'package:get_10101/common/domain/model.dart'; @@ -60,6 +61,9 @@ class ChannelFunding extends StatefulWidget { class _ChannelFunding extends State { FundingType selectedBox = FundingType.onchain; + // TODO(holzeis): It would be nicer if this would come directly from the invoice. + final expiry = DateTime.timestamp().second + 300; + @override Widget build(BuildContext context) { final status = context.watch().status; @@ -206,12 +210,24 @@ class _ChannelFunding extends State { "Copied: $qrCodeSubTitle"); }); }, - child: Text( - truncateWithEllipsis(44, qrCodeSubTitle), - style: const TextStyle(fontSize: 14), - textAlign: TextAlign.center, - maxLines: 1, - overflow: TextOverflow.ellipsis, + child: Column( + children: [ + Text( + truncateWithEllipsis(44, qrCodeSubTitle), + style: const TextStyle(fontSize: 14), + textAlign: TextAlign.center, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + if (selectedBox == FundingType.lightning) + Padding( + padding: const EdgeInsets.only(top: 2), + child: Countdown( + start: expiry > DateTime.timestamp().second + ? expiry - DateTime.timestamp().second + : 0), + ), + ], ), ), ),