Skip to content

Commit 4ef28cc

Browse files
authored
fix: eagerly emit chainChanged events when receiving a successful response from switchChain calls rather than wait for chainChanged event (#62)
* eagerly emit chainChanged events when receiving a successful response from switchChain calls rather than wait for chainChanged event * add changelog entry * changelog formatting issue
1 parent 3931d4d commit 4ef28cc

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

packages/connect-evm/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
- Eagerly call `onChainChanged` when `switchChain` is called (rather than waiting for the `chainChanged` event), this ensures that the provider's selected chain ID is updated even if the `chainChanged` event is not received ([#62](https://github.com/MetaMask/connect-monorepo/pull/62))
13+
1214
- Fixed incorrect caching of error responses for some requests/events ([#59](https://github.com/MetaMask/connect-monorepo/pull/59))
1315

1416
## [0.1.0]

packages/connect-evm/src/connect.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ export class MetamaskConnectEVM {
459459
params,
460460
});
461461
await this.#trackWalletActionSucceeded(method, scope, params);
462+
if((result as unknown as { result: unknown }).result === null) {
463+
// result is successful we eagerly call onChainChanged to update the provider's selected chain ID.
464+
this.#onChainChanged(hexChainId);
465+
}
462466
return result;
463467
} catch (error) {
464468
await this.#trackWalletActionFailed(method, scope, params, error);

0 commit comments

Comments
 (0)