Skip to content

refactor(web): remove mock simulation methods from StellarService, route through SDK - #547

Merged
Idrhas merged 8 commits into
Fundable-Protocol:mainfrom
kathy-ai-art:fix/remove-stellar-mock-simulation-methods-371
Aug 7, 2026
Merged

refactor(web): remove mock simulation methods from StellarService, route through SDK#547
Idrhas merged 8 commits into
Fundable-Protocol:mainfrom
kathy-ai-art:fix/remove-stellar-mock-simulation-methods-371

Conversation

@kathy-ai-art

@kathy-ai-art kathy-ai-art commented Jul 29, 2026

Copy link
Copy Markdown

Closes #371

Summary

Removes all mock simulation methods from apps/web/src/lib/stellar.ts that used Math.random() and setTimeout instead of delegating to the real SDK service. All payment stream operations now exclusively route through @/services/stellar.service.ts and the SDK client wrappers in @/lib/api.ts.

What Changed

  • apps/web/src/lib/stellar.ts: Removed 6 mock methods (createPaymentStream, getAccountInfo, getWithdrawableAmount, withdrawFromStream, depositToStream, getStreamDetails) that used synthetic delays and random IDs. Added @deprecated JSDoc header. Preserved 4 utility methods (validateStellarAddress, formatAmount, formatTokenAmount, calculateStreamProgress)
  • apps/web/src/lib/api.ts: Added depositToStream function using PaymentStreamClient.deposit()
  • apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx: Routes createStream through @/lib/api.ts with wallet signing
  • apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx: Routes depositToStream through @/lib/api.ts with wallet signing
  • apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx: Routes withdraw through @/lib/api.ts with wallet signing
  • apps/web/src/hooks/use-stream-delegation.ts: Removed unused StellarService import
  • apps/web/src/lib/stellar.test.ts: 18 tests covering all remaining utility methods (success paths, failure paths, edge cases)

Key Design Decisions

  • Kept utility methods (validateStellarAddress, formatAmount, formatTokenAmount, calculateStreamProgress) in lib/stellar.ts since they have no network dependency and are used across the codebase
  • Wallet signing flows through StellarWalletProvider via the signTransaction callback pattern
  • The WithdrawStreamModal uses a placeholder for getWithdrawableAmount display since that requires a live RPC call through PaymentStreamClient

Acceptance Criteria Checklist

  • Mock simulation methods removed or deprecated
  • Payment stream operations exclusively utilize @/services/stellar.service.ts
  • Tests cover success paths, failure paths, and edge cases

Test Output

All 18 tests in src/lib/stellar.test.ts pass. 15 pre-existing failures in unrelated test files (sanitize-error, stellar.service edge/timeout) are unchanged.

Security Note

  • No more synthetic Math.random() stream IDs - all stream IDs come from the Soroban contract
  • All write operations require explicit signTransaction from the connected wallet
  • No sensitive data exposed

Follow-ups

  • WithdrawStreamModal.getWithdrawableAmount should call PaymentStreamClient.getWithdrawableAmount() instead of the placeholder
  • Coverage for the multi-day time format branch in calculateStreamProgress

Summary by CodeRabbit

  • New Features

    • Create payment streams using the connected wallet and selected token.
    • Deposit into existing streams and withdraw available funds.
    • Display complete transaction and stream identifiers after successful actions.
    • Show the current withdrawable balance before withdrawal.
  • Bug Fixes

    • Improved wallet connection and signing validation.
    • Enhanced amount conversion and stream progress handling.
    • Added safer error handling for balance loading and transaction failures.

…ute through SDK

Removes all mock simulation methods (createPaymentStream, getAccountInfo,
getWithdrawableAmount, withdrawFromStream, depositToStream, getStreamDetails)
from apps/web/src/lib/stellar.ts that used Math.random() and setTimeout.

All payment stream operations now exclusively route through @/services/stellar.service.ts
and the SDK client wrappers in @/lib/api.ts.

Adds tests for all remaining utility methods (validateStellarAddress,
formatAmount, formatTokenAmount, calculateStreamProgress) covering success
paths, failure paths, and edge cases.
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@kathy-ai-art 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

📝 Walkthrough

Walkthrough

Payment-stream creation, deposits, and withdrawals now use shared contract APIs with wallet signing. Stream records include contract identifiers. Legacy simulated stream operations were removed from StellarService, and utility tests were added.

