Skip to content

fix: Wallet disconnect should clear role context and reset to landing page state #81

Description

@JamesVictor-O

Problem

When a user disconnects their wallet (via the wallet dropdown), only the wallet state is cleared. The role context persists in localStorage, meaning:

  1. User onboards as "business", role saved to localStorage
  2. User disconnects wallet
  3. User reconnects wallet — they're automatically routed to `/dashboard/business` without going through onboarding again
  4. Or worse: a different user connects their wallet on the same browser and inherits the previous user's role

Files:

  • `components/wallet/wallet-provider.tsx` (line 83-86) — `disconnect()` only clears wallet state
  • `components/role/role-context.tsx` — role persists independently in localStorage

Fix

When the wallet disconnects, also clear the role:

Option A — Clear role in disconnect handler

Add `useRole` to the wallet dropdown and clear on disconnect:

`components/wallet/connect-wallet-button.tsx`:
```tsx
import { useRole } from "@/components/role/role-context";

// Inside the component:
const { setRole } = useRole();

// In the disconnect handler:
onClick={() => {
disconnect();
setRole(null); // Clear persisted role
setIsOpen(false);
}}
```

`components/wallet/wallet-chip.tsx`:
Same change in the dashboard wallet chip disconnect handler.

Option B — Add an `onDisconnect` callback to WalletProvider

Let consumers register cleanup callbacks that fire on disconnect.


Acceptance Criteria

  • Disconnecting wallet clears the role from localStorage
  • After disconnect, navigating to `/dashboard` redirects to `/dashboard/business` (default, not cached role)
  • Reconnecting wallet and clicking "Start a campaign" opens fresh onboarding
  • Works in both Navbar wallet button and dashboard wallet chip

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignbugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions