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

[common, core] Update: allow instantiation with only chain id #1589

Merged
merged 21 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d0f4277
allow instantiation with only chainid
leightkt Mar 13, 2023
5bb32e8
update docs
leightkt Mar 14, 2023
6d3cd23
Merge branch 'develop' into allow-instantiation-with-only-chainid
leightkt Mar 14, 2023
49d4f60
update common and core package references
leightkt Mar 14, 2023
cbc69de
update all packages that use core and common
leightkt Mar 14, 2023
dc8e823
update related package versions, add rpcUrl label and token to setChain
leightkt Mar 15, 2023
8e308f0
update keepkey
leightkt Mar 15, 2023
cdc6618
Merge branch 'develop' into allow-instantiation-with-only-chainid
leightkt Mar 15, 2023
a760fd4
Merge branch 'develop' into allow-instantiation-with-only-chainid
leightkt Mar 15, 2023
3cd269c
update vue package with correct versioning
leightkt Mar 15, 2023
80ea016
Merge branch 'allow-instantiation-with-only-chainid' of github.com:bl…
leightkt Mar 15, 2023
102e4ee
update chain in state when new values passed to setChain
leightkt Mar 16, 2023
8f09d3a
add chain validation to update chain
leightkt Mar 16, 2023
ec18242
Update packages/core/src/chain.ts
leightkt Mar 17, 2023
fa6b744
add conditional check for rpcUrl, label, and token
leightkt Mar 17, 2023
ca5cc3c
correct package versions
leightkt Mar 20, 2023
dc0d18c
Merge branch 'develop' into allow-instantiation-with-only-chainid
leightkt Mar 20, 2023
a67d86c
versioning update, prettier cleanup
leightkt Mar 20, 2023
fe1f369
add type notes for improved devEx
leightkt Mar 20, 2023
e66b6c0
keep react package readme in line with docs
leightkt Mar 20, 2023
8e0d903
add other type comments
leightkt Mar 20, 2023
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
48 changes: 24 additions & 24 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@
"type": "module",
"dependencies": {
"bnc-sdk": "^4.6.6",
"@web3-onboard/coinbase": "^2.1.4",
"@web3-onboard/core": "^2.15.5",
"@web3-onboard/dcent": "^2.2.3",
"@web3-onboard/enkrypt": "^2.0.0",
"@web3-onboard/fortmatic": "^2.0.14",
"@web3-onboard/gas": "^2.1.4",
"@web3-onboard/gnosis": "^2.1.6",
"@web3-onboard/infinity-wallet": "^2.0.0",
"@web3-onboard/injected-wallets": "^2.8.1",
"@web3-onboard/keepkey": "^2.3.3",
"@web3-onboard/keystone": "^2.3.3",
"@web3-onboard/ledger": "^2.4.2",
"@web3-onboard/magic": "^2.1.3",
"@web3-onboard/coinbase": "^2.2.1-alpha.1",
"@web3-onboard/core": "^2.15.6-alpha.1",
"@web3-onboard/dcent": "^2.2.4-alpha.1",
"@web3-onboard/enkrypt": "^2.0.1-alpha.1",
"@web3-onboard/fortmatic": "^2.0.16-alpha.1",
"@web3-onboard/gas": "^2.1.5-alpha.1",
"@web3-onboard/gnosis": "^2.1.7-alpha.1",
"@web3-onboard/infinity-wallet": "^2.0.1-alpha.1",
"@web3-onboard/injected-wallets": "^2.8.3-alpha.1",
"@web3-onboard/keepkey": "^2.3.4-alpha.1",
"@web3-onboard/keystone": "^2.3.4-alpha.1",
"@web3-onboard/ledger": "^2.4.3-alpha.1",
"@web3-onboard/magic": "^2.1.4-alpha.1",
"@web3-onboard/mew-wallet": "^2.0.0",
"@web3-onboard/portis": "^2.1.3",
"@web3-onboard/sequence": "^2.0.4",
"@web3-onboard/taho": "^2.0.0",
"@web3-onboard/torus": "^2.2.0",
"@web3-onboard/transaction-preview": "^2.0.4",
"@web3-onboard/trezor": "^2.3.3",
"@web3-onboard/trust": "^2.0.0",
"@web3-onboard/uauth": "^2.0.1",
"@web3-onboard/walletconnect": "^2.3.2",
"@web3-onboard/web3auth": "^2.1.4",
"@web3-onboard/xdefi": "^2.0.0",
"@web3-onboard/portis": "^2.1.4-alpha.1",
"@web3-onboard/sequence": "^2.0.5-alpha.1",
"@web3-onboard/taho": "^2.0.1-alpha.1",
"@web3-onboard/torus": "^2.2.2-alpha.1",
"@web3-onboard/transaction-preview": "^2.0.5-alpha.1",
"@web3-onboard/trezor": "^2.3.4-alpha.1",
"@web3-onboard/trust": "^2.0.1-alpha.1",
"@web3-onboard/uauth": "^2.0.2-alpha.1",
"@web3-onboard/walletconnect": "^2.3.3-alpha.1",
"@web3-onboard/web3auth": "^2.1.5-alpha.1",
"@web3-onboard/xdefi": "^2.0.1-alpha.1",
"animejs": "^3.2.1",
"ethers": "^5.7.0"
}
Expand Down
15 changes: 10 additions & 5 deletions docs/src/routes/docs/[...3]modules/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ An array of Chains that your app supports:
```ts
type Chain = {
id: ChainId // hex encoded string, eg '0x1' for Ethereum Mainnet
namespace?: 'evm' // string indicating chain namespace. Defaults to 'evm' but will allow other chain namespaces in the future
rpcUrl: string // used for network requests
label: string // used for display, eg Ethereum Mainnet
token: TokenSymbol // the native token symbol, eg ETH, BNB, MATIC
namespace?: 'evm' // string indicating chain namespace. Defaults to 'evm' but will allow other chain namespaces in the future
// PLEASE NOTE: Some wallets require an rpcUrl, label, and token for actions such as adding a new chain.
// It is recommended to include rpcUrl, label, and token for full functionality.
rpcUrl?: string // Recommended to include. Used for network requests.
leightkt marked this conversation as resolved.
Show resolved Hide resolved
label?: string // Recommended to include. Used for display, eg Ethereum Mainnet.
token?: TokenSymbol // Recommended to include. The native token symbol, eg ETH, BNB, MATIC.
color?: string // the color used to represent the chain and will be used as a background for the icon
icon?: string // the icon to represent the chain
publicRpcUrl?: string // an optional public RPC used when adding a new chain config to the wallet
Expand Down Expand Up @@ -967,12 +969,15 @@ type SetChainOptions = {
chainId: string // hex encoded string
chainNamespace?: 'evm' // defaults to 'evm' (currently the only valid value, but will add more in future updates)
wallet?: string // the wallet.label of the wallet to set chain
rpcUrl?: string // if chain was instantiated without rpcUrl, include here. Used for network requests
token?: string // if chain was instantiated without token, include here. Used for display, eg Ethereum Mainnet
label?: string // if chain was instantiated without label, include here. The native token symbol, eg ETH, BNB, MATIC
}

const success = await onboard.setChain({ chainId: '0x89' })
```

