Skip to content

fix(web): enforce min start time of now + 60s in stream validation schema - #502

Merged
Idrhas merged 2 commits into
Fundable-Protocol:mainfrom
Cerome360:fix/payment-stream-start-time-validation
Aug 3, 2026
Merged

fix(web): enforce min start time of now + 60s in stream validation schema#502
Idrhas merged 2 commits into
Fundable-Protocol:mainfrom
Cerome360:fix/payment-stream-start-time-validation

Conversation

@Cerome360

@Cerome360 Cerome360 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes #398

Add validateStartTime() and getMinStartTime() to stream-validation.ts - Update calculateEndTime() to use getMinStartTime() when startTime is null - Update validateEndTime() to reject explicit start times < now + 60s - Update CreatePaymentStream.tsx fee estimation to use now + 60s start time - Write comprehensive unit tests covering success, failure, and edge cases

Summary by CodeRabbit

  • New Features
    • Added enforcement that stream start times must be at least 60 seconds in the future.
    • Updated end-time calculations and validation to use a consistent minimum start-time buffer.
  • Bug Fixes
    • Improved payment stream creation fee estimates by applying the same 60-second buffered start time.
  • Tests
    • Adjusted and expanded end-time validation test coverage around minimum duration constraints and timing edge cases.

…hema

Add validateStartTime() and getMinStartTime() to stream-validation.ts - Update calculateEndTime() to use getMinStartTime() when startTime is null - Update validateEndTime() to reject explicit start times < now + 60s - Update CreatePaymentStream.tsx fee estimation to use now + 60s start time - Write comprehensive unit tests covering success, failure, and edge cases
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@Cerome360 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c103bfd-920a-4657-a124-67864d609614

📥 Commits

Reviewing files that changed from the base of the PR and between cb8fab8 and 0f30bb3.

📒 Files selected for processing (1)
  • apps/web/src/lib/__tests__/stream-validation.test.ts

📝 Walkthrough

Walkthrough

Stream timing validation now requires starts to be at least 60 seconds in the future, derives null starts from that threshold, validates end times accordingly, adds comprehensive tests, and uses the buffered start time for fee estimation.

Changes

Stream timing validation

Layer / File(s) Summary
Minimum start and end-time validation
apps/web/src/lib/stream-validation.ts
Adds minimum-start helpers and updates end-time calculation and validation to enforce the 60-second timing threshold.
Stream timing test coverage
apps/web/src/lib/__tests__/stream-validation.test.ts
Adds deterministic coverage for start-time validation, end-time calculation, duration parsing, formatting, and relative-time output.
Buffered stream fee estimation
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx
Uses a start timestamp 60 seconds ahead when calculating stream creation fee estimates and end times.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The validation schema change aligns with #398, but the summary does not show the form-level date picker fix required by the issue. Update PaymentStreamForm to enforce the minimum selectable start time and confirm the issue path is covered by tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: enforcing a 60-second minimum stream start time in validation.
Out of Scope Changes check ✅ Passed The fee-estimation tweak and validation/test updates are all consistent with the stated PR objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx (1)

104-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Buffer duplicates the MIN_START_TIME_OFFSET_SECONDS constant instead of importing it.

Hardcoding 60 here duplicates the value now owned by stream-validation.ts; if that constant changes, fee estimation and actual validation will silently diverge.

♻️ Proposed fix
-      const startTime = BigInt(Math.floor(Date.now() / 1000) + 60); // 60s buffer for on-chain latency
+      const startTime = BigInt(getMinStartTime()); // buffered per MIN_START_TIME_OFFSET_SECONDS
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx` at
line 104, Update the startTime calculation in CreatePaymentStream to import and
use MIN_START_TIME_OFFSET_SECONDS from stream-validation.ts instead of the
hardcoded 60-second offset, keeping fee estimation aligned with validation.
apps/web/src/lib/stream-validation.ts (3)

40-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Error message hardcodes "60" instead of referencing MIN_START_TIME_OFFSET_SECONDS.

If the offset constant ever changes, this message silently goes stale. Interpolate the constant instead.

♻️ Proposed fix
   const minStart = getMinStartTime();
   if (startTime < minStart) {
-    return "Start time must be at least 60 seconds from now";
+    return `Start time must be at least ${MIN_START_TIME_OFFSET_SECONDS} seconds from now`;
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/stream-validation.ts` around lines 40 - 52, Update the error
message in validateStartTime to interpolate MIN_START_TIME_OFFSET_SECONDS
instead of hardcoding “60”, keeping the existing validation logic and return
behavior unchanged.

