Skip to content

Commit c0cc508

Browse files
katspaughmahmud-bn
andauthored
Feature: optional public RPC and block explorer Chain params (#1021)
* Feat: add publicRpcUrl and blockExplorerUrl to the Chain type for adding a chain to wallet * Update docs * packages bump Co-authored-by: Mahmud Adeleye <[email protected]>
1 parent f32aefb commit c0cc508

File tree

7 files changed

+21
-12
lines changed

7 files changed

+21
-12
lines changed

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/common",
3-
"version": "2.1.1",
3+
"version": "2.1.2-alpha.1",
44
"scripts": {
55
"build": "rollup -c",
66
"dev": "rollup -c -w",

packages/common/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ export interface Chain {
430430
color?: string
431431
icon?: string // svg string
432432
providerConnectionInfo?: ConnectionInfo
433+
publicRpcUrl?: string
434+
blockExplorerUrl?: string
433435
}
434436

435437
export type TokenSymbol = string // eg ETH

packages/core/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type Chain = {
4949
token: TokenSymbol // the native token symbol, eg ETH, BNB, MATIC
5050
color?: string // the color used to represent the chain and will be used as a background for the icon
5151
icon?: string // the icon to represent the chain
52+
publicRpcUrl?: string // an optional public RPC used when adding a new chain config to the wallet
53+
blockExplorerUrl?: string // also used when adding a new config to the wallet
5254
}
5355
```
5456

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.2.12",
3+
"version": "2.2.13-alpha.1",
44
"scripts": {
55
"build": "rollup -c",
66
"dev": "rollup -c -w",
@@ -41,7 +41,7 @@
4141
"typescript": "^4.5.5"
4242
},
4343
"dependencies": {
44-
"@web3-onboard/common": "^2.1.1",
44+
"@web3-onboard/common": "^2.1.2",
4545
"bowser": "^2.11.0",
4646
"ethers": "5.5.3",
4747
"eventemitter3": "^4.0.7",

packages/core/src/provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ export function addNewChain(
324324
symbol: chain.token,
325325
decimals: 18
326326
},
327-
rpcUrls: [chain.rpcUrl]
327+
rpcUrls: [chain.publicRpcUrl || chain.rpcUrl],
328+
blockExplorerUrls: chain.blockExplorerUrl ? [chain.blockExplorerUrl] : undefined
328329
}
329330
]
330331
})

packages/core/src/validation.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Joi from 'joi'
2-
import type { ChainId, WalletInit, WalletModule } from '@web3-onboard/common'
1+
import Joi, { ObjectSchema, Schema } from 'joi'
2+
import type { Chain, ChainId, WalletInit, WalletModule } from '@web3-onboard/common'
33

44
import type {
55
InitOptions,
@@ -28,16 +28,19 @@ const providerConnectionInfo = Joi.object({
2828
timeout: Joi.number()
2929
})
3030

31-
const chain = Joi.object({
31+
const chainValidationParams: Record<keyof Chain, Schema | ObjectSchema> = {
3232
namespace: chainNamespace,
3333
id: chainId.required(),
3434
rpcUrl: Joi.string().required(),
3535
label: Joi.string().required(),
3636
token: Joi.string().required(),
3737
icon: Joi.string(),
3838
color: Joi.string(),
39-
providerConnectionInfo: providerConnectionInfo
40-
})
39+
publicRpcUrl: Joi.string(),
40+
blockExplorerUrl: Joi.string(),
41+
providerConnectionInfo
42+
}
43+
const chain = Joi.object(chainValidationParams)
4144

4245
const connectedChain = Joi.object({
4346
namespace: chainNamespace.required(),
@@ -207,6 +210,7 @@ export function validateString(str: string): ValidateReturn {
207210

208211
export function validateSetChainOptions(data: {
209212
chainId: ChainId
213+
chainNamespace?: string
210214
wallet?: WalletState['label']
211215
}): ValidateReturn {
212216
return validate(setChainOptions, data)

packages/react/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/react",
3-
"version": "2.1.9",
3+
"version": "2.1.10-alpha.1",
44
"description": "Collection of React Hooks for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",
@@ -23,8 +23,8 @@
2323
"typescript": "^4.5.5"
2424
},
2525
"dependencies": {
26-
"@web3-onboard/core": "^2.2.12",
27-
"@web3-onboard/common": "^2.1.1",
26+
"@web3-onboard/core": "^2.2.13-alpha.1",
27+
"@web3-onboard/common": "^2.1.2-alpha.1",
2828
"use-sync-external-store": "1.0.0"
2929
},
3030
"peerDependencies": {

0 commit comments

Comments
 (0)