Skip to content

Commit

Permalink
Merge pull request #2575 from get10101/feat/show-invoice-expiry
Browse files Browse the repository at this point in the history
feat: Show invoice expiry
  • Loading branch information
holzeis authored May 29, 2024
2 parents 33ab37a + cdcdc38 commit 7b65629
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
52 changes: 52 additions & 0 deletions mobile/lib/common/countdown.dart
Original file line number Diff line number Diff line change
@@ -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<Countdown> {
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),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -60,6 +61,9 @@ class ChannelFunding extends StatefulWidget {
class _ChannelFunding extends State<ChannelFunding> {
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<FundingChannelChangeNotifier>().status;
Expand Down Expand Up @@ -205,17 +209,30 @@ class _ChannelFunding extends State<ChannelFunding> {
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),
),
],
),
),
),
Expand Down

0 comments on commit 7b65629

Please sign in to comment.