diff --git a/.circleci/config.yml b/.circleci/config.yml index 755afac11..70cc73d66 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -291,6 +291,12 @@ jobs: working_directory: ~/web3-onboard-monorepo/packages/gas steps: - node-build-steps + build-hw-common: + docker: + - image: cimg/node:16.13.1 + working_directory: ~/web3-onboard-monorepo/packages/hw-common + steps: + - node-build-steps # Build staging/Alpha releases build-staging-core: @@ -419,6 +425,12 @@ jobs: working_directory: ~/web3-onboard-monorepo/packages/gas steps: - node-staging-build-steps + build-staging-hw-common: + docker: + - image: cimg/node:16.13.1 + working_directory: ~/web3-onboard-monorepo/packages/hw-common + steps: + - node-staging-build-steps workflows: version: 2 @@ -549,3 +561,9 @@ workflows: <<: *deploy_production_filters - build-staging-gas: <<: *deploy_staging_filters + hw-common: + jobs: + - build-common: + <<: *deploy_production_filters + - build-staging-common: + <<: *deploy_staging_filters diff --git a/examples/with-vuejs/package.json b/examples/with-vuejs/package.json index 322e4879f..3a60cce97 100644 --- a/examples/with-vuejs/package.json +++ b/examples/with-vuejs/package.json @@ -9,7 +9,7 @@ }, "dependencies": { "@web3-onboard/injected-wallets": "^2.0.15", - "@web3-onboard/vue": "file:.yalc/@web3-onboard/vue", + "@web3-onboard/vue": "^2.1.6", "pinia": "^2.0.16", "vue": "^3.2.37", "vue-router": "^4.1.2" diff --git a/examples/with-vuejs/yarn.lock b/examples/with-vuejs/yarn.lock index 799079e2d..286d9607a 100644 --- a/examples/with-vuejs/yarn.lock +++ b/examples/with-vuejs/yarn.lock @@ -939,7 +939,7 @@ dependencies: vue-demi "*" -"@web3-onboard/common@^2.1.7", "@web3-onboard/common@^2.1.7-alpha.4": +"@web3-onboard/common@^2.1.7": version "2.1.7" resolved "https://registry.yarnpkg.com/@web3-onboard/common/-/common-2.1.7.tgz#62c74726ed9dd6e8baadab1e6aec6462d62e7d2d" integrity sha512-4nJvfNl0t5D17B1jD8H9BNBtUOVDDHxyxmRyQxnv1u1D5dgdd2I/mUVGhee0xWIHgMy9ORjuJCApraYCwZfgJA== @@ -950,12 +950,23 @@ joi "^17.4.2" rxjs "^7.5.2" -"@web3-onboard/core@^2.6.0-alpha.7": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.6.0.tgz#978b41211780189d9f5fb2f8f3259659bf6022e2" - integrity sha512-mxX4kMKetSqp/kDWYEZYqpIeDx7s3Q2i+XgS9FAaNDv+Rbv95CC/AC5zxpxiUy2zsixe8avTZtKoPXRV7y0Wag== +"@web3-onboard/common@^2.1.8": + version "2.1.8" + resolved "https://registry.yarnpkg.com/@web3-onboard/common/-/common-2.1.8.tgz#e20e027eaa597846b4ff178423de13d5ca597a5b" + integrity sha512-3kmJi0FKUw0rPXrbVe/BL+K13JSEzZ2QndnzpmHtKt4xFyRN+JgboAaAvJqfuk9t4hAZe45PqEWraSnYUCgDaA== dependencies: - "@web3-onboard/common" "^2.1.7" + "@ethereumjs/common" "2.6.2" + bignumber.js "^9.0.0" + ethers "5.5.4" + joi "^17.4.2" + rxjs "^7.5.2" + +"@web3-onboard/core@^2.7.0": + version "2.7.0" + resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.7.0.tgz#20acb5ae430cc5d0b2a7513e4e83f3182cff19eb" + integrity sha512-wxlUheuqgW8C5W2W4bpQdfjV9fXwmWxQx82IKem5kEnDhU8NPjVYEO/Xg4+kUwPlzYg0Uj/SPuGGjk+tNIrn9g== + dependencies: + "@web3-onboard/common" "^2.1.8" bignumber.js "^9.0.0" bnc-sdk "^4.4.1" bowser "^2.11.0" @@ -966,7 +977,7 @@ lodash.partition "^4.6.0" nanoid "^4.0.0" rxjs "^7.5.2" - svelte "^3.46.4" + svelte "^3.49.0" svelte-i18n "^3.3.13" "@web3-onboard/injected-wallets@^2.0.15": @@ -978,13 +989,15 @@ joi "^17.4.2" lodash.uniqby "^4.7.0" -"@web3-onboard/vue@file:.yalc/@web3-onboard/vue": - version "2.1.5-alpha.6" +"@web3-onboard/vue@^2.1.6": + version "2.1.6" + resolved "https://registry.yarnpkg.com/@web3-onboard/vue/-/vue-2.1.6.tgz#c634aff42932cc51e97bc40dc8669af1396d4485" + integrity sha512-RWWpZdTYLiwjUoem2+Lppdxtj0qPycrw44Dls83PjOp+9mO9/dvLO+FXSwmMJcPJiOH9WYPuejqAGOF89LQAUQ== dependencies: "@vueuse/core" "^8.4.2" "@vueuse/rxjs" "^8.2.0" - "@web3-onboard/common" "^2.1.7-alpha.4" - "@web3-onboard/core" "^2.6.0-alpha.7" + "@web3-onboard/common" "^2.1.8" + "@web3-onboard/core" "^2.7.0" vue-demi "^0.12.4" acorn-jsx@^5.3.2: @@ -2453,7 +2466,7 @@ svelte-i18n@^3.3.13: sade "^1.7.4" tiny-glob "^0.2.6" -svelte@^3.46.4: +svelte@^3.49.0: version "3.49.0" resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.49.0.tgz#5baee3c672306de1070c3b7888fc2204e36a4029" integrity sha512-+lmjic1pApJWDfPCpUUTc1m8azDqYCG1JN9YEngrx/hUyIcFJo6VZhj0A1Ai0wqoHcEIuQy+e9tk+4uDgdtsFA== diff --git a/package.json b/package.json index fc91d4fb0..4658f2f3f 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "install-m1-mac": "yarn install --ignore-optional", "format": "prettier --write 'packages/**/*.ts'", "dev": "yarn wsrun dev", - "build": "yarn wsrun --stages build", + "build": "yarn wsrun --serial build", "type-check": "yarn wsrun type-check" }, "devDependencies": { diff --git a/packages/coinbase/package.json b/packages/coinbase/package.json index 4c0c3555b..794021acb 100644 --- a/packages/coinbase/package.json +++ b/packages/coinbase/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/coinbase", - "version": "2.0.11", + "version": "2.1.0-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", @@ -36,7 +36,7 @@ "repository": { "type": "git", "url": "https://github.com/blocknative/web3-onboard.git", - "directory": "packages/core" + "directory": "packages/coinbase" }, "homepage": "https://www.blocknative.com/onboard", "bugs": "https://github.com/blocknative/web3-onboard/issues", @@ -59,6 +59,6 @@ }, "dependencies": { "@coinbase/wallet-sdk": "^3.0.5", - "@web3-onboard/common": "^2.1.8" + "@web3-onboard/common": "^2.2.0-alpha.1" } } diff --git a/packages/common/package.json b/packages/common/package.json index 0ae8e9135..bb449aa10 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/common", - "version": "2.1.8", + "version": "2.2.0-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", @@ -36,15 +36,14 @@ "repository": { "type": "git", "url": "https://github.com/blocknative/web3-onboard.git", - "directory": "packages/core" + "directory": "packages/common" }, "homepage": "https://www.blocknative.com/onboard", "bugs": "https://github.com/blocknative/web3-onboard/issues", "scripts": { - "build": "rollup -c", - "dev": "rollup -c -w", - "start": "sirv public --no-clear", - "type-check": "svelte-check --tsconfig ./tsconfig.json", + "build": "tsc", + "dev": "tsc -w", + "type-check": "tsc --noEmit", "lint": "eslint -c './.eslintrc.cjs' './src' && prettier --check './src/**/*'" }, "module": "dist/index.js", @@ -57,33 +56,25 @@ ], "license": "MIT", "devDependencies": { - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^11.0.0", - "@rollup/plugin-replace": "^3.0.0", - "@rollup/plugin-typescript": "^8.0.0", - "@tsconfig/svelte": "^2.0.0", "@typescript-eslint/eslint-plugin": "^4.31.1", "@typescript-eslint/parser": "^4.31.1", "eip-712": "^0.4.3", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", - "eslint-plugin-svelte3": "^3.2.1", "eventemitter3": "^4.0.7", "prettier": "^2.4.0", "prettier-plugin-svelte": "^2.4.0", "rollup": "^2.3.4", "rollup-plugin-svelte": "^7.0.0", - "svelte": "^3.49.0", + "svelte": "^3.42.5", "svelte-check": "^2.2.6", "svelte-preprocess": "^4.9.4", "tslib": "^2.0.0", "typescript": "^4.5.5" }, "dependencies": { - "@ethereumjs/common": "2.6.2", - "bignumber.js": "^9.0.0", + "bignumber.js": "^9.1.0", "ethers": "5.5.4", - "joi": "^17.4.2", - "rxjs": "^7.5.2" + "joi": "^17.4.2" } } diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index bf7240ce7..493c2f079 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -1,14 +1,7 @@ -export { ProviderRpcErrorCode } from './types' export { ProviderRpcError } from './errors' export { createEIP1193Provider } from './eip-1193' -export { default as accountSelect } from './account-select' -export { entryModal } from './entry-modal' export { SofiaProLight, SofiaProRegular, SofiaProSemiBold } from './fonts' -export { - getCommon, - bigNumberFieldsToStrings, - getHardwareWalletProvider -} from './hdwallets' export { weiToEth } from './utils' export * from './types' +export * from './validation' diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 3ad1c2518..10d46bfd3 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -75,56 +75,6 @@ export type RequestPatch = { }) => Promise) | null } - -// eslint-disable-next-line max-len -export type AccountSelectAPI = ( - options: SelectAccountOptions -) => Promise - -export type SelectAccountOptions = { - basePaths: BasePath[] // the paths to display in the base path selector - assets: Asset[] // the selectable assets to scan for a balance - chains: Chain[] // the selectable chains/networks to scan for balance - scanAccounts: ScanAccounts - supportsCustomPath?: boolean -} - -export type BasePath = { - label: string // eg - Ethereum Ledger Live - value: DerivationPath -} - -export type DerivationPath = string // eg - m/44'/60' - -export type Asset = { - label: string // eg - ETH - address?: string // if is a token, address to query contract -} - -export type ScanAccounts = (options: ScanAccountsOptions) => Promise - -export type ScanAccountsOptions = { - derivationPath: DerivationPath - chainId: Chain['id'] - asset: Asset -} - -export type AccountAddress = string - -export type Account = { - address: AccountAddress - derivationPath: DerivationPath - balance: { - asset: Asset['label'] - value: ethers.BigNumber - } -} - -export type AccountsList = { - all: Account[] - filtered: Account[] -} - export interface AppMetadata { /* App name */ name: string @@ -262,6 +212,8 @@ export interface ProviderInfo { chainId: ChainId } +export type AccountAddress = string + /** * An array of addresses */ diff --git a/packages/common/src/utils.ts b/packages/common/src/utils.ts index caf1e5b60..3d11abf68 100644 --- a/packages/common/src/utils.ts +++ b/packages/common/src/utils.ts @@ -1,5 +1,5 @@ -import BigNumber from 'bignumber.js' +import Bignumber from 'bignumber.js' export function weiToEth(wei: string): string { - return new BigNumber(wei).div(1e18).toString(10) -} \ No newline at end of file + return new Bignumber(wei).div(1e18).toString(10) +} diff --git a/packages/common/src/validation.ts b/packages/common/src/validation.ts index 904ffb3d4..631af1e09 100644 --- a/packages/common/src/validation.ts +++ b/packages/common/src/validation.ts @@ -1,49 +1,42 @@ import Joi from 'joi' -import type { SelectAccountOptions } from './types' -const basePath = Joi.object({ - label: Joi.string().required(), - value: Joi.string().required() +export type ValidateReturn = Joi.ValidationResult | null + +export function validate(validator: Joi.Schema, data: unknown): ValidateReturn { + const result = validator.validate(data) + return result.error ? result : null +} + +export const chainIdValidation = Joi.alternatives().try( + Joi.string().pattern(/^0x[0-9a-fA-F]+$/), + Joi.number().positive() +) + +export const chainNamespaceValidation = Joi.string().valid('evm') + +/** Related to ConnectionInfo from 'ethers/lib/utils' */ +export const providerConnectionInfoValidation = Joi.object({ + url: Joi.string().required(), + headers: Joi.object(), + user: Joi.string(), + password: Joi.string(), + allowInsecureAuthentication: Joi.boolean(), + allowGzip: Joi.boolean(), + throttleLimit: Joi.number(), + throttleSlotInterval: Joi.number(), + throttleCallback: Joi.function(), + timeout: Joi.number() }) -const basePaths = Joi.array().items(basePath) -const chain = Joi.object({ - namespace: Joi.string(), - id: Joi.string() - .pattern(/^0x[0-9a-fA-F]+$/) - .required(), +export const chainValidation = Joi.object({ + namespace: chainNamespaceValidation, + id: chainIdValidation.required(), rpcUrl: Joi.string().required(), label: Joi.string().required(), token: Joi.string().required(), icon: Joi.string(), - color: Joi.string() -}) - -const chains = Joi.array().items(chain) - -const asset = Joi.object({ - label: Joi.string().required(), - address: Joi.string() + color: Joi.string(), + publicRpcUrl: Joi.string(), + blockExplorerUrl: Joi.string(), + providerConnectionInfoValidation }) -const assets = Joi.array().items(asset) - -const selectAccountOptions = Joi.object({ - basePaths: basePaths, - assets: assets, - chains: chains, - scanAccounts: Joi.function().arity(1).required(), - supportsCustomPath: Joi.bool() -}) - -type ValidateReturn = Joi.ValidationResult | null - -const validate = (validator: Joi.Schema, data: unknown): ValidateReturn => { - const result = validator.validate(data) - return result.error ? result : null -} - -export const validateSelectAccountOptions = ( - data: SelectAccountOptions -): ValidateReturn => { - return validate(selectAccountOptions, data) -} diff --git a/packages/common/tsconfig.json b/packages/common/tsconfig.json index bd1cf6bcf..9db8ebeb0 100644 --- a/packages/common/tsconfig.json +++ b/packages/common/tsconfig.json @@ -1,15 +1,16 @@ { - "extends": "@tsconfig/svelte/tsconfig.json", - + "extends": "../../tsconfig.json", "include": ["src/**/*"], - "exclude": ["node_modules/*", "dist"], + "compilerOptions": { - "strict": true, + "outDir": "dist", + "rootDir": "src", "declaration": true, "declarationDir": "dist", - "target": "ES2018", - "module": "ES2020", - "resolveJsonModule": true - }, - "outDir": "dist" + "allowSyntheticDefaultImports": true, + "paths": { + "*": ["./src/*", "./node_modules/*"] + }, + "typeRoots": ["node_modules/@types"] + } } diff --git a/packages/core/package.json b/packages/core/package.json index 2581d35ba..13a5df2f0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/core", - "version": "2.7.0", + "version": "2.8.0-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", @@ -82,7 +82,7 @@ "typescript": "^4.5.5" }, "dependencies": { - "@web3-onboard/common": "^2.1.8", + "@web3-onboard/common": "^2.2.0-alpha.1", "bignumber.js": "^9.0.0", "bnc-sdk": "^4.4.1", "bowser": "^2.11.0", diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js index a70cda355..0995d1e78 100644 --- a/packages/core/rollup.config.js +++ b/packages/core/rollup.config.js @@ -12,7 +12,7 @@ export default { input: 'src/index.ts', output: { format: 'es', - dir: 'dist/', + dir: 'dist/' }, plugins: [ json(), @@ -38,7 +38,7 @@ export default { copy({ src: 'src/i18n/en.json', dest: 'i18n' - }), + }) ], external: [ '@web3-onboard/common', diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index 96b13018f..164f1ebc4 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -1,10 +1,15 @@ -import Joi, { ObjectSchema, Schema } from 'joi' -import type { - Chain, - ChainId, - DecimalChainId, - WalletInit, - WalletModule +import Joi from 'joi' + +import { + type ChainId, + type DecimalChainId, + type WalletInit, + type WalletModule, + type ValidateReturn, + chainNamespaceValidation, + chainIdValidation, + chainValidation, + validate } from '@web3-onboard/common' import type { @@ -24,45 +29,11 @@ import type { ConnectModalOptions } from './types' -// const chainId = Joi.string().pattern(/^0x[0-9a-fA-F]+$/) -const chainId = Joi.alternatives().try( - Joi.string().pattern(/^0x[0-9a-fA-F]+$/), - Joi.number().positive() -) -const chainNamespace = Joi.string().valid('evm') const unknownObject = Joi.object().unknown() -/** Related to ConnectionInfo from 'ethers/lib/utils' */ -const providerConnectionInfo = Joi.object({ - url: Joi.string().required(), - headers: Joi.object(), - user: Joi.string(), - password: Joi.string(), - allowInsecureAuthentication: Joi.boolean(), - allowGzip: Joi.boolean(), - throttleLimit: Joi.number(), - throttleSlotInterval: Joi.number(), - throttleCallback: Joi.function(), - timeout: Joi.number() -}) - -const chainValidationParams: Record = { - namespace: chainNamespace, - id: chainId.required(), - rpcUrl: Joi.string().required(), - label: Joi.string().required(), - token: Joi.string().required(), - icon: Joi.string(), - color: Joi.string(), - publicRpcUrl: Joi.string(), - blockExplorerUrl: Joi.string(), - providerConnectionInfo -} -const chain = Joi.object(chainValidationParams) - const connectedChain = Joi.object({ - namespace: chainNamespace.required(), - id: chainId.required() + namespace: chainNamespaceValidation.required(), + id: chainIdValidation.required() }) const ens = Joi.any().allow( @@ -88,7 +59,7 @@ const account = Joi.object({ balance }) -const chains = Joi.array().items(chain) +const chains = Joi.array().items(chainValidation) const accounts = Joi.array().items(account) const wallet = Joi.object({ @@ -218,8 +189,8 @@ const disconnectOptions = Joi.object({ }).required() const setChainOptions = Joi.object({ - chainId: chainId.required(), - chainNamespace: chainNamespace, + chainId: chainIdValidation.required(), + chainNamespace: chainNamespaceValidation, wallet: Joi.string() }) @@ -276,13 +247,6 @@ const transactionHandlerReturn = Joi.any().allow( Joi.boolean().allow(false) ) -type ValidateReturn = Joi.ValidationResult | null - -function validate(validator: Joi.Schema, data: unknown): ValidateReturn { - const result = validator.validate(data) - return result.error ? result : null -} - export function validateWallet( data: WalletState | Partial ): ValidateReturn { diff --git a/packages/dcent/package.json b/packages/dcent/package.json index e8937c5fe..1fffe7fe9 100644 --- a/packages/dcent/package.json +++ b/packages/dcent/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/dcent", - "version": "2.0.8", + "version": "2.1.0-alpha.1", "description": "D'CENT 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", @@ -36,7 +36,7 @@ "repository": { "type": "git", "url": "https://github.com/blocknative/web3-onboard.git", - "directory": "packages/core" + "directory": "packages/dcent" }, "homepage": "https://www.blocknative.com/onboard", "bugs": "https://github.com/blocknative/web3-onboard/issues", @@ -56,8 +56,8 @@ "typescript": "^4.5.5" }, "dependencies": { - "@web3-onboard/common": "^2.1.8", - "@ethereumjs/common": "^2.6.1", + "@web3-onboard/common": "^2.2.0-alpha.1", + "@web3-onboard/hw-common": "^2.0.0-alpha.1", "@ethereumjs/tx": "^3.4.0", "@ethersproject/providers": "^5.5.0", "eth-dcent-keyring": "^0.2.2" diff --git a/packages/dcent/src/index.ts b/packages/dcent/src/index.ts index f373e6d88..a38bd5f85 100644 --- a/packages/dcent/src/index.ts +++ b/packages/dcent/src/index.ts @@ -1,18 +1,12 @@ -import { - Account, - accountSelect, - Chain, - createEIP1193Provider, - CustomNetwork, - ProviderRpcErrorCode, - ProviderRpcError, - ScanAccountsOptions, - WalletInit, - EIP1193Provider -} from '@web3-onboard/common' - +import type { Chain, WalletInit, EIP1193Provider } from '@web3-onboard/common' import type { providers } from 'ethers' +import type { + CustomNetwork, + Account, + ScanAccountsOptions +} from '@web3-onboard/hw-common' + interface CustomWindow extends Window { ethereum: EIP1193Provider } @@ -89,7 +83,6 @@ function dcent({ const { StaticJsonRpcProvider } = await import( '@ethersproject/providers' ) - const { default: Common, Hardfork } = await import('@ethereumjs/common') const { default: EthDcentKeyring } = await import('eth-dcent-keyring') const dcentKeyring = new EthDcentKeyring({}) @@ -98,6 +91,16 @@ function dcent({ '@ethereumjs/tx' ) + const { getCommon, accountSelect } = await import( + '@web3-onboard/hw-common' + ) + + const { + createEIP1193Provider, + ProviderRpcErrorCode, + ProviderRpcError + } = await import('@web3-onboard/common') + let currentChain: Chain = chains[0] const scanAccounts = async ({ chainId @@ -193,16 +196,11 @@ function dcent({ // Set the `from` field to the currently selected account transactionObject = { ...transactionObject, from } - // @ts-ignore -- Due to weird commonjs exports - const CommonConstructor = Common.default || Common + const chainId = currentChain.hasOwnProperty('id') + ? Number.parseInt(currentChain.id) + : 1 - const common = new CommonConstructor({ - chain: customNetwork || Number.parseInt(currentChain.id) || 1, - // Berlin is the minimum hardfork that will allow for EIP1559 - hardfork: Hardfork.Berlin, - // List of supported EIPS - eips: [1559] - }) + const common = await getCommon({ customNetwork, chainId }) transactionObject.gasLimit = transactionObject.gas || transactionObject.gasLimit diff --git a/packages/demo/package.json b/packages/demo/package.json index 9aa2d306e..ba8dd4398 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -22,22 +22,22 @@ "webpack-dev-server": "4.7.4" }, "dependencies": { - "@web3-onboard/coinbase": "^2.0.10", - "@web3-onboard/core": "^2.7.0", - "@web3-onboard/dcent": "^2.0.7", - "@web3-onboard/fortmatic": "^2.0.9", - "@web3-onboard/gas": "^2.0.0", - "@web3-onboard/gnosis": "^2.0.8", - "@web3-onboard/injected-wallets": "^2.0.15", - "@web3-onboard/keepkey": "^2.1.7", - "@web3-onboard/keystone": "^2.1.8", - "@web3-onboard/ledger": "^2.1.8", - "@web3-onboard/magic": "^2.0.10", - "@web3-onboard/portis": "^2.0.7", - "@web3-onboard/torus": "^2.0.8", - "@web3-onboard/trezor": "^2.1.7", - "@web3-onboard/walletconnect": "^2.0.8", - "@web3-onboard/web3auth": "^2.0.6", + "@web3-onboard/coinbase": "^2.1.0-alpha.1", + "@web3-onboard/core": "^2.8.0-alpha.1", + "@web3-onboard/dcent": "^2.1.0-alpha.1", + "@web3-onboard/fortmatic": "^2.0.11-alpha.1", + "@web3-onboard/gas": "^2.1.0-alpha.1", + "@web3-onboard/gnosis": "^2.1.0-alpha.1", + "@web3-onboard/injected-wallets": "^2.1.0-alpha.1", + "@web3-onboard/keepkey": "^2.2.0-alpha.1", + "@web3-onboard/keystone": "^2.2.0-alpha.1", + "@web3-onboard/ledger": "^2.2.0-alpha.1", + "@web3-onboard/magic": "^2.1.0-alpha.1", + "@web3-onboard/portis": "^2.1.0-alpha.1", + "@web3-onboard/torus": "^2.1.0-alpha.1", + "@web3-onboard/trezor": "^2.2.0-alpha.1", + "@web3-onboard/walletconnect": "^2.1.0-alpha.1", + "@web3-onboard/web3auth": "^2.1.0-alpha.1", "vconsole": "^3.9.5" }, "license": "MIT", diff --git a/packages/fortmatic/package.json b/packages/fortmatic/package.json index 58ba1bb85..3e93c98a5 100644 --- a/packages/fortmatic/package.json +++ b/packages/fortmatic/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/fortmatic", - "version": "2.0.10", + "version": "2.0.11-alpha.1", "description": "Fortmatic 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", @@ -36,7 +36,7 @@ "repository": { "type": "git", "url": "https://github.com/blocknative/web3-onboard.git", - "directory": "packages/core" + "directory": "packages/fortmatic" }, "homepage": "https://www.blocknative.com/onboard", "bugs": "https://github.com/blocknative/web3-onboard/issues", @@ -59,7 +59,7 @@ "typescript": "^4.5.5" }, "dependencies": { - "@web3-onboard/common": "^2.1.8", + "@web3-onboard/common": "^2.2.0-alpha.1", "fortmatic": "^2.2.1" } } diff --git a/packages/gas/package.json b/packages/gas/package.json index 3c22b3635..b10fdba8a 100644 --- a/packages/gas/package.json +++ b/packages/gas/package.json @@ -1,9 +1,11 @@ { "name": "@web3-onboard/gas", - "version": "2.0.0", - "description": "Gas", + "version": "2.1.0-alpha.1", + "description": "Estimate the gas prices needed to get a transaction in to the next block for Ethereum Mainnet and Polygon Matic Mainnet.", "keywords": [ - "gas" + "gas", + "Ethereum", + "Polygon" ], "repository": { "type": "git", @@ -28,6 +30,7 @@ "typescript": "^4.5.5" }, "dependencies": { + "@web3-onboard/common": "^2.2.0-alpha.1", "rxjs": "^7.5.2", "joi": "^17.4.2" } diff --git a/packages/gas/src/validation.ts b/packages/gas/src/validation.ts index 1eb720b75..e5ff674c8 100644 --- a/packages/gas/src/validation.ts +++ b/packages/gas/src/validation.ts @@ -1,5 +1,6 @@ import Joi from 'joi' -import { RequestOptions, StreamOptions } from 'types' +import { RequestOptions, StreamOptions } from './types' +import { validate, type ValidateReturn } from '@web3-onboard/common' const requestOptions = Joi.object({ endpoint: Joi.string().valid('blockPrices').required(), @@ -8,13 +9,6 @@ const requestOptions = Joi.object({ poll: Joi.number().min(1000).max(5000) }) -type ValidateReturn = Joi.ValidationResult | null - -const validate = (validator: Joi.Schema, data: unknown): ValidateReturn => { - const result = validator.validate(data) - return result.error ? result : null -} - export const validateRequest = ( request: RequestOptions | StreamOptions ): ValidateReturn => validate(requestOptions, request) diff --git a/packages/gnosis/package.json b/packages/gnosis/package.json index 1e0034b0f..7e8cb0534 100644 --- a/packages/gnosis/package.json +++ b/packages/gnosis/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/gnosis", - "version": "2.0.9", + "version": "2.1.0-alpha.1", "description": "Gnosis Safe 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", @@ -34,7 +34,7 @@ "repository": { "type": "git", "url": "https://github.com/blocknative/web3-onboard.git", - "directory": "packages/core" + "directory": "packages/gnosis" }, "homepage": "https://www.blocknative.com/onboard", "bugs": "https://github.com/blocknative/web3-onboard/issues", @@ -59,6 +59,6 @@ "dependencies": { "@gnosis.pm/safe-apps-provider": "^0.9.2", "@gnosis.pm/safe-apps-sdk": "^6.1.1", - "@web3-onboard/common": "^2.1.8" + "@web3-onboard/common": "^2.2.0-alpha.1" } } diff --git a/packages/hw-common/.eslintrc.cjs b/packages/hw-common/.eslintrc.cjs new file mode 100644 index 000000000..03c345514 --- /dev/null +++ b/packages/hw-common/.eslintrc.cjs @@ -0,0 +1,43 @@ +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'prettier' + ], + plugins: ['svelte3', '@typescript-eslint'], + ignorePatterns: ['*.cjs'], + overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }], + settings: { + 'svelte3/typescript': () => require('typescript') + }, + parserOptions: { + sourceType: 'module', + ecmaVersion: 2019 + }, + env: { + browser: true, + node: true, + es2017: true + }, + rules: { + '@typescript-eslint/quotes': [ + 'error', + 'single', + { allowTemplateLiterals: true } + ], + '@typescript-eslint/no-case-declarations': 'off', + 'max-len': [ + 'error', + { + code: 80, + tabWidth: 2, + ignoreStrings: true, + ignoreTemplateLiterals: true + } + ], + 'object-curly-spacing': ['error', 'always'], + '@typescript-eslint/no-empty-function': 'off' + } +} diff --git a/packages/hw-common/.prettierrc.cjs b/packages/hw-common/.prettierrc.cjs new file mode 100644 index 000000000..c62c290ec --- /dev/null +++ b/packages/hw-common/.prettierrc.cjs @@ -0,0 +1,9 @@ +module.exports = { + semi: false, + trailingComma: 'none', + singleQuote: true, + printWidth: 80, + tabWidth: 2, + arrowParens: 'avoid', + svelteSortOrder: 'options-scripts-styles-markup' +} diff --git a/packages/hw-common/README.md b/packages/hw-common/README.md new file mode 100644 index 000000000..49543e387 --- /dev/null +++ b/packages/hw-common/README.md @@ -0,0 +1,3 @@ +# @web3-onboard/common + +## A collection of functions and types that are shared across various packages in the Onboard V2 monorepo diff --git a/packages/hw-common/package.json b/packages/hw-common/package.json new file mode 100644 index 000000000..01455b6f1 --- /dev/null +++ b/packages/hw-common/package.json @@ -0,0 +1,89 @@ +{ + "name": "@web3-onboard/hw-common", + "version": "2.0.0-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", + "Web3", + "EVM", + "dapp", + "Multichain", + "Wallet", + "Transaction", + "Provider", + "Hardware Wallet", + "Notifications", + "React", + "Svelte", + "Vue", + "Next", + "Nuxt", + "MetaMask", + "Coinbase", + "WalletConnect", + "Ledger", + "Trezor", + "Connect Wallet", + "Ethereum Hooks", + "Blocknative", + "Mempool", + "pending", + "confirmed", + "Injected Wallet", + "Crypto", + "Crypto Wallet" + ], + "repository": { + "type": "git", + "url": "https://github.com/blocknative/web3-onboard.git", + "directory": "packages/hw-common" + }, + "homepage": "https://www.blocknative.com/onboard", + "bugs": "https://github.com/blocknative/web3-onboard/issues", + "scripts": { + "build": "rollup -c", + "dev": "rollup -c -w", + "start": "sirv public --no-clear", + "type-check": "svelte-check --tsconfig ./tsconfig.json", + "lint": "eslint -c './.eslintrc.cjs' './src' && prettier --check './src/**/*'" + }, + "module": "dist/index.js", + "browser": "dist/index.js", + "main": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "files": [ + "dist" + ], + "license": "MIT", + "devDependencies": { + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^11.0.0", + "@rollup/plugin-replace": "^3.0.0", + "@rollup/plugin-typescript": "^8.0.0", + "@tsconfig/svelte": "^2.0.0", + "@typescript-eslint/eslint-plugin": "^4.31.1", + "@typescript-eslint/parser": "^4.31.1", + "eip-712": "^0.4.3", + "eslint": "^7.32.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-svelte3": "^3.2.1", + "eventemitter3": "^4.0.7", + "prettier": "^2.4.0", + "prettier-plugin-svelte": "^2.4.0", + "rollup": "^2.3.4", + "rollup-plugin-svelte": "^7.0.0", + "svelte": "^3.49.0", + "svelte-check": "^2.2.6", + "svelte-preprocess": "^4.9.4", + "tslib": "^2.0.0", + "typescript": "^4.5.5" + }, + "dependencies": { + "@ethereumjs/common": "2.6.2", + "@web3-onboard/common": "^2.2.0-alpha.1", + "ethers": "5.5.4", + "joi": "^17.4.2", + "rxjs": "^7.5.2" + } +} diff --git a/packages/common/rollup.config.js b/packages/hw-common/rollup.config.js similarity index 89% rename from packages/common/rollup.config.js rename to packages/hw-common/rollup.config.js index 0541818bf..569e3f178 100644 --- a/packages/common/rollup.config.js +++ b/packages/hw-common/rollup.config.js @@ -35,5 +35,11 @@ export default { inlineSources: !production }) ], - external: ['joi', 'rxjs', 'ethers', '@ethereumjs/common', 'bignumber.js'] + external: [ + 'joi', + 'rxjs', + 'ethers', + '@ethereumjs/common', + '@web3-onboard/common' + ] } diff --git a/packages/common/src/account-select.ts b/packages/hw-common/src/account-select.ts similarity index 96% rename from packages/common/src/account-select.ts rename to packages/hw-common/src/account-select.ts index a184f55ca..e31ace52d 100644 --- a/packages/common/src/account-select.ts +++ b/packages/hw-common/src/account-select.ts @@ -1,9 +1,8 @@ import { firstValueFrom, Subject, take } from 'rxjs' - +import { SofiaProRegular, SofiaProLight } from '@web3-onboard/common' import AccountSelect from './views/AccountSelect.svelte' import { accounts$ } from './streams' import { validateSelectAccountOptions } from './validation' -import { SofiaProRegular, SofiaProSemiBold, SofiaProLight } from './fonts' import type { SelectAccountOptions, Account } from './types' @@ -48,7 +47,6 @@ const mountAccountSelect = ( styleEl.innerHTML = ` ${SofiaProRegular} - ${SofiaProSemiBold} ${SofiaProLight} ` document.body.appendChild(styleEl) diff --git a/packages/common/src/elements/AddressTable.svelte b/packages/hw-common/src/elements/AddressTable.svelte similarity index 98% rename from packages/common/src/elements/AddressTable.svelte rename to packages/hw-common/src/elements/AddressTable.svelte index 99cacce03..13b03bdb3 100644 --- a/packages/common/src/elements/AddressTable.svelte +++ b/packages/hw-common/src/elements/AddressTable.svelte @@ -1,6 +1,6 @@