1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Magic number 60 duplicated across files instead of using MIN_START_TIME_OFFSET_SECONDS. Three sites re-derive the 60-second buffer independently rather than deriving from the single exported constant; a future change to the constant would silently desync the error messages and the fee-estimation buffer from the actual validation minimum.

  • apps/web/src/lib/stream-validation.ts#L40-52: interpolate MIN_START_TIME_OFFSET_SECONDS into the validateStartTime error string instead of the literal "60 seconds".
  • apps/web/src/lib/stream-validation.ts#L94-121: interpolate MIN_START_TIME_OFFSET_SECONDS into the validateEndTime error string as well.
  • apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx#L104-104: replace Math.floor(Date.now() / 1000) + 60 with getMinStartTime() (imported from stream-validation.ts) so the fee-estimation buffer stays in sync with the validation minimum.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/stream-validation.ts` at line 1, Replace the hardcoded “60
seconds” text in validateStartTime and validateEndTime with
MIN_START_TIME_OFFSET_SECONDS interpolation, and update CreatePaymentStream’s
fee-estimation timestamp to use getMinStartTime() instead of adding 60 directly.
Reuse these existing symbols so validation messages and the estimation buffer
remain synchronized.

94-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Same magic-number issue in the end-time error message.

Same as the validateStartTime message — hardcode should reference MIN_START_TIME_OFFSET_SECONDS.

♻️ Proposed fix
   if (endTime <= minEndTime) {
-    return "Stream end time must be at least 60 seconds from now";
+    return `Stream end time must be at least ${MIN_START_TIME_OFFSET_SECONDS} seconds from now`;
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/stream-validation.ts` around lines 94 - 121, Update the
end-time validation error message in the surrounding stream validation function
to reference MIN_START_TIME_OFFSET_SECONDS instead of hardcoding “60 seconds,”
matching the constant-based message used by validateStartTime while preserving
the existing validation behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/lib/__tests__/stream-validation.test.ts`:
- Around line 149-158: Remove the duplicate test case following the long-enough
duration test, or replace it with a distinct supported DurationUnit scenario; do
not label it as a minute test because DurationUnit has no minute unit. Keep the
existing unique coverage and assertions in validateEndTime tests unchanged.

---

Nitpick comments:
In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Line 104: Update the startTime calculation in CreatePaymentStream to import
and use MIN_START_TIME_OFFSET_SECONDS from stream-validation.ts instead of the
hardcoded 60-second offset, keeping fee estimation aligned with validation.

In `@apps/web/src/lib/stream-validation.ts`:
- Around line 40-52: Update the error message in validateStartTime to
interpolate MIN_START_TIME_OFFSET_SECONDS instead of hardcoding “60”, keeping
the existing validation logic and return behavior unchanged.
- Line 1: Replace the hardcoded “60 seconds” text in validateStartTime and
validateEndTime with MIN_START_TIME_OFFSET_SECONDS interpolation, and update
CreatePaymentStream’s fee-estimation timestamp to use getMinStartTime() instead
of adding 60 directly. Reuse these existing symbols so validation messages and
the estimation buffer remain synchronized.
- Around line 94-121: Update the end-time validation error message in the
surrounding stream validation function to reference
MIN_START_TIME_OFFSET_SECONDS instead of hardcoding “60 seconds,” matching the
constant-based message used by validateStartTime while preserving the existing
validation behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 29c3aab2-882e-4ee2-ba3b-22e34a9533e3

📥 Commits

Reviewing files that changed from the base of the PR and between 375c936 and cb8fab8.

📒 Files selected for processing (3)
  • apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx
  • apps/web/src/lib/__tests__/stream-validation.test.ts
  • apps/web/src/lib/stream-validation.ts

Comment thread apps/web/src/lib/__tests__/stream-validation.test.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Idrhas

Idrhas commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates

@Idrhas
Idrhas merged commit c842938 into Fundable-Protocol:main Aug 3, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2026
10 tasks
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.

web(PaymentStreamForm): prevent selecting past start times in date picker

2 participants