Skip to content

fix: stale state on previews#196

Merged
antoncoding merged 1 commit intomasterfrom
fix/util-and-post-action-calc
Nov 30, 2025
Merged

fix: stale state on previews#196
antoncoding merged 1 commit intomasterfrom
fix/util-and-post-action-calc

Conversation

@antoncoding
Copy link
Owner

@antoncoding antoncoding commented Nov 30, 2025

Summary by CodeRabbit

  • New Features

    • Added a manual refresh button to update balance information directly in the supply modal.
  • Bug Fixes

    • Fixed stale state issues when switching between supply and withdraw modes.
    • Improved balance data synchronization to ensure accurate display when modal reopens.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Contributor

vercel bot commented Nov 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
monarch Ready Ready Preview Comment Nov 30, 2025 3:31am

@coderabbitai
Copy link

coderabbitai bot commented Nov 30, 2025

📝 Walkthrough

Walkthrough

Adds manual balance refetch capability to the supply modal. Users can click a new Refetch button in SupplyModalContent to refresh their token and ETH balances. The useSupplyMarket hook exposes a refetch function, and SupplyModalV2 improves state handling by resetting preview amounts when the modal reopens.

Changes

Cohort / File(s) Summary
Supply modal UI enhancements
src/components/SupplyModalContent.tsx
Adds ReloadIcon import and Refetch button next to balance display. Button calls refetchBalance to refresh balances on demand. Removes unused console.log.
Supply modal state management
src/components/SupplyModalV2.tsx
Introduces useEffect to reset mode and preview amounts when modal reopens. Adds useMemo for supplyDelta calculation. Updates mode toggle button styling (hover text color).
Balance refetch API
src/hooks/useSupplyMarket.ts
Exposes new refetch function in UseSupplyMarketReturn interface. Internal implementation combines token and ETH balance refetches via useCallback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Check that the refetch button correctly wires to the hook's refetch function
  • Verify the useEffect dependency array in SupplyModalV2 (defaultMode) prevents infinite resets
  • Confirm parallel refetch execution in useSupplyMarket doesn't cause race conditions

Possibly related PRs

  • feat: add monad chain #194: Removes the stray console.log that was added to SupplyModalContent—direct cleanup of code in this PR.
  • feat: refetch #58: Adds manual refetch functionality to supply components, overlapping with this refetch button feature.
  • feat: preview withdraw #178: Modifies supplyDelta and preview amount handling in SupplyModalV2, touching similar state management logic.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix across multiple files: preventing stale state in preview amounts when toggling supply/withdraw mode.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/util-and-post-action-calc

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
src/components/SupplyModalContent.tsx (1)

33-36: Add refetch to onSuccess dependencies

onSuccess closes the modal and calls refetch, but the callback only depends on onClose. If refetch ever changes, this can use a stale version and will also trip the hooks lint rules. Suggest:

-  const onSuccess = useCallback(() => {
-    onClose();
-    refetch();
-  }, [onClose]);
+  const onSuccess = useCallback(() => {
+    onClose();
+    refetch();
+  }, [onClose, refetch]);
🧹 Nitpick comments (2)
src/components/SupplyModalV2.tsx (1)

44-55: supplyDelta memo logic is correct but could be clearer

The positive/negative delta handling looks right and should avoid zero/no-op values. For readability you might replace the x && x > 0n pattern with an explicit if (!x || x <= 0n) return undefined; style, but that’s optional.

src/hooks/useSupplyMarket.ts (1)

96-100: Combined refetch implementation is fine; async variant optional

Calling both refetchToken and refetchETH inside a memoized callback is enough here. If you ever need to await completion, you could switch to:

const refetch = useCallback(async () => {
  await Promise.all([refetchToken(), refetchETH()]);
}, [refetchETH, refetchToken]);

For now, the void-fire-and-forget version is acceptable.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f23dc44 and 3e19ed0.

📒 Files selected for processing (3)
  • src/components/SupplyModalContent.tsx (3 hunks)
  • src/components/SupplyModalV2.tsx (4 hunks)
  • src/hooks/useSupplyMarket.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx,js,jsx,css,scss}

📄 CodeRabbit inference engine (AGENTS.md)

Run pnpm format (Prettier) before pushing with 2-space indentation, 100-character width, single quotes, and Tailwind-aware class ordering

Files:

  • src/components/SupplyModalV2.tsx
  • src/hooks/useSupplyMarket.ts
  • src/components/SupplyModalContent.tsx
**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use PascalCase for React component file names (e.g., VaultBanner.tsx)

Files:

  • src/components/SupplyModalV2.tsx
  • src/components/SupplyModalContent.tsx
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use camelCase for helper function names (e.g., formatApr)

