Skip to content

feat(wallet): add sidebar variant and fix connect/disconnect flow#63

Merged
JoelVR17 merged 2 commits intoTrustless-Work:developfrom
andreMD287:develop
Mar 12, 2026
Merged

feat(wallet): add sidebar variant and fix connect/disconnect flow#63
JoelVR17 merged 2 commits intoTrustless-Work:developfrom
andreMD287:develop

Conversation

@andreMD287
Copy link
Copy Markdown
Contributor

@andreMD287 andreMD287 commented Mar 12, 2026

Summary

  • Wallet connect/disconnect fix: When disconnected (walletAddress is null), the button now correctly shows "Conectar Billetera" instead of an empty popover. Users can disconnect and reconnect without issues.
  • Sidebar variant: Added variant="sidebar" to WalletButton for use inside sidebars. Uses bg-sidebar-accent and border instead of dark background (bg-primary), so it fits the sidebar layout.
  • SidebarWalletButton: Passes variant="sidebar" to WalletButton for the investor app sidebar.

Files changed

  • packages/tw-blocks-shared/src/wallet-kit/WalletButtons.tsx — Added variant prop, conditional connect button styling, fixed connect/disconnect UI logic
  • packages/ui/src/sidebar-wallet-button.tsx — Pass variant="sidebar" to WalletButton

Test plan

  • Backoffice (localhost:3000): Connect wallet → disconnect → connect again → works
  • Investor (localhost:3001): Sidebar wallet shows "Conectar Billetera" when disconnected (no dark/black background)
  • Investor: Connect → disconnect → connect again → works
  • Investor: When sidebar is collapsed, wallet button adapts correctly

Summary by CodeRabbit

  • Enhancements
    • Wallet button component now supports context-aware styling variants, enabling tailored visual presentation based on where it appears in the interface (default view or sidebar).

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

The WalletButton component now supports a variant prop system ("default" or "sidebar") to enable variant-specific styling. SidebarWalletButton updated to pass the "sidebar" variant, while the core logic now depends on both mount state and wallet address.

Changes

Cohort / File(s) Summary
WalletButton Component Variant System
packages/tw-blocks-shared/src/wallet-kit/WalletButtons.tsx
Added WalletButtonProps type with optional variant prop. Implemented variant-driven styling logic via connectButtonClass computed value. Updated early-return condition to also check walletAddress alongside mount state. onClick handler consolidated to always invoke handleConnect for unauthenticated state.
SidebarWalletButton Integration
packages/ui/src/sidebar-wallet-button.tsx
Updated WalletButton invocation to pass variant="sidebar" prop for styled differentiation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • JoelVR17
  • armandocodecr

Poem

🐰 A button wears a coat of choice,
"Default" or "Sidebar" to rejoice,
Variants bloom like clover fair,
With styling magic in the air! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly and specifically describes the two main changes in the PR: adding a sidebar variant to the WalletButton component and fixing the connect/disconnect flow logic.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

Copy link
Copy Markdown

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/tw-blocks-shared/src/wallet-kit/WalletButtons.tsx`:
- Around line 50-55: Add a hydrated boolean to the WalletProvider context and
set it true when the localStorage restore effect completes, then include
hydrated in the provider value; in WalletButtons.tsx stop relying on the local
mounted flag and change the early-return guard from "if (!mounted ||
!walletAddress)" to "if (!hydrated || !walletAddress)" (keeping handleConnect
and connectButtonClass usage unchanged) so the connect CTA is hidden until
provider hydration finishes and prevents invoking handleConnect during the
restore window.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5adf4f89-b9a5-4300-80f7-fa9005fe468f

📥 Commits

Reviewing files that changed from the base of the PR and between 87c2857 and e0831cc.

📒 Files selected for processing (2)
  • packages/tw-blocks-shared/src/wallet-kit/WalletButtons.tsx
  • packages/ui/src/sidebar-wallet-button.tsx

Comment on lines +50 to +55
if (!mounted || !walletAddress) {
return (
<button
type="button"
onClick={mounted ? handleConnect : undefined}
className="flex w-full items-center gap-2 rounded-xl px-3 h-12 bg-primary text-primary-foreground hover:bg-brand-primary-hover transition-colors font-medium text-sm cursor-pointer"
onClick={handleConnect}
className={connectButtonClass}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C3 'useState<string \| null>\(null\)|localStorage.getItem|handleConnect|openModal' \
  packages/tw-blocks-shared/src/wallet-kit/WalletProvider.tsx \
  packages/tw-blocks-shared/src/wallet-kit/useWallet.ts

Repository: Trustless-Work/tokenization-private-credit

Length of output: 3254


🏁 Script executed:

cat -n packages/tw-blocks-shared/src/wallet-kit/WalletButtons.tsx | head -70

Repository: Trustless-Work/tokenization-private-credit

Length of output: 3097


🏁 Script executed:

cat -n packages/tw-blocks-shared/src/wallet-kit/WalletProvider.tsx

Repository: Trustless-Work/tokenization-private-credit

Length of output: 3634


🏁 Script executed:

cat -n packages/tw-blocks-shared/src/wallet-kit/useWalletContext.ts

Repository: Trustless-Work/tokenization-private-credit

Length of output: 178


Expose a hydration flag from WalletProvider to prevent showing the connect CTA during the hydration window.

The current code initializes walletAddress as null and restores persisted wallet data in a useEffect. Line 50 treats falsy walletAddress as "disconnected", but the local mounted flag only tracks component mount, not provider hydration. This creates a race condition: already-connected users briefly see the connect button after the component mounts but before the localStorage restore effect completes, and handleConnect() can be invoked during this transient state.

Add a hydrated boolean to the context. Update WalletProvider to track when the localStorage restore effect completes and expose that in the context value. Then change the check in WalletButtons.tsx line 50 to gate on hydration first:

-  const { walletAddress, walletName } = useWalletContext();
+  const { walletAddress, walletName, hydrated } = useWalletContext();

-  if (!mounted || !walletAddress) {
+  if (!hydrated) {
+    return null;
+  }
+
+  if (!walletAddress) {
     return (

This removes the need for the local mounted gate in WalletButtons.tsx.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/tw-blocks-shared/src/wallet-kit/WalletButtons.tsx` around lines 50 -
55, Add a hydrated boolean to the WalletProvider context and set it true when
the localStorage restore effect completes, then include hydrated in the provider
value; in WalletButtons.tsx stop relying on the local mounted flag and change
the early-return guard from "if (!mounted || !walletAddress)" to "if (!hydrated
|| !walletAddress)" (keeping handleConnect and connectButtonClass usage
unchanged) so the connect CTA is hidden until provider hydration finishes and
prevents invoking handleConnect during the restore window.

@JoelVR17 JoelVR17 merged commit d0fe1fa into Trustless-Work:develop Mar 12, 2026
1 of 4 checks 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.

3 participants