Skip to content

web(WalletStatus): display locked badge when extension wallet is locked - #555

Merged
Idrhas merged 1 commit into
Fundable-Protocol:mainfrom
muizbolaji4:fix/locked-wallet-badge
Aug 3, 2026
Merged

web(WalletStatus): display locked badge when extension wallet is locked#555
Idrhas merged 1 commit into
Fundable-Protocol:mainfrom
muizbolaji4:fix/locked-wallet-badge

Conversation

@muizbolaji4

@muizbolaji4 muizbolaji4 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR fixes locked extension wallets showing as a generic disconnected state. When connect fails with the stellar-wallets-kit locked/empty-address error code (-3) or unlock-related messages, the UI now surfaces a dedicated Locked badge via WalletStatus.

Related Issue

Closes #393

Changes

🔒 Locked wallet detection

  • [ADD] apps/web/src/utils/wallet-errors.ts

    • Defines WALLET_LOCKED_ERROR_CODE (-3) matching @creit.tech/stellar-wallets-kit Freighter empty-address errors.
    • isLockedWalletError() detects code -3 address errors and locked/unlock message patterns.
  • [MODIFY] apps/web/src/providers/StellarWalletProvider.tsx

    • Extends ConnectionStatus with "locked".
    • Exposes isLocked on wallet context.
    • On connect failure, sets connectionStatus to "locked" when a locked-wallet error is detected (instead of falling back to idle/disconnected).

🏷️ WalletStatus badge

  • [ADD] apps/web/src/components/molecules/WalletStatus.tsx

    • Renders Locked badge (amber) when isLocked — lines 15–35 implement the locked-state UI from the issue.
    • Also covers connecting / connected badge states for reuse.
    • Locked badge opens the connect modal so users can retry after unlocking.
  • [MODIFY] apps/web/src/components/organisms/connect-button.tsx

    • Shows WalletStatus Locked badge instead of the generic CONNECT WALLET CTA when the extension is locked.

✅ Tests

  • [ADD] apps/web/src/utils/wallet-errors.test.ts
  • [ADD] apps/web/src/components/molecules/WalletStatus.test.tsx

Verification Results

pnpm exec vitest run src/utils/wallet-errors.test.ts src/components/molecules/WalletStatus.test.tsx
✅ 9/9 passed
Acceptance Criteria Status
Issue resolved in WalletStatus.tsx:15-35 (locked badge) ✅ Locked badge rendered when isLocked
Detect locked wallet error code ✅ Code -3 + unlock/locked messages
No regression in existing test suites ✅ New focused tests pass; no production API regressions

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added clear wallet status indicators for locked, connecting, and connected states.
    • Added a wallet unlock prompt when the browser extension is locked.
    • Connected wallets now display a recognizable connected badge and accessible address label.
  • Bug Fixes

    • Improved detection and handling of wallet-locked errors across supported error formats.
  • Tests

    • Added coverage for wallet status displays and locked-wallet error detection.

Detect stellar-wallets-kit locked/empty-address error code (-3) and unlock messages so WalletStatus renders a Locked badge instead of the generic disconnected Connect CTA.

Closes Fundable-Protocol#393
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@muizbolaji4 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added locked-wallet error detection, provider state handling, and a WalletStatus component. ConnectButton now renders the locked badge, while tests cover locked, disconnected, connected, and connecting states.

Changes

Locked wallet status

Layer / File(s) Summary
Locked-wallet error detection
apps/web/src/utils/wallet-errors.ts, apps/web/src/utils/wallet-errors.test.ts
Detects locked-wallet errors across structured payloads, Error instances, and strings, with corresponding Vitest coverage.
Provider locked state
apps/web/src/providers/StellarWalletProvider.tsx
Adds the "locked" connection status, detects matching connection errors, notifies the user, and exposes isLocked through wallet context.
Wallet status rendering and integration
apps/web/src/components/molecules/WalletStatus.tsx, apps/web/src/components/molecules/WalletStatus.test.tsx, apps/web/src/components/organisms/connect-button.tsx
Renders locked, connecting, and connected states; ConnectButton routes locked wallets to WalletStatus, with component tests for each state.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • Fundable-Protocol/stellar_client_os issue 293 — Covers the same locked-wallet detection and “Locked” status behavior implemented here.

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant WalletExtension
  participant StellarWalletProvider
  participant ConnectButton
  participant WalletStatus
  WalletExtension->>StellarWalletProvider: Return locked-wallet error
  StellarWalletProvider->>StellarWalletProvider: Set connectionStatus to locked
  StellarWalletProvider->>ConnectButton: Expose isLocked
  ConnectButton->>WalletStatus: Render Locked badge
  WalletStatus->>StellarWalletProvider: Open wallet modal on click
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific and matches the main change: showing a locked badge for locked extension wallets.
Linked Issues check ✅ Passed The PR detects locked-wallet errors and shows a dedicated Locked badge in WalletStatus, with tests added and no apparent regression risk.
Out of Scope Changes check ✅ Passed The provider, utility, and test updates support the locked-badge flow and do not appear unrelated to the issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/src/components/molecules/WalletStatus.test.tsx (1)

