Problem
When a user disconnects their wallet (via the wallet dropdown), only the wallet state is cleared. The role context persists in localStorage, meaning:
- User onboards as "business", role saved to localStorage
- User disconnects wallet
- User reconnects wallet — they're automatically routed to `/dashboard/business` without going through onboarding again
- 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
Problem
When a user disconnects their wallet (via the wallet dropdown), only the wallet state is cleared. The role context persists in localStorage, meaning:
Files:
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