The `setChain` methods takes an options object with a `chainId` property hex encoded string for the chain id to switch to. The chain id must be one of the chains that Onboard was initialized with. If the wallet supports programatically adding and switching the chain, then the user will be prompted to do so, if not, then a modal will be displayed indicating to the user that they need to switch chains to continue. The `setChain` method returns a promise that resolves when either the user has confirmed the chain switch, or has dismissed the modal and resolves with a boolean indicating if the switch network was successful or not. The `setChain` method will by default switch the first wallet (the most recently connected) in the `wallets` array. A specific wallet can be targeted by passing in the `wallet.label` in the options object as the `wallet` parameter.
The `setChain` methods takes an options object with a `chainId` property hex encoded string for the chain id to switch to. The chain id must be one of the chains that Onboard was initialized with. If the wallet supports programatically adding and switching the chain, then the user will be prompted to do so, if not, then a modal will be displayed indicating to the user that they need to switch chains to continue. The `setChain` method returns a promise that resolves when either the user has confirmed the chain switch, or has dismissed the modal and resolves with a boolean indicating if the switch network was successful or not. The `setChain` method will by default switch the first wallet (the most recently connected) in the `wallets` array. A specific wallet can be targeted by passing in the `wallet.label` in the options object as the `wallet` parameter. If a chain was instantiated without an rpcUrl, token, or label, add these options for wallets that require this information for adding a new chain.

## Custom Styling