Changes

Payment stream API migration

Layer / File(s) Summary
Remove legacy operations and test utilities
apps/web/src/lib/stellar.ts, apps/web/src/lib/stellar.test.ts
StellarService retains utility methods and removes legacy stream operations. Tests cover address, amount, token, and progress utilities.
Expose shared stream transaction APIs
apps/web/src/lib/api.ts, apps/web/src/lib/validations.ts
Transaction APIs return hashes. Deposit and withdrawable-amount APIs are added. StreamRecord now includes contractStreamId.
Route stream creation through the API
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx
Stream creation resolves token and timing values, validates wallet signing, and calls createStream. The changed block contains duplicate amount and duration-multiplier declarations, including an incomplete first multiplier expression.
Route deposits and withdrawals through wallet APIs
apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx, apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx, apps/web/src/components/modules/payment-stream/StreamsHistory.tsx
Deposit and withdrawal flows use contract stream IDs, wallet signing, scaled BigInt amounts, and returned transaction hashes. Withdrawable amounts load through the shared API. Mock records include contract IDs.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: cerome360

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 describes removing mock StellarService methods and routing payment-stream operations through the SDK.
Linked Issues check ✅ Passed The PR removes the legacy mock methods and routes payment-stream operations through SDK-backed service APIs, satisfying issue #371.
Out of Scope Changes check ✅ Passed The changes support the refactor through API wrappers, wallet integration, contract IDs, type updates, and relevant utility tests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.6)
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx

File contains syntax errors that prevent linting: Line 204: Expected an expression, or an assignment but instead found 'const'.


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: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx (1)

190-203: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

formData is now dead code.

With StellarService.createPaymentStream(formData) removed, this object (and the PaymentStreamFormData type import) is constructed and never read.

🧹 Proposed cleanup
-      // Convert form data to the format expected by StellarService
-      const formData: PaymentStreamFormData = {
-        recipientAddress: streamData.recipient,
-        token: streamData.token,
-        totalAmount: streamData.amount,
-        duration: streamData.durationValue,
-        durationUnit: streamData.duration === "hour" ? "hours" : "days",
-        cancelable: streamData.cancellability,
-        transferable: streamData.transferability,
-      };
-
       const tokenAddress = SUPPORTED_TOKENS.find(t => t.value === streamData.token)?.address;

Drop the PaymentStreamFormData import too if it has no other use in this file.

🤖 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`
around lines 190 - 203, Remove the unused formData construction in the payment
stream creation flow and delete the PaymentStreamFormData import if it is not
referenced elsewhere in CreatePaymentStream. Preserve the tokenAddress
validation and subsequent logic unchanged.
🧹 Nitpick comments (5)
apps/web/src/lib/stellar.ts (1)

1-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

@deprecated here documents nothing and is misleading.

A JSDoc block before an import isn't attached to any symbol, so editors won't warn consumers. It also contradicts the sentence that follows: the retained utilities (validateStellarAddress, formatAmount, formatTokenAmount, calculateStreamProgress) are still the canonical implementations and are actively imported by the payment-stream modals. Consider dropping the tag and keeping only the explanatory note.

♻️ Proposed doc fix
 /**
- * `@deprecated` Utility methods for Stellar address validation and amount formatting.
- * All smart contract operations now route through {`@link` `@/services/stellar.service.ts`}
- * or the SDK client wrappers in {`@link` `@/lib/api.ts`}.
+ * Pure utility helpers for Stellar address validation, amount formatting and
+ * stream progress calculation.
+ *
+ * NOTE: all smart-contract operations live in `@/services/stellar.service.ts`
+ * or the SDK client wrappers in `@/lib/api.ts` — do not add network calls here.
  */
🤖 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/stellar.ts` around lines 1 - 5, Remove the `@deprecated` tag
from the file-level JSDoc in stellar.ts, retaining only an accurate explanatory
note about smart contract operations and the still-canonical utility functions.
apps/web/src/lib/api.ts (1)

230-239: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Validate streamId before BigInt().

BigInt(NaN) / BigInt(1.5) throws a RangeError from inside the SDK call, producing an opaque message in the caller's error toast. A guard here gives a clear failure for every caller.

