Skip to content

feat(wallet): poll 2s/30s then focus+visibilitychange for mid-session Freighter install detection (#41)#262

Merged
ezedike-evan merged 5 commits into
ezedike-evan:mainfrom
collinsezedike:feat/41-mid-session-install-detection
Jun 1, 2026
Merged

feat(wallet): poll 2s/30s then focus+visibilitychange for mid-session Freighter install detection (#41)#262
ezedike-evan merged 5 commits into
ezedike-evan:mainfrom
collinsezedike:feat/41-mid-session-install-detection

Conversation

@collinsezedike
Copy link
Copy Markdown
Contributor

Summary

  • Adds a 2s polling phase for the first 30s after mount so a mid-session Freighter install is surfaced within 2s
  • After 30s, clears the interval and attaches window focus + document visibilitychange listeners instead (zero-cost ongoing detection)
  • WatchWalletChanges subscription runs in parallel for account/network change tracking — the two concerns are independent
  • 7 new tests in tests/freighter-detect.spec.tsx covering early-poll detection, event-driven detection, and cleanup

Test plan

  • Open the page without Freighter installed — "Install Freighter" link shown
  • Install Freighter extension — Connect button appears within ~2s without a page reload
  • Wait 30s, then re-focus the tab after installing — Connect button still appears
  • Unmount/navigate away — confirm no console errors about state updates on unmounted component

Closes #41

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@collinsezedike is attempting to deploy a commit to the ezedikeevan's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@collinsezedike 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

@@ -0,0 +1,166 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { renderHook, waitFor, act } from '@testing-library/react'
Copy link
Copy Markdown
Owner

@ezedike-evan ezedike-evan left a comment

Choose a reason for hiding this comment

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

The implementation is exactly right: 2s early polling for the first 30s, then zero-cost event-driven detection via `focus` + `visibilitychange`, with `WatchWalletChanges` running in parallel for account/network changes. The three-timer cleanup in the return function is correct (early interval, early timeout, watcher, fallback interval, and both event listeners all removed). `onVisibilityDetect` is properly hoisted outside `init()` so `removeEventListener` matches the same reference. The 7 new tests in `freighter-detect.spec.tsx` cover every path including the "no polls after 30s without an event" invariant.

Ready to merge — but this branch is stacked on #261 and cannot land until #261 is rebased and merged first. Once #261 is merged into `main`, rebase this branch on the updated `main` and push — it will merge cleanly.

```bash

After #261 is merged:

git fetch origin
git rebase origin/main
git push --force-with-lease
```

@ezedike-evan
Copy link
Copy Markdown
Owner

Approved and ready to land — waiting on #261 to merge first since this branch is stacked on it.

Once #261 is merged into `main`, rebase this branch on the updated `main` and push:

```bash
git fetch origin
git rebase origin/main
git push --force-with-lease
```

No code changes needed — just the rebase.

@collinsezedike collinsezedike force-pushed the feat/41-mid-session-install-detection branch from d9740dd to 8034d94 Compare June 1, 2026 17:09
Comment thread tests/useFreighter.spec.tsx Fixed
@ezedike-evan ezedike-evan merged commit 589b8cf into ezedike-evan:main Jun 1, 2026
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.

[#041] mid-session install detection

3 participants