Expand Down
5 changes: 4 additions & 1 deletion docs/src/routes/docs/[...3]modules/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ type UseSetChain = (
type SetChainOptions = {
chainId: string
chainNamespace?: string
wallet?: WalletState['label']
wallet?: WalletState['label'],
leightkt marked this conversation as resolved.
Show resolved Hide resolved
rpcUrl?: string,
label?: string,
token?: string,
}

const [
Expand Down
2 changes: 1 addition & 1 deletion examples/with-ledger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@web3-onboard/ledger": "^2.1.6",
"@web3-onboard/ledger": "^2.4.3-alpha.1",
"@web3-onboard/react": "^2.4.1",
"next": "12.2.4",
"react": "18.2.0",
Expand Down
30 changes: 15 additions & 15 deletions examples/with-nextjs-13/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
"@types/node": "18.11.11",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.9",
"@web3-onboard/coinbase": "^2.1.3",
"@web3-onboard/dcent": "^2.2.1",
"@web3-onboard/fortmatic": "^2.0.14",
"@web3-onboard/gnosis": "^2.1.3",
"@web3-onboard/injected-wallets": "^2.6.2",
"@web3-onboard/keepkey": "^2.3.1",
"@web3-onboard/keystone": "^2.3.1",
"@web3-onboard/ledger": "^2.3.1",
"@web3-onboard/magic": "^2.1.3",
"@web3-onboard/coinbase": "^2.2.1-alpha.1",
"@web3-onboard/dcent": "^2.2.4-alpha.1",
"@web3-onboard/fortmatic": "^2.0.16-alpha.1",
"@web3-onboard/gnosis": "^2.1.7-alpha.1",
"@web3-onboard/injected-wallets": "^2.8.3-alpha.1",
"@web3-onboard/keepkey": "^2.3.4-alpha.1",
"@web3-onboard/keystone": "^2.3.4-alpha.1",
"@web3-onboard/ledger": "^2.4.3-alpha.1",
"@web3-onboard/magic": "^2.1.4-alpha.1",
"@web3-onboard/mew-wallet": "^2.0.0",
"@web3-onboard/portis": "^2.1.3",
"@web3-onboard/portis": "^2.1.4-alpha.1",
"@web3-onboard/react": "^2.6.1",
"@web3-onboard/sequence": "^2.0.3",
"@web3-onboard/taho": "^2.0.0",
"@web3-onboard/torus": "^2.1.3",
"@web3-onboard/trezor": "^2.3.1",
"@web3-onboard/walletconnect": "^2.1.3",
"@web3-onboard/sequence": "^2.0.5-alpha.1",
"@web3-onboard/taho": "^2.0.1-alpha.1",
"@web3-onboard/torus": "^2.2.2-alpha.1",
"@web3-onboard/trezor": "^2.3.4-alpha.1",
"@web3-onboard/walletconnect": "^2.3.3-alpha.1",
"ethers": "^5.7.2",
"next": "13.1.6",
"react": "18.2.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/with-sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"type": "module",
"dependencies": {
"@fontsource/fira-mono": "^4.5.10",
"@web3-onboard/core": "^2.15.4",
"@web3-onboard/injected-wallets": "^2.8.1",
"@web3-onboard/walletconnect": "^2.3.1",
"@web3-onboard/core": "^2.15.6-alpha.1",
"@web3-onboard/injected-wallets": "^2.8.3-alpha.1",
"@web3-onboard/walletconnect": "^2.3.3-alpha.1",
"buffer": "^6.0.3"
}
}
30 changes: 15 additions & 15 deletions examples/with-vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
"preview": "vite preview"
},
"dependencies": {
"@web3-onboard/coinbase": "^2.1.3",
"@web3-onboard/dcent": "^2.2.1",
"@web3-onboard/fortmatic": "^2.0.14",
"@web3-onboard/gnosis": "^2.1.5",
"@web3-onboard/injected-wallets": "^2.6.2",
"@web3-onboard/keepkey": "^2.3.1",
"@web3-onboard/keystone": "^2.3.1",
"@web3-onboard/ledger": "^2.3.1",
"@web3-onboard/magic": "^2.1.3",
"@web3-onboard/coinbase": "^2.2.1-alpha.1",
"@web3-onboard/dcent": "^2.2.4-alpha.1",
"@web3-onboard/fortmatic": "^2.0.16-alpha.1",
"@web3-onboard/gnosis": "^2.1.7-alpha.1",
"@web3-onboard/injected-wallets": "^2.8.3-alpha.1",
"@web3-onboard/keepkey": "^2.3.4-alpha.1",
"@web3-onboard/keystone": "^2.3.4-alpha.1",
"@web3-onboard/ledger": "^2.4.3-alpha.1",
"@web3-onboard/magic": "^2.1.4-alpha.1",
"@web3-onboard/mew": "^2.1.3",
"@web3-onboard/portis": "^2.1.3",
"@web3-onboard/react": "^2.4.1",
"@web3-onboard/sequence": "^2.0.3",
"@web3-onboard/portis": "^2.1.4-alpha.1",
"@web3-onboard/react": "^2.6.7-alpha.1",
"@web3-onboard/sequence": "^2.0.5-alpha.1",
"@web3-onboard/tallyho": "^2.0.1",
"@web3-onboard/torus": "^2.1.3",
"@web3-onboard/trezor": "^2.3.1",
"@web3-onboard/walletconnect": "^2.2.0",
"@web3-onboard/torus": "^2.2.2-alpha.1",
"@web3-onboard/trezor": "^2.3.4-alpha.1",
"@web3-onboard/walletconnect": "^2.3.3-alpha.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/with-vuejs-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"serve": "vite preview"
},
"dependencies": {
"@web3-onboard/injected-wallets": "^2.6.2",
"@web3-onboard/injected-wallets": "^2.8.3-alpha.1",
"@web3-onboard/vue": "^2.5.1",
"vue": "^2.7.14",
"vue-template-compiler": "2.7.14"
Expand Down
2 changes: 1 addition & 1 deletion examples/with-vuejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
},
"dependencies": {
"@web3-onboard/injected-wallets": "^2.6.2",
"@web3-onboard/injected-wallets": "^2.8.3-alpha.1",
"@web3-onboard/vue": "^2.5.1",
"pinia": "^2.0.29",
"vue": "^3.2.45",
Expand Down
4 changes: 2 additions & 2 deletions packages/coinbase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/coinbase",
"version": "2.2.0",
"version": "2.2.1-alpha.1",
"description": "Coinbase SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
"keywords": [
"Ethereum",
Expand Down Expand Up @@ -59,6 +59,6 @@
},
"dependencies": {
"@coinbase/wallet-sdk": "^3.6.0",
"@web3-onboard/common": "^2.2.3"
"@web3-onboard/common": "^2.2.4-alpha.1"
}
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/common",
"version": "2.2.3",
"version": "2.2.4-alpha.1",
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
"keywords": [
"Ethereum",
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ export enum ProviderRpcErrorCode {
export interface Chain {
namespace?: 'evm'
id: ChainId
rpcUrl: string
label: string
token: TokenSymbol // eg ETH, BNB, MATIC
rpcUrl?: string
leightkt marked this conversation as resolved.
Show resolved Hide resolved
label?: string
token?: TokenSymbol // eg ETH, BNB, MATIC
color?: string
icon?: string // svg string
providerConnectionInfo?: ConnectionInfo
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const providerConnectionInfoValidation = Joi.object({
export const chainValidation = Joi.object({
namespace: chainNamespaceValidation,
id: chainIdValidation.required(),
rpcUrl: Joi.string().required(),
label: Joi.string().required(),
token: Joi.string().required(),
rpcUrl: Joi.string(),
label: Joi.string(),
token: Joi.string(),
icon: Joi.string(),
color: Joi.string(),
publicRpcUrl: Joi.string(),
Expand Down
13 changes: 9 additions & 4 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ An array of Chains that your app supports:
type Chain = {
id: ChainId // hex encoded string, eg '0x1' for Ethereum Mainnet
namespace?: 'evm' // string indicating chain namespace. Defaults to 'evm' but will allow other chain namespaces in the future
rpcUrl: string // used for network requests (eg Alchemy or Infura end point)
label: string // used for display, eg Ethereum Mainnet
token: TokenSymbol // the native token symbol, eg ETH, BNB, MATIC
// PLEASE NOTE: Some wallets require an rpcUrl, label, and token for actions such as adding a new chain.
// It is recommended to include rpcUrl, label, and token for full functionality.
rpcUrl?: string // Recommended to include. Used for network requests (eg Alchemy or Infura end point).
leightkt marked this conversation as resolved.
Show resolved Hide resolved
label?: string // Recommended to include. Used for display, eg Ethereum Mainnet.
token?: TokenSymbol // Recommended to include. The native token symbol, eg ETH, BNB, MATIC.
color?: string // the color used to represent the chain and will be used as a background for the icon
icon?: string // the icon to represent the chain
publicRpcUrl?: string // an optional public RPC used when adding a new chain config to the wallet
Expand Down Expand Up @@ -908,12 +910,15 @@ type SetChainOptions = {
chainId: string // hex encoded string
chainNamespace?: 'evm' // defaults to 'evm' (currently the only valid value, but will add more in future updates)
wallet?: string // the wallet.label of the wallet to set chain
rpcUrl?: string // if chain was instantiated without rpcUrl, include here. Used for network requests
token?: string // if chain was instantiated without token, include here. Used for display, eg Ethereum Mainnet
label?: string // if chain was instantiated without label, include here. The native token symbol, eg ETH, BNB, MATIC
}

const success = await onboard.setChain({ chainId: '0x89' })
```

The `setChain` methods takes an options object with a `chainId` property hex encoded string for the chain id to switch to. The chain id must be one of the chains that Onboard was initialized with. If the wallet supports programatically adding and switching the chain, then the user will be prompted to do so, if not, then a modal will be displayed indicating to the user that they need to switch chains to continue. The `setChain` method returns a promise that resolves when either the user has confirmed the chain switch, or has dismissed the modal and resolves with a boolean indicating if the switch network was successful or not. The `setChain` method will by default switch the first wallet (the most recently connected) in the `wallets` array. A specific wallet can be targeted by passing in the `wallet.label` in the options object as the `wallet` parameter.
The `setChain` methods takes an options object with a `chainId` property hex encoded string for the chain id to switch to. The chain id must be one of the chains that Onboard was initialized with. If the wallet supports programatically adding and switching the chain, then the user will be prompted to do so, if not, then a modal will be displayed indicating to the user that they need to switch chains to continue. The `setChain` method returns a promise that resolves when either the user has confirmed the chain switch, or has dismissed the modal and resolves with a boolean indicating if the switch network was successful or not. The `setChain` method will by default switch the first wallet (the most recently connected) in the `wallets` array. A specific wallet can be targeted by passing in the `wallet.label` in the options object as the `wallet` parameter. If a chain was instantiated without an rpcUrl, token, or label, add these options for wallets that require this information for adding a new chain.

## Custom Styling

Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/core",
"version": "2.15.5",
"version": "2.15.6-alpha.1",
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
"keywords": [
"Ethereum",
Expand Down Expand Up @@ -69,8 +69,8 @@
"@types/lodash.partition": "^4.6.6",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"@web3-onboard/gas": "^2.0.0",
"@web3-onboard/transaction-preview": "^2.0.4",
"@web3-onboard/gas": "^2.1.5-alpha.1",
"@web3-onboard/transaction-preview": "^2.0.5-alpha.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^3.2.1",
Expand All @@ -85,7 +85,7 @@
},
"dependencies": {
"@unstoppabledomains/resolution": "^8.0",
"@web3-onboard/common": "^2.2.3",
"@web3-onboard/common": "^2.2.4-alpha.1",
"bignumber.js": "^9.0.0",
"bnc-sdk": "^4.6.7",
"bowser": "^2.11.0",
Expand Down
23 changes: 16 additions & 7 deletions packages/core/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import type { WalletState } from './types.js'
import { toHexString } from './utils.js'

async function setChain(options: {
chainId: string | number
chainNamespace?: string
wallet?: WalletState['label']
chainId: string | number,
chainNamespace?: string,
wallet?: WalletState['label'],
rpcUrl?: string,
label?: string,
token?: string
}): Promise<boolean> {
const error = validateSetChainOptions(options)

Expand All @@ -20,7 +23,7 @@ async function setChain(options: {
}

const { wallets, chains } = state.get()
const { chainId, chainNamespace = 'evm', wallet: walletToSet } = options
const { chainId, chainNamespace = 'evm', wallet: walletToSet, rpcUrl, label, token } = options
leightkt marked this conversation as resolved.
Show resolved Hide resolved
const chainIdHex = toHexString(chainId)

// validate that chainId has been added to chains
Expand Down Expand Up @@ -75,7 +78,10 @@ async function setChain(options: {
wallet,
chain,
switchChainModalClosed$,
chainIdHex
chainIdHex,
leightkt marked this conversation as resolved.
Show resolved Hide resolved
rpcUrl,
label,
token,
)
}

Expand All @@ -93,10 +99,13 @@ const chainNotInWallet = async (
wallet: WalletState,
chain: Chain,
switchChainModalClosed$: Observable<boolean>,
chainIdHex: string
chainIdHex: string,
rpcUrl?: string,
label?: string,
token?: string,
): Promise<boolean> => {
try {
await addNewChain(wallet.provider, chain)
await addNewChain(wallet.provider, chain, rpcUrl, label, token)
await switchChain(wallet.provider, chainIdHex)
return true
} catch (error) {
Expand Down
Loading