🛡️ Proposed guard
 }): Promise<void> {
+    if (!Number.isInteger(params.streamId) || params.streamId < 0) {
+        throw new Error(`Invalid stream id: ${params.streamId}`);
+    }
     const client = createPaymentStreamClient(params.sender);

Otherwise this mirrors withdraw (Lines 133-152) cleanly.

🤖 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/api.ts` around lines 230 - 239, Update depositToStream to
validate params.streamId before converting it with BigInt, rejecting NaN and
non-integer values with a clear caller-facing error. Keep the existing client
creation, deposit, and signAndSendTx flow unchanged for valid stream IDs,
matching the validation behavior used by withdraw.
apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx (1)

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

Missing success notification.

DepositStreamModal.tsx (Line 77) fires notify.success("Deposit successful!"); the withdraw path closes silently. Add the matching toast for consistency.

🤖 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/WithdrawStreamModal.tsx` at
line 134, Add a success toast in the withdraw completion flow before or
alongside the existing onSuccess callback, matching the notification pattern and
message used by DepositStreamModal. Update the handler containing
onSuccess?.(`withdraw_${Date.now()}`) so withdrawals display “Withdraw
successful!” before closing.
apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx (1)

61-68: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Move the wallet guard above the amount conversion.

BigInt(Math.floor(parseFloat(...) * 1e7)) throws RangeError on a non-numeric/NaN amount, so ordering the connectivity check first keeps the failure modes distinct and avoids doing work that will be discarded.

♻️ Proposed reorder
-      const amount = BigInt(Math.floor(parseFloat(data.amount) * 10000000))
-
-      // Use the real SDK-backed depositToStream from `@/lib/api`
-      // This routes through PaymentStreamClient.deposit()
       if (!isConnected || !signTransaction || !address) {
         notify.error('Wallet not connected');
         return;
       }
+
+      const amount = BigInt(Math.floor(parseFloat(data.amount) * 10000000))
🤖 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/DepositStreamModal.tsx` around
lines 61 - 68, Move the wallet connectivity guard in the deposit submission flow
above the amount conversion that computes amount with BigInt. Ensure
!isConnected, !signTransaction, or !address returns with notify.error before
parsing data.amount, while preserving the existing conversion and
connected-wallet behavior.
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx (1)

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

Duplicated duration-multiplier ladder.

The same hour/day/week/month/year → seconds mapping and the same 1e7 scaling already exist in estimateFee (Lines 99-104). Extracting DURATION_SECONDS and a toStroops(amount) helper keeps the fee estimate and the actual submission from drifting apart.

🤖 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`
around lines 205 - 211, In CreatePaymentStream, extract the shared
hour/day/week/month/year-to-seconds mapping into DURATION_SECONDS and the 1e7
amount conversion into a toStroops(amount) helper, then reuse both from
estimateFee and the submission logic around durationMultiplier and amount.
Remove the duplicated ladder and inline scaling while preserving the existing
fallback and rounding 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/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Around line 205-221: Update handleConfirmStream to revalidate the wallet
address immediately before calling createStream and return or surface an error
when it is unavailable; remove the unsafe address! assertion. Ensure cancelable
and transferable from the form state are either passed through createStream and
its contract call or disabled/clearly annotated in the UI until supported. Also
replace the parseFloat-based amount conversion in this handler with exact
decimal-string scaling before constructing the BigInt.

In `@apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx`:
- Line 78: The payment-stream success callbacks fabricate timestamp IDs instead
of receiving real transaction hashes. Update depositToStream and withdraw in
apps/web/src/lib/api.ts to return the transaction hash, then pass those returned
hashes to onSuccess in
apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx#L78-L78
and
apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx#L134-L134,
removing the generated deposit_${Date.now()} and withdraw_${Date.now()} values.
- Around line 70-75: Remove the Number conversion in the deposit flow around
depositToStream and preserve the string StreamRecord.id when passing the stream
identifier. Ensure real stream operations receive a valid numeric contract ID
only after an explicit mapping step, or use the separate numeric ID field if
available; do not pass arbitrary record IDs such as stream_001_abc123def456 to
BigInt-based operations.

In `@apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx`:
- Around line 72-87: Replace the placeholder timeout in the withdrawable-amount
effect with the real `getWithdrawableAmount` SDK/service flow used by the
payment-stream operations, preserving loading, abort, and error handling. Ensure
`withdrawableAmount` reflects the stream’s actual state so the Available display
and Max handler do not submit a fabricated zero; if the read API is unavailable,
disable Max and render an unavailable state instead. Remove the unused `onError`
effect dependency and inert cancellation logic as appropriate.
- Around line 118-132: Update the withdraw flow in WithdrawStreamModal,
including withdrawTo handling, so a selected “Other Address” is either passed
through to the SDK/contract as the withdrawal destination or the option is
removed/disabled with matching validation. Also require address alongside
isConnected and signTransaction before calling withdraw, and pass the validated
connected address without falling back to stream.recipient.

In `@apps/web/src/lib/stellar.test.ts`:
- Around line 121-137: Update StellarService.calculateStreamProgress to handle
streams whose startTime equals endTime without dividing by zero; return finite
progressPercentage and ratePerHour values, preserving the existing completed and
not-started behavior. Add a zero-duration test in the calculateStreamProgress
test suite that verifies both returned values are finite.
- Around line 58-78: Add a `decimals = 0` test for
`StellarService.formatTokenAmount` that preserves integer values such as “100”.
Update the trimming logic in `formatTokenAmount` so its trailing-zero regex only
removes zeros from an existing fractional portion, never integer trailing zeros
when `toFixed(0)` returns no decimal point.

---

Outside diff comments:
In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Around line 190-203: Remove the unused formData construction in the payment
stream creation flow and delete the PaymentStreamFormData import if it is not
referenced elsewhere in CreatePaymentStream. Preserve the tokenAddress
validation and subsequent logic unchanged.

---

Nitpick comments:
In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Around line 205-211: In CreatePaymentStream, extract the shared
hour/day/week/month/year-to-seconds mapping into DURATION_SECONDS and the 1e7
amount conversion into a toStroops(amount) helper, then reuse both from
estimateFee and the submission logic around durationMultiplier and amount.
Remove the duplicated ladder and inline scaling while preserving the existing
fallback and rounding behavior.

In `@apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx`:
- Around line 61-68: Move the wallet connectivity guard in the deposit
submission flow above the amount conversion that computes amount with BigInt.
Ensure !isConnected, !signTransaction, or !address returns with notify.error
before parsing data.amount, while preserving the existing conversion and
connected-wallet behavior.

In `@apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx`:
- Line 134: Add a success toast in the withdraw completion flow before or
alongside the existing onSuccess callback, matching the notification pattern and
message used by DepositStreamModal. Update the handler containing
onSuccess?.(`withdraw_${Date.now()}`) so withdrawals display “Withdraw
successful!” before closing.

In `@apps/web/src/lib/api.ts`:
- Around line 230-239: Update depositToStream to validate params.streamId before
converting it with BigInt, rejecting NaN and non-integer values with a clear
caller-facing error. Keep the existing client creation, deposit, and
signAndSendTx flow unchanged for valid stream IDs, matching the validation
behavior used by withdraw.

In `@apps/web/src/lib/stellar.ts`:
- Around line 1-5: Remove the `@deprecated` tag from the file-level JSDoc in
stellar.ts, retaining only an accurate explanatory note about smart contract
operations and the still-canonical utility functions.
🪄 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: 51b06c83-1797-4125-af7b-76f609779228

📥 Commits

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

📒 Files selected for processing (7)
  • apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx
  • apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx
  • apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx
  • apps/web/src/hooks/use-stream-delegation.ts
  • apps/web/src/lib/api.ts
  • apps/web/src/lib/stellar.test.ts
  • apps/web/src/lib/stellar.ts
💤 Files with no reviewable changes (1)
  • apps/web/src/hooks/use-stream-delegation.ts

Comment thread apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx Outdated
Comment thread apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx Outdated
Comment thread apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx Outdated
Comment thread apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx Outdated
Comment thread apps/web/src/lib/stellar.test.ts
Comment thread apps/web/src/lib/stellar.test.ts
kathy-ai-art and others added 5 commits July 30, 2026 07:47
…odal.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…ream.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…ream.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Change depositToStream/withdraw streamId type from number to string to avoid NaN from Number() on non-numeric stream IDs- Return real tx hash from signAndSendTx, depositToStream, withdraw; pass real hash to onSuccess in both modals- Add getWithdrawableAmount API wrapper in api.ts; replace setTimeout mock in WithdrawStreamModal- Fix formatTokenAmount to not strip integer trailing zeros when decimals=0; add test coverage
- Add contractStreamId: number field to StreamRecord interface (validations.ts)- Update mock data in StreamsHistory.tsx with contractStreamId- Revert api.ts depositToStream/withdraw/getWithdrawableAmount streamId to number- Update DepositStreamModal and WithdrawStreamModal to use stream.contractStreamId instead of stream.id- Update test mock stream to include contractStreamId
@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

2 similar comments
@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 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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
apps/web/src/components/modules/payment-stream/StreamsHistory.tsx (1)

40-55: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Do not use fixture stream IDs for live contract actions.

fetchStreams returns static records, but deposit and withdrawal now use contractStreamId for real transactions. These fixture IDs can target unrelated on-chain streams when this view is used with a matching wallet.

Replace this mock query with contract-backed stream data before enabling actions. Otherwise, disable stream actions for fixture records.

🤖 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/StreamsHistory.tsx` around
lines 40 - 55, Replace the static stream records used by fetchStreams with
contract-backed data before allowing deposit or withdrawal actions to use
contractStreamId. Alternatively, identify fixture records in StreamsHistory and
disable their stream actions so their IDs cannot trigger live transactions.
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx (1)

212-220: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Remove the duplicate amount and durationMultiplier declarations.

Lines 212-216 declare these same block-scoped const variables twice in the same scope, which makes CreatePaymentStream.tsx fail TypeScript compilation.

Proposed fix
-      const amount = BigInt(Math.floor(parseFloat(streamData.amount) * 10000000));
-      const durationMultiplier = streamData.duration === 'hour' ? 3600 :
-        streamData.duration === 'day' ? 86400 :
-          streamData.duration === 'week' ? 604800 :
       const amount = BigInt(Math.floor(parseFloat(streamData.amount) * 10000000));
       const durationMultiplier = streamData.duration === 'hour' ? 3600 :
🤖 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`
around lines 212 - 220, Remove the duplicate amount and durationMultiplier const
declarations in CreatePaymentStream, keeping one complete declaration pair with
the existing hour/day/week/month duration mapping so the block compiles without
changing behavior.
apps/web/src/lib/api.ts (1)

132-137: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve contractStreamId precision across the contract boundary.

createStream returns a decimal string from a bigint, but these APIs and StreamRecord convert stream IDs to number. Values above Number.MAX_SAFE_INTEGER lose precision before BigInt(params.streamId) runs. A later deposit, withdrawal, or query can then target the wrong contract stream.

  • apps/web/src/lib/api.ts#L132-L137: accept string or bigint for withdraw.
  • apps/web/src/lib/api.ts#L228-L233: accept string or bigint for depositToStream.
  • apps/web/src/lib/api.ts#L240-L242: accept string or bigint for getWithdrawableAmount.
  • apps/web/src/lib/validations.ts#L6-L9: store contractStreamId as a decimal string at the UI boundary.

Convert the value directly with BigInt(streamId) only when building the contract call.

🤖 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/api.ts` around lines 132 - 137, Preserve stream ID precision
by updating withdraw, depositToStream, and getWithdrawableAmount in
apps/web/src/lib/api.ts at lines 132-137, 228-233, and 240-242 to accept string
or bigint, converting directly with BigInt(streamId) only when constructing
contract calls. Update StreamRecord in apps/web/src/lib/validations.ts at lines
6-9 to store contractStreamId as a decimal string at the UI boundary.
♻️ Duplicate comments (2)
apps/web/src/lib/stellar.test.ts (1)

117-153: 🩺 Stability & Availability | 🟡 Minor

Handle zero-duration streams in the utility and this test suite.

StellarService.calculateStreamProgress still divides by totalDuration and totalHours without handling startTime === endTime. A zero-duration stream can return NaN for progressPercentage and Infinity for ratePerHour. Add a regression test here and guard both divisors in apps/web/src/lib/stellar.ts.

🤖 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/stellar.test.ts` around lines 117 - 153, Update
StellarService.calculateStreamProgress in stellar.ts to handle streams where
startTime equals endTime, preventing division by zero in both progressPercentage
and ratePerHour while preserving normal progress behavior. Add a regression test
in the calculateStreamProgress test suite that creates a zero-duration stream
and verifies finite, valid results for both fields.
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx (1)

228-236: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Do not silently drop stream options.

The form and confirmation modal display cancelable and transferable. createStream accepts neither value, and this call does not send them. The created stream therefore does not reflect the selected options.

Pass both options through the API and contract call. If the contract does not support them, disable these controls and state that they are unavailable.

🤖 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`
around lines 228 - 236, Update the createStream flow in CreatePaymentStream to
pass the selected cancelable and transferable values through the API and
contract call, preserving the form and confirmation selections in the created
stream. If createStream or the contract cannot accept these options, disable the
corresponding controls and clearly mark them unavailable instead.
🤖 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/components/modules/payment-stream/WithdrawStreamModal.tsx`:
- Around line 137-142: Update the withdrawal flow in WithdrawStreamModal around
withdraw so the validated data.withdrawTo destination is honored by passing it
through the API and contract call; alternatively remove or disable the “Other
Address” option until destination support exists. Ensure the selected address
cannot be accepted by validation while being ignored during withdrawal.

---

Outside diff comments:
In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Around line 212-220: Remove the duplicate amount and durationMultiplier const
declarations in CreatePaymentStream, keeping one complete declaration pair with
the existing hour/day/week/month duration mapping so the block compiles without
changing behavior.

In `@apps/web/src/components/modules/payment-stream/StreamsHistory.tsx`:
- Around line 40-55: Replace the static stream records used by fetchStreams with
contract-backed data before allowing deposit or withdrawal actions to use
contractStreamId. Alternatively, identify fixture records in StreamsHistory and
disable their stream actions so their IDs cannot trigger live transactions.

In `@apps/web/src/lib/api.ts`:
- Around line 132-137: Preserve stream ID precision by updating withdraw,
depositToStream, and getWithdrawableAmount in apps/web/src/lib/api.ts at lines
132-137, 228-233, and 240-242 to accept string or bigint, converting directly
with BigInt(streamId) only when constructing contract calls. Update StreamRecord
in apps/web/src/lib/validations.ts at lines 6-9 to store contractStreamId as a
decimal string at the UI boundary.

---

Duplicate comments:
In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Around line 228-236: Update the createStream flow in CreatePaymentStream to
pass the selected cancelable and transferable values through the API and
contract call, preserving the form and confirmation selections in the created
stream. If createStream or the contract cannot accept these options, disable the
corresponding controls and clearly mark them unavailable instead.

In `@apps/web/src/lib/stellar.test.ts`:
- Around line 117-153: Update StellarService.calculateStreamProgress in
stellar.ts to handle streams where startTime equals endTime, preventing division
by zero in both progressPercentage and ratePerHour while preserving normal
progress behavior. Add a regression test in the calculateStreamProgress test
suite that creates a zero-duration stream and verifies finite, valid results for
both fields.
🪄 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: 2d443ce0-3256-43d6-aaf7-b7dfa5053667

📥 Commits

Reviewing files that changed from the base of the PR and between 623e5c4 and 754829d.

📒 Files selected for processing (8)
  • apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx
  • apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx
  • apps/web/src/components/modules/payment-stream/StreamsHistory.tsx
  • apps/web/src/components/modules/payment-stream/WithdrawStreamModal.tsx
  • apps/web/src/lib/api.ts
  • apps/web/src/lib/stellar.test.ts
  • apps/web/src/lib/stellar.ts
  • apps/web/src/lib/validations.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/src/lib/stellar.ts
  • apps/web/src/components/modules/payment-stream/DepositStreamModal.tsx

Comment on lines +137 to +142
const hash = await withdraw({
streamId: stream.contractStreamId,
amount,
sender: address,
signTransaction,
});

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Send withdrawTo or remove the alternate-address option.

When the user selects “Other Address”, the form validates data.withdrawTo. This withdraw call does not send it, and the API accepts no destination parameter. The selected address has no effect on the withdrawal.

Disable this option until the contract supports it, or pass the destination through the API and contract call.

🤖 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/WithdrawStreamModal.tsx`
around lines 137 - 142, Update the withdrawal flow in WithdrawStreamModal around
withdraw so the validated data.withdrawTo destination is honored by passing it
through the API and contract call; alternatively remove or disable the “Other
Address” option until destination support exists. Ensure the selected address
cannot be accepted by validation while being ignored during withdrawal.

@kathy-ai-art

Copy link
Copy Markdown
Author

Hello @pragmaticAweds please review and merge PR

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx (1)

200-208: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Remove the broken duplicate declarations.

durationMultiplier is cut off after the week branch, then amount and durationMultiplier are declared again below. This leaves CreatePaymentStream.tsx:204 with an unclosed ternary and duplicate declarations, so the file will not compile.

Proposed fix
-      const amount = BigInt(Math.floor(parseFloat(streamData.amount) * 10000000));
-      const durationMultiplier = streamData.duration === 'hour' ? 3600 :
-        streamData.duration === 'day' ? 86400 :
-          streamData.duration === 'week' ? 604800 :
       const amount = BigInt(Math.floor(parseFloat(streamData.amount) * 10000000));
       const durationMultiplier = streamData.duration === 'hour' ? 3600 :
         streamData.duration === 'day' ? 86400 :
           streamData.duration === 'week' ? 604800 :
             streamData.duration === 'month' ? 2592000 : 31536000;
🤖 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`
around lines 200 - 208, Remove the first incomplete amount and
durationMultiplier declarations in CreatePaymentStream, retaining the complete
declarations that include the month and default-year duration branches so the
function compiles without duplicate variables.
♻️ Duplicate comments (2)
apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx (2)

200-204: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Use exact decimal scaling for the on-chain amount.

parseFloat(streamData.amount) * 10000000 can round before Math.floor, so createStream can receive a different stroop amount than the user entered. This previous review finding remains present at Lines [200] and [204]. Use an exact decimal-string scaler or decimal library in this path and the fee-estimation path at Line [94].

🤖 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`
around lines 200 - 204, Replace floating-point amount conversion in
CreatePaymentStream, including the createStream amount and the fee-estimation
path around the fee calculation, with exact decimal-string scaling to seven
decimal places before converting to BigInt. Preserve the existing
floor/truncation behavior and ensure both paths use the same exact conversion
logic.

216-224: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve cancelable and transferable in the contract request.

The form still collects these options, but the createStream call does not pass them. The API definition in apps/web/src/lib/api.ts Lines [105]-[132] also does not accept or map these fields. The toggles therefore have no effect. Extend the API and contract call, or remove and disable the options until they are supported.

🤖 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`
around lines 216 - 224, Update the CreatePaymentStream submission and
createStream API contract to preserve the form’s cancelable and transferable
values, forwarding both fields into the underlying contract request and mapping
them as required. Ensure the toggles affect stream creation consistently;
alternatively remove and disable these options throughout the form if support
cannot be added.
🤖 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.

Outside diff comments:
In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Around line 200-208: Remove the first incomplete amount and durationMultiplier
declarations in CreatePaymentStream, retaining the complete declarations that
include the month and default-year duration branches so the function compiles
without duplicate variables.

---

Duplicate comments:
In `@apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx`:
- Around line 200-204: Replace floating-point amount conversion in
CreatePaymentStream, including the createStream amount and the fee-estimation
path around the fee calculation, with exact decimal-string scaling to seven
decimal places before converting to BigInt. Preserve the existing
floor/truncation behavior and ensure both paths use the same exact conversion
logic.
- Around line 216-224: Update the CreatePaymentStream submission and
createStream API contract to preserve the form’s cancelable and transferable
values, forwarding both fields into the underlying contract request and mapping
them as required. Ensure the toggles affect stream creation consistently;
alternatively remove and disable these options throughout the form if support
cannot be added.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 64c78b7d-077e-4d6c-908a-e61441a2e44c

📥 Commits

Reviewing files that changed from the base of the PR and between 754829d and 687dd9b.

📒 Files selected for processing (5)
  • apps/web/src/components/modules/payment-stream/CreatePaymentStream.tsx
  • apps/web/src/components/modules/payment-stream/StreamsHistory.tsx
  • apps/web/src/lib/api.ts
  • apps/web/src/lib/stellar.ts
  • apps/web/src/lib/validations.ts
💤 Files with no reviewable changes (1)
  • apps/web/src/components/modules/payment-stream/StreamsHistory.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/web/src/lib/validations.ts
  • apps/web/src/lib/api.ts
  • apps/web/src/lib/stellar.ts

@Idrhas
Idrhas merged commit 023a765 into Fundable-Protocol:main Aug 7, 2026
1 check passed
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(stellar.ts): legacy simulation methods present in StellarService class

2 participants