MetaMask / MetaMask/test-dapp-tron

WalletConnect adapter is pinned to the page-load network, breaking signing after switching to Mainnet

Open Beginner friendly
#67 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1
Forks
1
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug

When the page is loaded with a testnet selected and the user then switches to Mainnet and connects via WalletConnect, every `signMessage` / `signTransaction` call fails in the dapp with:

```
WalletSignMessageError: Missing or invalid. request() chainId: tron:0x94a9059e
```

No request ever reaches the wallet (the WC SignClient's `isValidRequest()` rejects it client-side), so no confirmation appears in the wallet.

## Root cause

`App.tsx` constructs the `WalletConnectAdapter` from a ref captured at mount:

```tsx
const initialNetwork = useRef(selectedNetwork);
// ...
new WalletConnectAdapter({
network: getWCNetworkName[initialNetwork.current],
// ...
})
```

The comment above the ref says switching between mainnet and a testnet remounts `WalletProvider` via the `key` prop, but the `key` only remounts `WalletProvider` and its children. The `App` component that owns `initialNetwork` is not remounted, so the ref keeps its page-load value.

Result: load on Shasta, switch to Mainnet, connect via WC. The session is approved for `tron:0x2b6653dc` (mainnet, the only scope MetaMask Mobile permits), but the adapter was constructed with the Shasta chain ID (`tron:0x94a9059e`). Every request is validated against the session namespaces in the dapp and rejected before sending.

## Steps to reproduce

1. Load the dapp with Shasta Testnet selected (the WalletConnect option is hidden, as expected).
2. Switch the Network dropdown to Mainnet.
3. Connect via WalletConnect (MetaMask Mobile) and approve the session.
4. Click Sign Message.

Expected: confirmation appears in the wallet.
Actual: `Missing or invalid. request() chainId: tron:0x94a9059e` in the console; the wallet never receives the request.

## Workaround

Hard-reload the page while Mainnet is selected (the selection persists in localStorage), then reconnect. The ref then captures mainnet and signing works.

## Suggested fix

Derive the adapter's `network` from the current `selectedNetwork` instead of the mount-time ref, or move the ref (or the adapter construction) inside the subtree that is remounted by the `key` prop so it is recreated when the network category changes.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in App.tsx by reading the selectedNetwork handling, initialNetwork ref, WalletProvider key, and WalletConnectAdapter construction. Reproduce the Shasta-to-Mainnet flow, then verify that WalletConnect signing reaches the wallet without the stale testnet chain ID error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
blockchain, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.