16-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the Locked badge opens the retry modal.

The test passes if onClick={openModal} is removed. Keep an openModal mock reference, click the labeled button, and assert it was called once.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/components/molecules/WalletStatus.test.tsx` around lines 16 -
29, Update the locked-wallet test around WalletStatus to retain a named
openModal mock, click the labeled locked-wallet button, and assert the mock is
called exactly once; keep the existing Locked status assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/utils/wallet-errors.ts`:
- Around line 23-25: Update the error classification logic around the
WalletErrorLike normalization to inspect both the top-level err.message and
nested err.error?.message instead of allowing a generic wrapper message to mask
the nested message. Preserve code extraction, ensure either normalized message
can trigger the appropriate classification, and add a regression case for a
wrapper containing “RPC failed” with nested code -3 and “Getting the address...”
message.

---

Nitpick comments:
In `@apps/web/src/components/molecules/WalletStatus.test.tsx`:
- Around line 16-29: Update the locked-wallet test around WalletStatus to retain
a named openModal mock, click the labeled locked-wallet button, and assert the
mock is called exactly once; keep the existing Locked status assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 55ec5fd3-21c0-46ea-b6c5-e15e1dbdc7c8

📥 Commits

Reviewing files that changed from the base of the PR and between 375c936 and aaa8900.

📒 Files selected for processing (6)
  • apps/web/src/components/molecules/WalletStatus.test.tsx
  • apps/web/src/components/molecules/WalletStatus.tsx
  • apps/web/src/components/organisms/connect-button.tsx
  • apps/web/src/providers/StellarWalletProvider.tsx
  • apps/web/src/utils/wallet-errors.test.ts
  • apps/web/src/utils/wallet-errors.ts

Comment on lines +23 to +25
const err = error as WalletErrorLike;
const code = err.code ?? err.error?.code;
const message = String(err.message ?? err.error?.message ?? "").toLowerCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Inspect both wrapper and nested error messages.

A generic top-level message masks error.message, so { message: "RPC failed", error: { code: -3, message: "Getting the address..." } } is misclassified and the provider falls back to the generic disconnected flow. Normalize and inspect both messages; add this wrapper shape as a regression case.

Proposed fix
-  const message = String(err.message ?? err.error?.message ?? "").toLowerCase();
+  const messages = [err.message, err.error?.message]
+    .map((value) => String(value ?? "").toLowerCase());
+
+  const hasLockedMessage = messages.some(
+    (message) =>
+      message.includes("locked") || message.includes("unlock"),
+  );
 
-  if (
-    message.includes("locked") ||
-    message.includes("unlock") ||
-    message.includes("wallet is locked")
-  ) {
+  if (hasLockedMessage) {
     return true;
   }
 
-  if (code === WALLET_LOCKED_ERROR_CODE && message.includes("address")) {
+  if (
+    code === WALLET_LOCKED_ERROR_CODE &&
+    messages.some((message) => message.includes("address"))
+  ) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const err = error as WalletErrorLike;
const code = err.code ?? err.error?.code;
const message = String(err.message ?? err.error?.message ?? "").toLowerCase();
const err = error as WalletErrorLike;
const code = err.code ?? err.error?.code;
const messages = [err.message, err.error?.message]
.map((value) => String(value ?? "").toLowerCase());
const hasLockedMessage = messages.some(
(message) =>
message.includes("locked") || message.includes("unlock"),
);
if (hasLockedMessage) {
return true;
}
if (
code === WALLET_LOCKED_ERROR_CODE &&
messages.some((message) => message.includes("address"))
) {
return true;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/utils/wallet-errors.ts` around lines 23 - 25, Update the error
classification logic around the WalletErrorLike normalization to inspect both
the top-level err.message and nested err.error?.message instead of allowing a
generic wrapper message to mask the nested message. Preserve code extraction,
ensure either normalized message can trigger the appropriate classification, and
add a regression case for a wrapper containing “RPC failed” with nested code -3
and “Getting the address...” message.

@Idrhas

Idrhas commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates

@Idrhas
Idrhas merged commit 0b08d8d into Fundable-Protocol:main Aug 3, 2026
1 check 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.

web(WalletStatus): display locked badge when extension wallet is locked

2 participants