bug: Wallet disconnects on page refresh (no auto-reconnect) #8

Closed
opened 2026-03-12 04:24:00 +00:00 by Brouie · 15 comments
Brouie commented 2026-03-12 04:24:00 +00:00 (Migrated from gitlab.com)

Description

After connecting Keplr wallet successfully, refreshing the page causes the wallet to disconnect. User must manually reconnect after every refresh.

Expected

Wallet should auto-reconnect on page refresh if Keplr is still authorized for the site.

Steps to Reproduce

  1. Open DEX frontend
  2. Connect Keplr wallet — connects successfully
  3. Refresh page (F5 or Ctrl+R)
  4. Wallet shows as disconnected

Environment

  • Browser: [your browser]
  • Keplr: [version]
  • Frontend: v0.1.0 (post big update, Vite 7.3.1)
  • LocalTerra devnet

Notes

May share root cause with #7 (wallet state not reaching swap page). Both point to wallet state not being persisted/restored properly.

## Description After connecting Keplr wallet successfully, refreshing the page causes the wallet to disconnect. User must manually reconnect after every refresh. ## Expected Wallet should auto-reconnect on page refresh if Keplr is still authorized for the site. ## Steps to Reproduce 1. Open DEX frontend 2. Connect Keplr wallet — connects successfully 3. Refresh page (F5 or Ctrl+R) 4. Wallet shows as disconnected ## Environment - Browser: [your browser] - Keplr: [version] - Frontend: v0.1.0 (post big update, Vite 7.3.1) - LocalTerra devnet ## Notes May share root cause with #7 (wallet state not reaching swap page). Both point to wallet state not being persisted/restored properly.
PlasticDigits commented 2026-03-12 07:04:32 +00:00 (Migrated from gitlab.com)

Fix has been committed in c77b96d — the wallet now auto-reconnects on page refresh.

What changed (frontend-dapp/src/hooks/useWallet.ts):

  • On successful connect, the wallet connection params (walletName, walletType) are persisted to localStorage.
  • On disconnect, the stored params are cleared.
  • On page load, the store reads the saved params and silently re-establishes the connection. If auto-reconnect fails (e.g. Keplr authorization was revoked), the stale entry is cleaned up automatically.

@Brouie — can you verify this works on your end? Connect Keplr, refresh the page, and confirm the wallet stays connected. Leaving this open until verified.

Fix has been committed in `c77b96d` — the wallet now auto-reconnects on page refresh. **What changed (`frontend-dapp/src/hooks/useWallet.ts`):** - On successful connect, the wallet connection params (`walletName`, `walletType`) are persisted to `localStorage`. - On disconnect, the stored params are cleared. - On page load, the store reads the saved params and silently re-establishes the connection. If auto-reconnect fails (e.g. Keplr authorization was revoked), the stale entry is cleaned up automatically. @Brouie — can you verify this works on your end? Connect Keplr, refresh the page, and confirm the wallet stays connected. Leaving this open until verified.
PlasticDigits commented 2026-03-12 11:49:15 +00:00 (Migrated from gitlab.com)

mentioned in commit c77b96d84f

mentioned in commit c77b96d84f185d3067a0df248c4ec34e51c4c846
Brouie commented 2026-03-13 02:02:26 +00:00 (Migrated from gitlab.com)

mentioned in issue #1

mentioned in issue #1
Brouie commented 2026-03-13 04:22:45 +00:00 (Migrated from gitlab.com)

mentioned in issue #18

mentioned in issue #18
PlasticDigits commented 2026-03-13 06:59:58 +00:00 (Migrated from gitlab.com)

mentioned in commit b09808cd68252db560e2bfb1a5e1ccb079aff490

mentioned in commit b09808cd68252db560e2bfb1a5e1ccb079aff490
PlasticDigits commented 2026-03-13 07:00:05 +00:00 (Migrated from gitlab.com)

Fix pushed on branch fix/issue-8-wallet-reconnect (commit b09808c).

Root cause: The auto-reconnect code ran at module import time, before browser extension wallets (Keplr, Leap, etc.) had injected their API into window. The connection attempt failed silently and the .catch() handler deleted the localStorage entry — making reconnection permanently impossible even after the extension finished loading.

Fix (in frontend-dapp/src/hooks/useWallet.ts):

  • Deferred auto-reconnect to the window.load event, when all extension content scripts are guaranteed to have injected their APIs.
  • Added retry logic (up to 3 attempts with increasing delays: 600ms, 1200ms, 1800ms) for transient timing failures.
  • Only clear the stored connection from localStorage on permanent errors (user rejection, wallet not installed, unsupported wallet) — not on transient failures.

@Brouie — requesting your review on this one.

Fix pushed on branch `fix/issue-8-wallet-reconnect` (commit b09808c). **Root cause:** The auto-reconnect code ran at module import time, before browser extension wallets (Keplr, Leap, etc.) had injected their API into `window`. The connection attempt failed silently and the `.catch()` handler deleted the `localStorage` entry — making reconnection permanently impossible even after the extension finished loading. **Fix (in `frontend-dapp/src/hooks/useWallet.ts`):** - Deferred auto-reconnect to the `window.load` event, when all extension content scripts are guaranteed to have injected their APIs. - Added retry logic (up to 3 attempts with increasing delays: 600ms, 1200ms, 1800ms) for transient timing failures. - Only clear the stored connection from `localStorage` on permanent errors (user rejection, wallet not installed, unsupported wallet) — not on transient failures. @Brouie — requesting your review on this one.
PlasticDigits commented 2026-03-13 07:00:35 +00:00 (Migrated from gitlab.com)

mentioned in commit 2e6f54fd29

mentioned in commit 2e6f54fd29de6a46c9bf8fb26bdf18019f00279c
PlasticDigits commented 2026-03-13 07:09:09 +00:00 (Migrated from gitlab.com)

Correction: the fix has been merged directly to main (commit 2e6f54f), not on a separate branch.

Correction: the fix has been merged directly to `main` (commit 2e6f54f), not on a separate branch.
Brouie (Migrated from gitlab.com) closed this issue 2026-03-13 12:18:36 +00:00
Brouie commented 2026-03-13 12:18:39 +00:00 (Migrated from gitlab.com)

Verified fixed — Keplr wallet persists after page refresh. Auto-reconnect with retry logic working. Note: simulated dev wallet does not persist (uses different connectDev path, not saved to localStorage).

Verified fixed — Keplr wallet persists after page refresh. Auto-reconnect with retry logic working. Note: simulated dev wallet does not persist (uses different connectDev path, not saved to localStorage).
Brouie commented 2026-04-04 04:34:13 +00:00 (Migrated from gitlab.com)

mentioned in issue #49

mentioned in issue #49
Brouie commented 2026-04-06 03:36:42 +00:00 (Migrated from gitlab.com)

mentioned in issue #50

mentioned in issue #50
PlasticDigits commented 2026-05-27 05:12:49 +00:00 (Migrated from gitlab.com)

mentioned in issue #155

mentioned in issue #155
PlasticDigits commented 2026-06-13 03:05:42 +00:00 (Migrated from gitlab.com)

mentioned in merge request !894

mentioned in merge request !894
PlasticDigits commented 2026-08-08 11:17:16 +00:00 (Migrated from gitlab.com)

mentioned in issue #502

mentioned in issue #502
PlasticDigits commented 2026-08-08 11:26:47 +00:00 (Migrated from gitlab.com)

mentioned in issue #507

mentioned in issue #507
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic#8
No description provided.