Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show invoice expiry #2575

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -200,17 +204,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
Loading