Skip to content

feat(wallet): subscribe to Freighter network changes, poll 5s fallback, disable Execute on wrong network (#42)#261

Merged
ezedike-evan merged 3 commits into
ezedike-evan:mainfrom
collinsezedike:feat/42-network-change-sync
Jun 1, 2026
Merged

feat(wallet): subscribe to Freighter network changes, poll 5s fallback, disable Execute on wrong network (#42)#261
ezedike-evan merged 3 commits into
ezedike-evan:mainfrom
collinsezedike:feat/42-network-change-sync

Conversation

@collinsezedike
Copy link
Copy Markdown
Contributor

Summary

  • useFreighter: replaced 300ms polling with WatchWalletChanges subscription (5s interval); falls back to 5s setInterval polling if the API is unavailable
  • WalletContext: same subscription pattern via lazy dynamic import (avoids SSR failures from a static top-level import); single cleanup covers both paths
  • WalletButton: consumes useWallet from context so the wrong-network badge re-renders reactively on network switch
  • RateTable: accepts executeDisabled prop; Execute button is disabled whenever the app network is not PUBLIC

Test plan

  • Switch Freighter to Testnet — WalletButton shows "Wrong network / Mainnet required" within 5s
  • Execute buttons in the rate table become disabled on wrong network
  • Switch back to Mainnet — WalletButton returns to connected state and Execute re-enables
  • With Freighter not installed, confirm no SSR crash and the "Install Freighter" link renders

Closes #42

@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

Comment thread hooks/useFreighter.ts Fixed
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.

Code quality is solid — the lazy dynamic import of `WatchWalletChanges` correctly eliminates the SSR crash, the 5s polling fallback is clean with proper cleanup, and `executeDisabled={network !== 'PUBLIC'}` in the rate table is the right place for that guard. The test mock upgrade in `useFreighter.spec.tsx` is a real improvement over the stub.

One thing to fix before this can land: this branch has a merge conflict with `main`. Please rebase on `main` and resolve any conflicts, then push — I'll merge immediately after.

```bash
git fetch origin
git rebase origin/main

resolve any conflicts, then:

git push --force-with-lease
```

Note: PR #262 (mid-session install detection) is stacked on top of this branch. Rebase this one first, then rebase #262 on top of the updated branch.

@ezedike-evan
Copy link
Copy Markdown
Owner

Approved and ready to land. Sole remaining blocker is the merge conflict — please rebase and push:

```bash
git fetch origin
git rebase origin/main

resolve any conflicts, then:

git push --force-with-lease
```

Once this is merged, ping here so I can trigger the rebase on #262 (which is stacked on top of this branch).

@collinsezedike collinsezedike force-pushed the feat/42-network-change-sync branch from 7a8dcb3 to 5089960 Compare June 1, 2026 17:06
import { renderHook, waitFor } from '@testing-library/react';
import { useFreighter } from '@/hooks/useFreighter';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, renderHook, waitFor } from '@testing-library/react'
@ezedike-evan ezedike-evan merged commit fc8eca6 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.

[#042] network-change sync into app state

3 participants