Page-side asset-metadata & bech32 reach the testnet default under a non-testnet (devnet) config
- Langage dominant
- TypeScript
- Étoiles
- 1
- Forks
- 21
- Merge moyen
- 12 h 14 min
- PR mergées (30 j)
- 41
Description
## Summary
During a devnet-configured run, page-side code issued **testnet** RPC calls and could tag addresses for testnet, while the service-worker sync and persisted storage correctly stayed on **devnet**. Once a consumer specifies a network (e.g. devnet), it should be that network everywhere on the page side too.
## Root cause
`MidenProvider` resolves the endpoint synchronously (`resolveRpcUrl`) but only writes it to the Zustand store (`config.rpcUrl`) inside its **async** init flow (`setConfig` runs during init; `isReady` flips at the end). Page-side consumers that read `config.rpcUrl` from the store therefore see `undefined` during the init window and fall back to a hardcoded testnet default:
- **`useAssetMetadata`** builds its own page-side `RpcClient`. When `config.rpcUrl` is unset it used `Endpoint.testnet()` and fired `getAccountDetails` against `rpc.testnet.miden.io`, independently of the configured WebClient/worker.
- **`utils/accountBech32.ts`** (`inferNetworkId`) defaulted to `NetworkId.testnet()` whenever the endpoint was unset or unrecognized (including `localhost` and custom URLs), tagging addresses with the `mtst` prefix.
## Impact
On a devnet run, page-side native-asset metadata calls hit testnet RPC, and bech32 addresses could render with the testnet (`mtst`) prefix — even though the client/worker used devnet.
## Expected
Once the consumer specifies devnet, all page-side code uses devnet. A testnet **default** is acceptable only at the top level (MidenProvider / WebClient) when nothing is configured.
## Fix
- Gate `useAssetMetadata`'s `RpcClient` construction on `isReady` (the same pattern the default prover uses), so it uses the resolved endpoint once initialization completes.
- Make `accountBech32` derive the network from the resolved endpoint, treat local nodes as devnet, and return the raw account id rather than a wrong-network bech32 string when the network can't be confirmed.
The testnet default still applies only when no endpoint was configured at all.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Look at the MidenProvider's resolveRpcUrl and setConfig async init flow in the Zustand store. Examine useAssetMetadata's RpcClient construction and utils/accountBech32.ts's inferNetworkId function. The fix involves gating client construction on isReady and updating network inference to handle devnet and local nodes correctly. Test by running a devnet-configured instance and verifying page-side calls use the correct endpoint and address prefixes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript
- Domaine
- backend-api-design, frontend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 55/100