feat: warn when the connected wallet is on a different network than the dApp - #193
Merged
Conversation
… switch The strip only reflected what was true at connect. Nothing re-read either synchronizer id, so switching networks in the wallet left it stale, which made the warning useless in the case it exists for. - useWrongNetwork re-reads on three triggers: the party changing, the page regaining focus, and every 30 seconds. Focus catches a switch as it happens, because using the wallet takes focus off the page. visibilitychange misses it, since an extension popup draws over the tab rather than hiding it. - synchronizer.ts reads /v2/state/connected-synchronizers in one request. The wallet's side no longer comes from the factory row in config.ts: that read is three round trips and its answer rebuilds the backend, so polling it would re-run every ledger read. - wrongNetwork tests membership instead of equality. A participant can be connected to several synchronizers, and reaching the app's one is what decides whether a write lands. - A failed read stays silent and leaves the last answer standing. It has to poll: CIP-0103 defines no network-change event and the SDK pushes accounts only.
The strip claimed to name a target network to switch to, and nothing can name one a reader could act on. CIP-0103 defines `networkId` for a wallet only, and the label wallet-service could supply from its NETWORK variable is typed by hand on both sides, so the two read the same for different networks as easily as differently for one. - The strip now reads "Wrong network: wallet is connected to bootnode-devnet, switch networks to proceed." It names the wallet's own label and no target, and drops the synchronizer ids, which were unreadable and told the user nothing they could act on. - networkLabel drops the CAIP-2 namespace, since every network this app sees is under canton. A label with no namespace stays whole. - wrongNetwork returns a boolean. Nothing rendered the ids any more, so the result payload went with them. - architecture.md records why there is no target label and that a wallet quiet about its network reads as canton:local.
The connected-synchronizers read put the party in the resource string. A wallet that checks the resource against the ledger API's own route list rejects that, and the hook swallows the failure, so the strip never appears. The party now travels in `query`, the way every other read passes one. Three fixes in `useWrongNetwork`: - Only the last check started may write, so a slow older read cannot overwrite a newer verdict. - The verdict carries the party it was read for, so the previous party's answer is not shown against the new one's network. - The app's synchronizer id is read once and kept. wallet-service answers for one network, so every later check is a single participant read rather than another `amulet.tap` every 30 seconds. On the wrong network `config.ts` finds no operator and throws its `run pnpm run bootstrap` advice, which filled the page with a symptom. The card now names the network, and the advice stays for a ledger that really has no deployment. Adds `synchronizer.test.ts`: the happy path, the request shape, the empty cases.
Split `fetchAppNetwork` out of `fetchTransferContext`. That builder needs an AmuletRules and an open mining round both, and the SV opens the first round minutes after a LocalNet start, so the check could not answer until then. The network id sits on the AmuletRules disclosure alone. Also: - Box the cached app network, so an answer carrying no id counts as read. Before, the ref held the bare id, so every later check re-ran the tap. - Read the wallet's synchronizers through `call` in config.ts instead of a second inline cast. - Simplify `networkLabel` to one expression and drop a redundant test row. - Move the rule about passing a filter in `query` into dapp/frontend/CLAUDE.md, where the next author looks for it. - Trim comments that restated the code or copied architecture.md.
# Conflicts: # dapp/frontend/architecture.md
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #146
Connecting a wallet pointed at another Canton network left every write failing with nothing on screen to explain it. The app now reads both networks, compares them, and says so.
Changes
Deviations
Acceptance criteria
Test plan
Automated tests
pnpm installpnpm -C dapp/frontend testManual verification
pnpm app:devBreaking changes
None.
Checklist
Screenshots