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 8aa99cea2..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; @@ -200,17 +204,30 @@ 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"); }); }, - 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), + ), + ], ), ), ),