Skip to content

fix: sub-day deadline precision in get_campaign_status#59

Open
morelucks wants to merge 3 commits into
OrbitChainLabs:mainfrom
morelucks:fix/subday-deadline-45
Open

fix: sub-day deadline precision in get_campaign_status#59
morelucks wants to merge 3 commits into
OrbitChainLabs:mainfrom
morelucks:fix/subday-deadline-45

Conversation

@morelucks

@morelucks morelucks commented Jun 20, 2026

Copy link
Copy Markdown

Summary

This PR addresses issue #45 where sub-day deadline values for campaigns are truncated to 0 by the integer division (end_time - now) / 86_400. Rather than applying a breaking change to existing days_remaining semantics, we implemented Option A (additive) which keeps backward compatibility while introducing higher granularity for clients (e.g., dashboards and indexers).

Proposed Changes

  1. Schema Update (campaign/src/types.rs):
    • Added hours_remaining: u32 to the CampaignStatusResponse struct.
  2. Logic Implementation (campaign/src/contract.rs):
    • Refactored get_campaign_status to compute both days_remaining and hours_remaining using the time delta.
    • For past/expired campaigns, hours_remaining is clamped to 0.
  3. Unit Tests & Ledger Snapshots (campaign/src/test/get_campaign_status_tests.rs):
    • Updated existing assertions to verify the newly added field.
    • Added calculates_subday_remaining to verify that active campaigns with less than 24 hours remaining return the correct number of hours.
    • Added calculates_past_subday_remaining to verify that campaigns past their deadlines return 0 hours.
    • Automatically regenerated ledger snapshots under campaign/test_snapshots/test/get_campaign_status_tests/.

Closes #45

Alqku commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Nice granularity improvement addressing the sub-day truncation in #45. One heads-up though: adding hours_remaining to CampaignStatusResponse changes the return-shape contract ABI of get_campaign_status — any dApp, indexer, or downstream tooling fetching that struct will see a different layout. Options: (a) ship this deliberately as a breaking ABI change and bump the contract version explicitly, or (b) expose hours in a separate get_campaign_hours_remaining view (or as a tuple) to keep the existing struct shape. Either way let us coordinate the deploy. Looking forward to a follow-up.

Alqku commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Hey @morelucks 👋 — the sub-day deadline fix for #45 looks correct. Unfortunately I don't see any CI check results on this PR. Could you rebase onto the latest main (or push an empty commit) to retrigger the workflow? Once the fmt/clippy/test/wasm jobs come back green I'll merge this right away 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LOW] get_campaign_status::days_remaining truncates sub-day deadlines to 0 (UX / dashboard)

2 participants