@web3-onboard/common
Advanced tools
Comparing version 2.3.4 to 2.4.0-alpha.2
export { ProviderRpcError } from './errors.js'; | ||
export { createEIP1193Provider } from './eip-1193.js'; | ||
export { InterVar } from './fonts.js'; | ||
export { weiToEth } from './utils.js'; | ||
export { weiHexToEth, weiToEth, isAddress, bigIntToHex, ethToWeiBigInt, createDownloadMessage, chainIdToViemImport } from './utils.js'; | ||
export * from './types.js'; | ||
export * from './validation.js'; |
export { ProviderRpcError } from './errors.js'; | ||
export { createEIP1193Provider } from './eip-1193.js'; | ||
export { InterVar } from './fonts.js'; | ||
export { weiToEth } from './utils.js'; | ||
export { weiHexToEth, weiToEth, isAddress, bigIntToHex, ethToWeiBigInt, createDownloadMessage, chainIdToViemImport } from './utils.js'; | ||
export * from './types.js'; | ||
export * from './validation.js'; |
import type { ConnectionInfo } from 'ethers/lib/utils'; | ||
import type EventEmitter from 'eventemitter3'; | ||
import EventEmitter from 'eventemitter3'; | ||
import type { TypedData as EIP712TypedData } from 'eip-712'; | ||
import type { ethers } from 'ethers'; | ||
export type { TypedData as EIP712TypedData } from 'eip-712'; | ||
@@ -79,7 +78,12 @@ /** | ||
* A method that takes `WalletHelpers` and | ||
* returns an initialised `WalletModule` or array of `WalletModule`s. | ||
* returns an initialized `WalletModule` or array of `WalletModule`s. | ||
*/ | ||
export type WalletInit = (helpers: WalletHelpers) => WalletModule | WalletModule[] | null; | ||
export type DeviceNotBrowser = { | ||
type: null; | ||
os: null; | ||
browser: null; | ||
}; | ||
export type WalletHelpers = { | ||
device: Device; | ||
device: Device | DeviceNotBrowser; | ||
}; | ||
@@ -121,3 +125,2 @@ export interface APIKey { | ||
appMetadata: AppMetadata | null; | ||
BigNumber: typeof ethers.BigNumber; | ||
EventEmitter: typeof EventEmitter; | ||
@@ -144,3 +147,3 @@ }; | ||
} | ||
export type AccountAddress = string; | ||
export type AccountAddress = Address; | ||
/** | ||
@@ -190,3 +193,3 @@ * An array of addresses | ||
} | ||
type Address = string; | ||
export type Address = `0x${string}`; | ||
type Message = string; | ||
@@ -193,0 +196,0 @@ export interface EthSignMessageRequest { |
@@ -1,1 +0,9 @@ | ||
export declare function weiToEth(wei: string): string; | ||
import type { Chain } from './types.js'; | ||
import type { Chain as ViemChain } from 'viem'; | ||
export declare const isAddress: (address: string) => address is `0x${string}`; | ||
export declare const weiHexToEth: (wei: `0x${string}`) => string; | ||
export declare const weiToEth: (wei: string) => string; | ||
export declare const ethToWeiBigInt: (eth: string | number) => bigint; | ||
export declare const bigIntToHex: (value: bigint) => string; | ||
export declare const createDownloadMessage: (walletLabel: string, download?: string | (() => void)) => string; | ||
export declare const chainIdToViemImport: (w3oChain: Chain) => Promise<ViemChain | unknown>; |
@@ -1,4 +0,126 @@ | ||
import Bignumber from 'bignumber.js'; | ||
export function weiToEth(wei) { | ||
return new Bignumber(wei).div(1e18).toString(10); | ||
} | ||
import { formatEther, fromHex, hexToBigInt, numberToHex, parseEther } from 'viem'; | ||
export const isAddress = (address) => { | ||
return isAddress(address); | ||
}; | ||
export const weiHexToEth = (wei) => { | ||
const weiBigInt = hexToBigInt(wei); | ||
return formatEther(weiBigInt); | ||
}; | ||
export const weiToEth = (wei) => { | ||
if (!wei) | ||
return wei; | ||
const weiBigInt = fromHex(wei, 'bigint'); | ||
return formatEther(weiBigInt); | ||
}; | ||
export const ethToWeiBigInt = (eth) => { | ||
if (typeof eth !== 'string' && typeof eth !== 'number') { | ||
throw new Error('eth must be a string or number value'); | ||
} | ||
const ethString = typeof eth === 'number' ? eth.toString() : eth; | ||
return parseEther(ethString); | ||
}; | ||
export const bigIntToHex = (value) => { | ||
return numberToHex(value); | ||
}; | ||
export const createDownloadMessage = (walletLabel, download) => { | ||
if (!download) | ||
return `Please switch to ${walletLabel} to continue`; | ||
if (typeof download === 'function') { | ||
return `Please <a href="#" onclick="${() => download()}">install</a> or enable to ${walletLabel} to continue`; | ||
} | ||
else { | ||
return `Please <a href="${download}" target="_blank">install</a> or enable to ${walletLabel} to continue`; | ||
} | ||
}; | ||
export const chainIdToViemImport = async (w3oChain) => { | ||
const viemChains = await import('viem/chains'); | ||
const { id, label, token, publicRpcUrl, blockExplorerUrl, rpcUrl } = w3oChain; | ||
switch (id) { | ||
case '0x89': { | ||
const { polygon } = viemChains; | ||
return polygon; | ||
} | ||
case '0xa': { | ||
const { optimism } = viemChains; | ||
return optimism; | ||
} | ||
case '0xa4b1': { | ||
const { arbitrum } = viemChains; | ||
return arbitrum; | ||
} | ||
case '0x144': { | ||
const { zkSync } = viemChains; | ||
return zkSync; | ||
} | ||
case '0x38': { | ||
const { bsc } = viemChains; | ||
return bsc; | ||
} | ||
case '0x1': { | ||
const { mainnet } = viemChains; | ||
return mainnet; | ||
} | ||
case '0xaa36a7': { | ||
const { sepolia } = viemChains; | ||
return sepolia; | ||
} | ||
case '0xfa': { | ||
const { fantom } = viemChains; | ||
return fantom; | ||
} | ||
case '0xa86a': { | ||
const { avalanche } = viemChains; | ||
return avalanche; | ||
} | ||
case '0xa4ec': { | ||
const { celo } = viemChains; | ||
return celo; | ||
} | ||
case '0x2105': { | ||
const { base } = viemChains; | ||
return base; | ||
} | ||
case '0x14a33': { | ||
const { baseGoerli } = viemChains; | ||
return baseGoerli; | ||
} | ||
case '0x64': { | ||
const { gnosis } = viemChains; | ||
return gnosis; | ||
} | ||
case '0x63564C40': { | ||
const { harmonyOne } = viemChains; | ||
return harmonyOne; | ||
} | ||
case '0x27bc86aa': { | ||
const { degen } = viemChains; | ||
return degen; | ||
} | ||
default: { | ||
const { extractChain, defineChain } = await import('viem'); | ||
const nonNativeChain = extractChain({ | ||
chains: Object.values(viemChains), | ||
id: fromHex(id, 'number') | ||
}); | ||
if (nonNativeChain) | ||
return nonNativeChain; | ||
return defineChain({ | ||
id: fromHex(id, 'number'), | ||
name: label !== null && label !== void 0 ? label : '', | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: token !== null && token !== void 0 ? token : '', | ||
symbol: token !== null && token !== void 0 ? token : '' | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: [rpcUrl !== null && rpcUrl !== void 0 ? rpcUrl : '', publicRpcUrl !== null && publicRpcUrl !== void 0 ? publicRpcUrl : ''] | ||
} | ||
}, | ||
blockExplorers: { | ||
default: { name: 'Explorer', url: blockExplorerUrl !== null && blockExplorerUrl !== void 0 ? blockExplorerUrl : '' } | ||
} | ||
}); | ||
} | ||
} | ||
}; |
@@ -6,4 +6,2 @@ import Joi from 'joi'; | ||
export declare const chainNamespaceValidation: Joi.StringSchema<string>; | ||
/** Related to ConnectionInfo from 'ethers/lib/utils' */ | ||
export declare const providerConnectionInfoValidation: Joi.ObjectSchema<any>; | ||
export declare const chainValidation: Joi.ObjectSchema<any>; |
@@ -8,15 +8,2 @@ import Joi from 'joi'; | ||
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 secondaryTokenValidation = Joi.object({ | ||
@@ -40,4 +27,3 @@ address: Joi.string().required(), | ||
protectedRpcUrl: Joi.string(), | ||
blockExplorerUrl: Joi.string(), | ||
providerConnectionInfoValidation | ||
blockExplorerUrl: Joi.string() | ||
}); |
{ | ||
"name": "@web3-onboard/common", | ||
"version": "2.3.4", | ||
"version": "2.4.0-alpha.2", | ||
"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.", | ||
@@ -74,9 +74,9 @@ "keywords": [ | ||
"tslib": "^2.0.0", | ||
"typescript": "^4.5.5" | ||
"typescript": "^5.4.5", | ||
"ethers": "5.5.4" | ||
}, | ||
"dependencies": { | ||
"bignumber.js": "^9.1.0", | ||
"ethers": "5.5.4", | ||
"joi": "17.9.1" | ||
"joi": "17.9.1", | ||
"viem": "2.12.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25576
2
665
16
1
+ Addedviem@2.12.0
+ Added@adraffy/ens-normalize@1.10.0(transitive)
+ Added@noble/curves@1.2.0(transitive)
+ Added@noble/hashes@1.3.2(transitive)
+ Added@scure/base@1.1.8(transitive)
+ Added@scure/bip32@1.3.2(transitive)
+ Added@scure/bip39@1.2.1(transitive)
+ Addedabitype@1.0.0(transitive)
+ Addedisows@1.0.4(transitive)
+ Addedviem@2.12.0(transitive)
+ Addedws@8.13.0(transitive)
- Removedbignumber.js@^9.1.0
- Removedethers@5.5.4
- Removed@ethersproject/abi@5.5.0(transitive)
- Removed@ethersproject/abstract-provider@5.5.1(transitive)
- Removed@ethersproject/abstract-signer@5.5.0(transitive)
- Removed@ethersproject/address@5.5.0(transitive)
- Removed@ethersproject/base64@5.5.0(transitive)
- Removed@ethersproject/basex@5.5.0(transitive)
- Removed@ethersproject/bignumber@5.5.0(transitive)
- Removed@ethersproject/bytes@5.5.0(transitive)
- Removed@ethersproject/constants@5.5.0(transitive)
- Removed@ethersproject/contracts@5.5.0(transitive)
- Removed@ethersproject/hash@5.5.0(transitive)
- Removed@ethersproject/hdnode@5.5.0(transitive)
- Removed@ethersproject/json-wallets@5.5.0(transitive)
- Removed@ethersproject/keccak256@5.5.0(transitive)
- Removed@ethersproject/logger@5.5.0(transitive)
- Removed@ethersproject/networks@5.5.2(transitive)
- Removed@ethersproject/pbkdf2@5.5.0(transitive)
- Removed@ethersproject/properties@5.5.0(transitive)
- Removed@ethersproject/providers@5.5.3(transitive)
- Removed@ethersproject/random@5.5.1(transitive)
- Removed@ethersproject/rlp@5.5.0(transitive)
- Removed@ethersproject/sha2@5.5.0(transitive)
- Removed@ethersproject/signing-key@5.5.0(transitive)
- Removed@ethersproject/solidity@5.5.0(transitive)
- Removed@ethersproject/strings@5.5.0(transitive)
- Removed@ethersproject/transactions@5.5.0(transitive)
- Removed@ethersproject/units@5.5.0(transitive)
- Removed@ethersproject/wallet@5.5.0(transitive)
- Removed@ethersproject/web@5.5.1(transitive)
- Removed@ethersproject/wordlists@5.5.0(transitive)
- Removedaes-js@3.0.0(transitive)
- Removedbech32@1.1.4(transitive)
- Removedbignumber.js@9.1.2(transitive)
- Removedbn.js@4.12.0(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedelliptic@6.5.4(transitive)
- Removedethers@5.5.4(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-sha3@0.8.0(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedscrypt-js@3.0.1(transitive)
- Removedws@7.4.6(transitive)