Skip to content

Commit 0cf9981

Browse files
committed
repin joinstr_flutter to merged master, surface pool expiry as absolute timestamp
1 parent aa3847a commit 0cf9981

7 files changed

Lines changed: 47 additions & 10 deletions

File tree

lib/features/joinstr/data/joinstr_datasource.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class JoinstrDatasource {
2929
rawJson: p.rawJson,
3030
denominationSat: p.denominationSat.toInt(),
3131
peers: p.peers,
32-
timeoutSec: p.timeout.toInt(),
32+
expiresAtUnixSec: p.expiresAtUnixSec.toInt(),
3333
relay: p.relay,
3434
feeRateSatPerVb: p.feeRate,
3535
publicKey: p.publicKey,

lib/features/joinstr/domain/joinstr.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class JoinstrPool {
3030
final String rawJson;
3131
final int denominationSat;
3232
final int peers;
33-
final int timeoutSec;
33+
34+
/// When the pool expires, as a unix timestamp in seconds (absolute, not a
35+
/// duration).
36+
final int expiresAtUnixSec;
3437
final String relay;
3538
final int feeRateSatPerVb;
3639
final String publicKey;
@@ -40,11 +43,17 @@ class JoinstrPool {
4043
required this.rawJson,
4144
required this.denominationSat,
4245
required this.peers,
43-
required this.timeoutSec,
46+
required this.expiresAtUnixSec,
4447
required this.relay,
4548
required this.feeRateSatPerVb,
4649
required this.publicKey,
4750
});
51+
52+
/// Seconds until the pool expires relative to [now], clamped at zero.
53+
int secondsUntilExpiry(DateTime now) {
54+
final remaining = expiresAtUnixSec - now.millisecondsSinceEpoch ~/ 1000;
55+
return remaining > 0 ? remaining : 0;
56+
}
4857
}
4958

5059
abstract final class Joinstr {

lib/features/joinstr/ui/screens/joinstr_screen.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ class _PoolTile extends StatelessWidget {
155155
context.loc.joinstrPoolSummary(pool.denominationSat, pool.peers),
156156
),
157157
subtitle: Text(
158-
context.loc.joinstrPoolDetail(pool.feeRateSatPerVb, pool.timeoutSec),
158+
context.loc.joinstrPoolDetail(
159+
pool.feeRateSatPerVb,
160+
pool.secondsUntilExpiry(DateTime.now()),
161+
),
159162
),
160163
trailing: FilledButton(
161164
onPressed: enabled

localization/app_en.arb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,14 @@
479479
}
480480
}
481481
},
482-
"joinstrPoolDetail": "{feeRate} sat/vB · expires in {timeoutSec}s",
482+
"joinstrPoolDetail": "{feeRate} sat/vB · expires in {secondsLeft}s",
483483
"@joinstrPoolDetail": {
484-
"description": "Secondary line of a joinstr pool tile: fee rate and timeout",
484+
"description": "Secondary line of a joinstr pool tile: fee rate and seconds until the pool expires",
485485
"placeholders": {
486486
"feeRate": {
487487
"type": "int"
488488
},
489-
"timeoutSec": {
489+
"secondsLeft": {
490490
"type": "int"
491491
}
492492
}

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,8 @@ packages:
12321232
dependency: "direct main"
12331233
description:
12341234
path: dart
1235-
ref: e4229f278e329a49f053bfb44465fc3f1c7085be
1236-
resolved-ref: e4229f278e329a49f053bfb44465fc3f1c7085be
1235+
ref: e4b77ec4341eebbb22cef74b57e608841779fcd7
1236+
resolved-ref: e4b77ec4341eebbb22cef74b57e608841779fcd7
12371237
url: "https://github.com/rust-joinstr/joinstr"
12381238
source: git
12391239
version: "0.1.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dependencies:
4747
joinstr_flutter:
4848
git:
4949
url: https://github.com/rust-joinstr/joinstr
50-
ref: e4229f278e329a49f053bfb44465fc3f1c7085be
50+
ref: e4b77ec4341eebbb22cef74b57e608841779fcd7
5151
path: dart
5252
qr_flutter: ^4.1.0
5353
dio: ^5.9.0

test/features/joinstr/domain/joinstr_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,31 @@ void main() {
155155
);
156156
});
157157

158+
group('pool expiry', () {
159+
JoinstrPool poolExpiringAt(int unixSec) => JoinstrPool(
160+
id: 'p',
161+
rawJson: '{}',
162+
denominationSat: 100000,
163+
peers: 2,
164+
expiresAtUnixSec: unixSec,
165+
relay: 'wss://nos.lol',
166+
feeRateSatPerVb: 1,
167+
publicKey: 'pk',
168+
);
169+
170+
test('reports the seconds remaining until an absolute expiry', () {
171+
final now = DateTime.utc(2026, 1, 1);
172+
final nowSec = now.millisecondsSinceEpoch ~/ 1000;
173+
expect(poolExpiringAt(nowSec + 300).secondsUntilExpiry(now), 300);
174+
});
175+
176+
test('clamps a past expiry to zero rather than going negative', () {
177+
final now = DateTime.utc(2026, 1, 1);
178+
final nowSec = now.millisecondsSinceEpoch ~/ 1000;
179+
expect(poolExpiringAt(nowSec - 60).secondsUntilExpiry(now), 0);
180+
});
181+
});
182+
158183
group('denomination conversion', () {
159184
test('converts satoshis to BTC for the pool config', () {
160185
expect(Joinstr.denominationBtc(100000), 0.001);

0 commit comments

Comments
 (0)