Files:

  • src/components/SupplyModalV2.tsx
  • src/hooks/useSupplyMarket.ts
  • src/components/SupplyModalContent.tsx
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{tsx,jsx}: Keep Tailwind class lists lean and dedupe variants with tailwind-merge
All toggles must use the shared IconSwitch component from @/components/common/IconSwitch for consistent sizing and animation

Files:

  • src/components/SupplyModalV2.tsx
  • src/components/SupplyModalContent.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

ESLint (Airbnb + Next.js) enforces hook safety and import hygiene

Files:

  • src/components/SupplyModalV2.tsx
  • src/hooks/useSupplyMarket.ts
  • src/components/SupplyModalContent.tsx
src/hooks/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

When building on-chain hooks, mirror useERC20Approval and useTransactionWithToast patterns and memoize arrays/objects before using them in effect dependencies to prevent redundant RPC calls

Files:

  • src/hooks/useSupplyMarket.ts
🧠 Learnings (3)
📚 Learning: 2024-11-25T09:39:42.148Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 87
File: app/home/HomePage.tsx:17-39
Timestamp: 2024-11-25T09:39:42.148Z
Learning: In `app/home/HomePage.tsx`, the `useEffect` hook depends on `[showCustomized]` because changing `showCustomized` triggers updates to the yield and risk terms.

Applied to files:

  • src/components/SupplyModalV2.tsx
  • src/components/SupplyModalContent.tsx
📚 Learning: 2025-11-25T14:45:50.378Z
Learnt from: CR
Repo: antoncoding/monarch PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T14:45:50.378Z
Learning: Applies to src/hooks/**/*.{ts,tsx} : When building on-chain hooks, mirror `useERC20Approval` and `useTransactionWithToast` patterns and memoize arrays/objects before using them in effect dependencies to prevent redundant RPC calls

Applied to files:

  • src/components/SupplyModalV2.tsx
  • src/hooks/useSupplyMarket.ts
📚 Learning: 2025-11-25T14:45:50.378Z
Learnt from: CR
Repo: antoncoding/monarch PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T14:45:50.378Z
Learning: Applies to **/*.{tsx,jsx} : All toggles must use the shared `IconSwitch` component from `@/components/common/IconSwitch` for consistent sizing and animation

Applied to files:

  • src/components/SupplyModalContent.tsx
🧬 Code graph analysis (2)
src/components/SupplyModalV2.tsx (1)
src/hooks/useFreshMarketsState.ts (1)
  • useFreshMarketsState (28-154)
src/components/SupplyModalContent.tsx (2)
src/utils/balance.ts (1)
  • formatBalance (21-23)
src/utils/networks.ts (1)
  • getNativeTokenSymbol (211-213)
🔇 Additional comments (8)
src/components/SupplyModalV2.tsx (3)

31-36: Effect reset on defaultMode looks fine; confirm open behavior

Resetting mode and preview amounts when defaultMode changes should prevent stale previews. This assumes the modal is either remounted on close or defaultMode is updated when reopening; worth double‑checking usage in parents but the effect itself is sound.


83-90: Good call resetting previews on mode toggle

Toggling between supply/withdraw while clearing both preview amounts directly addresses stale preview state when switching modes.


105-105: Using shared supplyDelta for MarketDetailsBlock is consistent

Passing the memoized supplyDelta keeps preview logic in one place and should avoid divergent calculations between the modal and details block.

Please confirm MarketDetailsBlock expects a signed delta (positive for supply, negative for withdraw) so the new behavior matches its internal assumptions.

src/components/SupplyModalContent.tsx (2)

57-57: Alias refetchrefetchBalance is straightforward

Destructuring refetch from useSupplyMarket as refetchBalance keeps the hook’s API generic while naming is clear at the call site.


115-130: Balance display + Refetch button look good

The balance formatting and symbol selection match the existing pattern, and the small ReloadIcon button with aria-label cleanly hooks into refetchBalance. No issues from a UX or code perspective.

src/hooks/useSupplyMarket.ts (3)

18-44: Adding refetch to UseSupplyMarketReturn is a clean API extension

Extending the return type with a refetch action is backward‑compatible and matches how the hook is now used from SupplyModalContent.


60-71: Using refetch from both useBalance calls is appropriate

Grabbing refetch for token and ETH balances gives you explicit, controllable refreshes without changing existing balance usage.


354-368: Exposing refetch in the returned object is consistent

Returning refetch alongside tokenBalance/ethBalance makes sense for consumers like SupplyModalContent that want a manual refresh.

@antoncoding antoncoding merged commit 7e1d603 into master Nov 30, 2025
4 checks passed
@antoncoding antoncoding deleted the fix/util-and-post-action-calc branch November 30, 2025 03:33
This was referenced Dec 9, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 26, 2025
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