Skip to content

🩹 app: ground date calculations in block timestamp#916

Merged
cruzdanilo merged 3 commits intomainfrom
timestamp
Mar 26, 2026
Merged

🩹 app: ground date calculations in block timestamp#916
cruzdanilo merged 3 commits intomainfrom
timestamp

Conversation

@cruzdanilo
Copy link
Copy Markdown
Member

@cruzdanilo cruzdanilo commented Mar 26, 2026


Open with Devin

Summary by CodeRabbit

  • Bug Fixes

    • Date/due/upcoming/overdue logic now uses a centralized on-chain timestamp for consistent, accurate maturities across the app.
  • Performance

    • Reduced redundant date computations and memoized date formatting to improve render performance and responsiveness.
  • UX

    • More consistent due-date labels, refresh behavior, and timing across lists, cards, and payment flows.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 26, 2026

🦋 Changeset detected

Latest commit: 9c2f63f

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

Warning

Rate limit exceeded

@cruzdanilo has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 38 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3c923484-dc6b-4749-a8c9-90b5829d4e8d

📥 Commits

Reviewing files that changed from the base of the PR and between c29872b and 9c2f63f.

📒 Files selected for processing (31)
  • .changeset/calm-foxes-tick.md
  • src/components/add-funds/Bridge.tsx
  • src/components/card/Card.tsx
  • src/components/card/exa-card/CardContents.tsx
  • src/components/home/AssetList.tsx
  • src/components/home/Home.tsx
  • src/components/home/Portfolio.tsx
  • src/components/loans/Amount.tsx
  • src/components/loans/Asset.tsx
  • src/components/loans/CreditLine.tsx
  • src/components/loans/LoanSummary.tsx
  • src/components/loans/Loans.tsx
  • src/components/loans/Maturity.tsx
  • src/components/loans/Review.tsx
  • src/components/pay/Calculator.tsx
  • src/components/pay/OverduePayments.tsx
  • src/components/pay/Pay.tsx
  • src/components/pay/PaymentSheet.tsx
  • src/components/pay/Repay.tsx
  • src/components/pay/UpcomingPayments.tsx
  • src/components/roll-debt/RollDebt.tsx
  • src/components/shared/Failure.tsx
  • src/components/shared/Pending.tsx
  • src/components/shared/Success.tsx
  • src/components/shared/TransactionDetails.tsx
  • src/components/swaps/Swaps.tsx
  • src/utils/useAsset.ts
  • src/utils/useInstallmentRates.ts
  • src/utils/useInstallments.ts
  • src/utils/useMarkets.ts
  • src/utils/usePortfolio.ts

Walkthrough

Adds a new useMarkets() hook that centralizes market, rate snapshot, and block-timestamp reads; ~25 components and several hooks now consume markets/timestamp instead of direct previewer contract reads or client-side Date.now(), with date formatting moved into memos.

Changes

