Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add await on switchNetwork #3895

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/good-dots-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@reown/appkit-adapter-bitcoin': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-utils': patch
'@reown/appkit': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-cdn': patch
'@reown/appkit-cli': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
'@reown/appkit-wallet-button': patch
---

Add await in switchNetwork
4 changes: 2 additions & 2 deletions packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class AppKit {
return ChainController.state.activeCaipNetwork?.id
}

public switchNetwork(appKitNetwork: AppKitNetwork) {
public async switchNetwork(appKitNetwork: AppKitNetwork) {
const network = this.caipNetworks?.find(n => n.id === appKitNetwork.id)

if (!network) {
Expand All @@ -249,7 +249,7 @@ export class AppKit {
return
}

ChainController.switchActiveNetwork(network)
await ChainController.switchActiveNetwork(network)
}

public getWalletProvider() {
Expand Down
4 changes: 2 additions & 2 deletions packages/appkit/tests/client/public-methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ describe('Base Public methods', () => {
vi.mocked(ChainController.switchActiveNetwork).mockResolvedValueOnce(undefined)

const appKit = new AppKit(mockOptions)
appKit.switchNetwork(mainnet)
await appKit.switchNetwork(mainnet)

expect(switchActiveNetwork).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -708,7 +708,7 @@ describe('Base Public methods', () => {
})
)

appKit.switchNetwork(polygon)
await appKit.switchNetwork(polygon)

expect(switchActiveNetwork).toHaveBeenCalledTimes(1)
})
Expand Down
Loading