Skip to content

Commit beedd4f

Browse files
1.32.0-0.1.0: Switch network if RPC request is available (#639)
1 parent 28227aa commit beedd4f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.32.0",
3+
"version": "1.32.0-0.1.0",
44
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
55
"keywords": [
66
"ethereum",

src/modules/check/network.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function network(
2222
walletCheck,
2323
exit,
2424
stateSyncStatus,
25-
stateStore
25+
stateStore,
26+
wallet
2627
} = stateAndHelpers
2728

2829
if (network === null) {
@@ -40,7 +41,14 @@ function network(
4041
})
4142
}
4243
}
43-
44+
try {
45+
await wallet?.provider?.request({
46+
method: 'wallet_switchEthereumChain',
47+
params: [{ chainId: '0x' + appNetworkId?.toString(16) }]
48+
})
49+
} catch (e) {
50+
// Could not switch networks so proceed as normal through the checks
51+
}
4452
if (stateStore.network.get() != appNetworkId) {
4553
return {
4654
heading: heading || 'You Must Change Networks',

0 commit comments

Comments
 (0)