Cohort / File(s) Summary
New Hook & Changeset
src/utils/useMarkets.ts, .changeset/calm-foxes-tick.md
Add useMarkets() that multicalls previewer, rate snapshot, and multicall timestamp; expose { markets, rateSnapshot, timestamp, firstMaturity, ...rest }. Add changeset noting block-timestamp-based ground date calculations.
High-level market consumers
src/components/.../Home.tsx, src/components/.../AssetList.tsx, src/components/.../Portfolio.tsx, src/components/card/Card.tsx, src/components/card/exa-card/CardContents.tsx, src/components/add-funds/Bridge.tsx, src/components/swaps/Swaps.tsx
Replace direct useReadPreviewerExactly/previewerAddress reads with useMarkets(); derive rates via floatingDepositRates(rateSnapshot, Number(timestamp)); remove previewer/ratePreviewer imports and account-gated query args.
Payments
src/components/pay/Pay.tsx, src/components/pay/PaymentSheet.tsx, src/components/pay/UpcomingPayments.tsx, src/components/pay/OverduePayments.tsx, src/components/pay/Repay.tsx, src/components/pay/Calculator.tsx
Switch to useMarkets() / asset timestamp; change overdue checks from date-fns to maturity < timestamp; memoize and memo-depend date labels on timestamp/language.
Loans & related UI
src/components/loans/Loans.tsx, src/components/loans/LoanSummary.tsx, src/components/loans/Maturity.tsx, src/components/loans/Review.tsx, src/components/loans/CreditLine.tsx, src/components/loans/Asset.tsx, src/components/loans/Amount.tsx, src/components/roll-debt/RollDebt.tsx
Replace previewer reads with useMarkets() or asset timestamp; adjust maturity/APR math to use block timestamp; memoize localized date strings and update hook inputs/outputs accordingly.
Shared UI components
src/components/shared/Failure.tsx, src/components/shared/Pending.tsx, src/components/shared/Success.tsx, src/components/shared/TransactionDetails.tsx
Add timestamp prop where applicable; replace date-fns isBefore/isAfter usage with direct bigint comparisons against timestamp; memoize formatted due-date strings; update component signatures for Pending/Success/Failure.
Utilities / Hooks
src/utils/useAsset.ts, src/utils/useInstallments.ts, src/utils/useInstallmentRates.ts, src/utils/usePortfolio.ts
useAsset now surfaces timestamp/firstMaturity; useInstallments removes external timestamp param and sources time from useAsset; installment/rates/portfolio hooks now use block timestamp and updated memo deps.
Other files (various)
src/components/card/..., src/components/shared/..., src/components/loans/... (multiple edits across repository)
Broad internal import/hook migrations from previewer contract reads to centralized useMarkets() and migration of time logic from client clock to block timestamp; assorted useMemo additions and dependency updates.

Sequence Diagram(s)

sequenceDiagram
    participant Component as UI Component
    participant Hook as useMarkets()
    participant ReadContracts as useReadContracts
    participant Contracts as On-chain Contracts

    Component->>Hook: call useMarkets({ enabled?, refetchInterval? })
    Hook->>ReadContracts: batch calls (multicall)
    ReadContracts->>Contracts: previewer.exactly(account), ratePreviewer.snapshot(), multicall.getCurrentBlockTimestamp()
    Contracts-->>ReadContracts: return [markets, rateSnapshot, blockTimestamp]
    ReadContracts-->>Hook: normalize and derive { markets, rateSnapshot, timestamp, firstMaturity }
    Hook-->>Component: return { markets, rateSnapshot, timestamp, firstMaturity, refetch, isFetching }
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • franm91
  • dieguezguille
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main objective: refactoring date/time calculations throughout the codebase to use block timestamp from a centralized useMarkets hook instead of client-side Date.now() calls.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch timestamp

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 and usage tips.

sentry[bot]

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@sentry
Copy link
Copy Markdown

sentry bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 93.24324% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.57%. Comparing base (526db16) to head (9c2f63f).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/components/shared/Failure.tsx 0.00% 2 Missing ⚠️
src/components/loans/LoanSummary.tsx 75.00% 1 Missing ⚠️
src/components/pay/Calculator.tsx 75.00% 1 Missing ⚠️
src/components/pay/Repay.tsx 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #916      +/-   ##
==========================================
+ Coverage   70.80%   71.57%   +0.76%     
==========================================
  Files         225      227       +2     
  Lines        8198     8197       -1     
  Branches     2634     2621      -13     
==========================================
+ Hits         5805     5867      +62     
+ Misses       2165     2102      -63     
  Partials      228      228              
Flag Coverage Δ
e2e 71.57% <93.24%> (+19.92%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

sentry[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 9 additional findings in Devin Review.

Open in Devin Review

@cruzdanilo cruzdanilo merged commit 9c2f63f into main Mar 26, 2026
11 of 14 checks passed
@cruzdanilo cruzdanilo deleted the timestamp branch March 26, 2026 20:23
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.

1 participant