-
Notifications
You must be signed in to change notification settings - Fork 1
feat(#270): drive waiting-state countdown from expiration_seconds + timeout_at #306
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import 'package:mostro/src/rust/api/types.dart'; | ||
|
|
||
| /// The countdown target for a trade, resolved for #270. | ||
| /// | ||
| /// [deadlineEpochSeconds] is the unix-second instant the countdown runs to; | ||
| /// [totalWindowSeconds] sizes the progress ring (the full window). | ||
| typedef CountdownDeadline = ({int deadlineEpochSeconds, int totalWindowSeconds}); | ||
|
|
||
| /// Last-resort waiting-state window (seconds) when the node's instance event | ||
| /// omits `expiration_seconds`. Matches the Mostro daemon default (15 min). | ||
| const int kWaitingCountdownFallbackSeconds = 900; | ||
|
|
||
| /// Chooses the countdown target for a trade (#270): | ||
| /// | ||
| /// - **Pending**: counts to the 24 h pending-order expiry ([pendingExpiresAt]). | ||
| /// - **Waiting states** (buyer-invoice / payment): counts to the state-change | ||
| /// deadline — the trade's [timeoutAtEpoch] when the daemon persisted one, | ||
| /// else `now + expiration_seconds` (falling back to | ||
| /// [kWaitingCountdownFallbackSeconds] when the node omits it). | ||
| /// - **Any other state**: no countdown (null). | ||
| /// | ||
| /// The UI only informs — the daemon stays the authority on expiry, so callers | ||
| /// never cancel locally at zero. | ||
| CountdownDeadline? waitingCountdownDeadline({ | ||
| required OrderStatus? status, | ||
| DateTime? pendingExpiresAt, | ||
| int? timeoutAtEpoch, | ||
| int? expirationSeconds, | ||
| }) { | ||
| final window = expirationSeconds ?? kWaitingCountdownFallbackSeconds; | ||
| final now = DateTime.now().millisecondsSinceEpoch ~/ 1000; | ||
| switch (status) { | ||
| case OrderStatus.pending: | ||
| if (pendingExpiresAt == null) return null; | ||
| final deadline = pendingExpiresAt.millisecondsSinceEpoch ~/ 1000; | ||
| final total = deadline - now; | ||
| return ( | ||
| deadlineEpochSeconds: deadline, | ||
| totalWindowSeconds: total > 0 ? total : window, | ||
| ); | ||
| case OrderStatus.waitingBuyerInvoice: | ||
| case OrderStatus.waitingPayment: | ||
| if (timeoutAtEpoch != null) { | ||
| return (deadlineEpochSeconds: timeoutAtEpoch, totalWindowSeconds: window); | ||
| } | ||
| return (deadlineEpochSeconds: now + window, totalWindowSeconds: window); | ||
| default: | ||
| return null; | ||
| } | ||
| } | ||
|
Comment on lines
+31
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift Keep the fallback deadline stable. When Use a stable waiting-state start time, or use a shared cache keyed by order ID and waiting status. Do not derive As per coding guidelines, “Add targeted tests when expanding complex logic, asynchronous workflows, or protocol handling” and “run 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use the snapshot status while live status resolves.
Line 94 uses
liveStatus ?? order.status. Line 102 passes onlyliveStatus. WhiletradeStatusProvideris loading, a known pending or waitingorder.statusproduces no countdown.Pass
liveStatus ?? order.statustowaitingCountdownDeadline. Add coverage for the provider-loading state.As per coding guidelines, “Add targeted tests when expanding complex logic, asynchronous workflows, or protocol handling.”
🤖 Prompt for AI Agents
Source: Coding guidelines