Skip to content

Commit c5d81ad

Browse files
authored
[common-v2.1.5-alpha.1, core-v2.4.0-alpha.7, react-v2.2.3-alpha.5, vue-v2.1.3-alpha.5, demo-v2.0.6]: Enhancement - chain number support (#1135)
* chain-number * chain-number * chain-number * chain-number * package-bump * merge develop * merge develop * remove space * remove yarn.lock * remove common-yarn.lock * package bump * package bump * package versioning * package versioning * package versioning * package versioning
1 parent 7fb6c25 commit c5d81ad

File tree

29 files changed

+212
-53
lines changed

29 files changed

+212
-53
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.6",
3+
"version": "2.1.7-alpha.1",
44
"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.",
55
"keywords": [
66
"Ethereum",

packages/common/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export type GetInterfaceHelpers = {
236236
EventEmitter: typeof EventEmitter
237237
}
238238

239-
export type ChainId = string
239+
export type ChainId = string | number
240240

241241
export type RpcUrl = string
242242

packages/common/src/validation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const basePaths = Joi.array().items(basePath)
99

1010
const chain = Joi.object({
1111
namespace: Joi.string(),
12-
id: Joi.string().required(),
12+
id: Joi.alternatives()
13+
.try(Joi.string().pattern(/^0x[0-9a-fA-F]+$/),
14+
Joi.number().positive()).required,
1315
rpcUrl: Joi.string().required(),
1416
label: Joi.string().required(),
1517
token: Joi.string().required(),

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.5.0",
3+
"version": "2.6.0-alpha.1",
44
"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.",
55
"keywords": [
66
"Ethereum",
@@ -81,7 +81,7 @@
8181
"typescript": "^4.5.5"
8282
},
8383
"dependencies": {
84-
"@web3-onboard/common": "^2.1.6",
84+
"@web3-onboard/common": "^2.1.7-alpha.1",
8585
"bignumber.js": "^9.0.0",
8686
"bnc-sdk": "^4.4.1",
8787
"bowser": "^2.11.0",

packages/core/src/chain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { validateSetChainOptions } from './validation'
88
import type { WalletState } from './types'
99

1010
async function setChain(options: {
11-
chainId: string
11+
chainId: string | number
1212
chainNamespace?: string
1313
wallet?: WalletState['label']
1414
}): Promise<boolean> {

packages/core/src/connect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ async function connect(
2525
if (!chains.length)
2626
throw new Error(
2727
'At least one chain must be set before attempting to connect a wallet'
28-
)
29-
28+
)
29+
3030
const { autoSelect } = options || {
3131
autoSelect: { label: '', disableModals: false }
3232
}

packages/core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from './store/actions'
2727

2828
import updateBalances from './update-balances'
29+
import { chainIdToHex } from './utils'
2930
import { preflightNotifications } from './preflight-notifications'
3031

3132
const API = {
@@ -89,8 +90,7 @@ function init(options: InitOptions): OnboardAPI {
8990
} = options
9091

9192
initI18N(i18n)
92-
addChains(chains)
93-
93+
addChains(chains.map(chainIdToHex))
9494
const { device, svelteInstance } = configuration
9595

9696
// update accountCenter

packages/core/src/store/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function addChains(chains: Chain[]): void {
6363
payload: chains.map(({ namespace = 'evm', id, ...rest }) => ({
6464
...rest,
6565
namespace,
66-
id: id.toLowerCase()
66+
id: id
6767
}))
6868
}
6969

packages/core/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export async function copyWalletAddress(text: string): Promise<void> {
9292
}
9393
}
9494

95+
export const chainIdToHex = (chain: Chain): Chain => typeof chain.id === 'number' ? { ...chain, id: `0x${chain.id.toString(16)}` } : chain
96+
9597
export const chainIdToLabel: Record<string, string> = {
9698
'0x1': 'Ethereum',
9799
'0x3': 'Ropsten',

packages/core/src/validation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import type {
2222
PreflightNotificationsOptions
2323
} from './types'
2424

25-
const chainId = Joi.string().pattern(/^0x[0-9a-fA-F]+$/)
25+
// const chainId = Joi.string().pattern(/^0x[0-9a-fA-F]+$/)
26+
const chainId = Joi.alternatives().
27+
try(Joi.string().pattern(/^0x[0-9a-fA-F]+$/),
28+
Joi.number().positive())
2629
const chainNamespace = Joi.string().valid('evm')
2730
const unknownObject = Joi.object().unknown()
2831

0 commit comments

Comments
 (0)