@web3-onboard/common
Advanced tools
Comparing version 2.4.0-viemtest.1 to 2.4.0-wagmi.1
@@ -1,1 +0,1 @@ | ||
export declare const InterVar = "\n@font-face {\n font-family: 'Inter';\n font-style: normal;\n font-weight: 300 600;\n font-display: swap;\n src: url(\"https://rsms.me/inter/font-files/Inter-roman.var.woff2?v=3.19\") format(\"woff2\");\n}\n"; | ||
export declare const InterVar = "\n@font-face {\n font-family: 'Inter';\n font-style: normal;\n font-weight: 300 600;\n font-display: swap;\n src: url(\"https://rsms.me/inter/font-files/InterVariable.woff2\") format(\"woff2-variations\");\n}\n"; |
@@ -7,4 +7,4 @@ export const InterVar = ` | ||
font-display: swap; | ||
src: url("https://rsms.me/inter/font-files/Inter-roman.var.woff2?v=3.19") format("woff2"); | ||
src: url("https://rsms.me/inter/font-files/InterVariable.woff2") format("woff2-variations"); | ||
} | ||
`; |
export { ProviderRpcError } from './errors.js'; | ||
export { createEIP1193Provider } from './eip-1193.js'; | ||
export { InterVar } from './fonts.js'; | ||
export { weiHexToEth, weiToEth, isAddress, bigIntToHex, ethToWeiBigInt } 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 { weiHexToEth, weiToEth, isAddress, bigIntToHex, ethToWeiBigInt } 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'; | ||
@@ -81,4 +81,9 @@ export type { TypedData as EIP712TypedData } from 'eip-712'; | ||
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; | ||
}; | ||
@@ -297,2 +302,7 @@ export interface APIKey { | ||
publicRpcUrl?: string; | ||
/** An optional protected RPC URL - Defaults to Blocknative's private and | ||
* protected RPC to allow users to update the chain RPC within their wallet, | ||
* specifically for private RPCs that protect user transactions | ||
*/ | ||
protectedRpcUrl?: string; | ||
blockExplorerUrl?: string; | ||
@@ -299,0 +309,0 @@ } |
@@ -0,5 +1,9 @@ | ||
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: string) => 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,9 +0,8 @@ | ||
const addressRegex = /^0x[a-fA-F0-9]{40}$/; | ||
import { formatEther, fromHex, hexToBigInt, numberToHex, parseEther } from 'viem'; | ||
export const isAddress = (address) => { | ||
return addressRegex.test(address); | ||
return isAddress(address); | ||
}; | ||
export const weiHexToEth = (wei) => { | ||
const weiBigInt = BigInt(parseInt(wei, 16)); | ||
const ethBalance = divideBigIntWithDecimalResolution(weiBigInt, BigInt('1000000000000000000')); | ||
return ethBalance.toString(); | ||
const weiBigInt = hexToBigInt(wei); | ||
return formatEther(weiBigInt); | ||
}; | ||
@@ -13,22 +12,5 @@ export const weiToEth = (wei) => { | ||
return wei; | ||
const weiBigInt = BigInt(parseInt(wei)); | ||
const ethBalance = divideBigIntWithDecimalResolution(weiBigInt, BigInt('1000000000000000000')); | ||
return ethBalance.toString(); | ||
const weiBigInt = fromHex(wei, 'bigint'); | ||
return formatEther(weiBigInt); | ||
}; | ||
const divideBigIntWithDecimalResolution = (dividend, divisor, decimalPlaces = 8) => { | ||
if (typeof dividend !== 'bigint' || typeof divisor !== 'bigint') { | ||
throw new Error('dividend and divisor must be BigInt values'); | ||
} | ||
if (typeof decimalPlaces !== 'number' || decimalPlaces < 0) { | ||
throw new Error('decimalPlaces must be a non-negative number'); | ||
} | ||
// Multiply the dividend by 10 ** decimalPlaces to add precision | ||
const adjustedDividend = dividend * BigInt(10 ** decimalPlaces); | ||
const quotient = adjustedDividend / divisor; | ||
// Convert the result back to a decimal number | ||
const decimalPart = String(quotient % BigInt(10 ** decimalPlaces)).padStart(decimalPlaces, '0'); | ||
const integerPart = quotient / BigInt(10 ** decimalPlaces); | ||
const result = `${integerPart}.${decimalPart}`; | ||
return parseFloat(result); | ||
}; | ||
export const ethToWeiBigInt = (eth) => { | ||
@@ -39,13 +21,108 @@ if (typeof eth !== 'string' && typeof eth !== 'number') { | ||
const ethString = typeof eth === 'number' ? eth.toString() : eth; | ||
const decimalSplit = ethString.split('.'); | ||
const integerPart = BigInt(decimalSplit[0]); | ||
const decimalPart = decimalSplit.length > 1 ? BigInt(decimalSplit[1]) : BigInt(0); | ||
const decimalLength = decimalSplit.length > 1 ? decimalSplit[1].length : 0; | ||
const weiFactor = BigInt(10 ** (18 - decimalLength)); | ||
// Perform the conversion from Eth to Wei | ||
const weiValue = integerPart * BigInt(10 ** 18) + decimalPart * weiFactor; | ||
return BigInt(weiValue); | ||
return parseEther(ethString); | ||
}; | ||
export const bigIntToHex = (value) => { | ||
return `0x${value.toString(16)}`; | ||
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({ | ||
@@ -39,4 +26,4 @@ address: Joi.string().required(), | ||
publicRpcUrl: Joi.string(), | ||
blockExplorerUrl: Joi.string(), | ||
providerConnectionInfoValidation | ||
protectedRpcUrl: Joi.string(), | ||
blockExplorerUrl: Joi.string() | ||
}); |
{ | ||
"name": "@web3-onboard/common", | ||
"version": "2.4.0-viemtest.1", | ||
"version": "2.4.0-wagmi.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.", | ||
@@ -17,2 +17,3 @@ "keywords": [ | ||
"React", | ||
"Solid.js", | ||
"Svelte", | ||
@@ -74,8 +75,9 @@ "Vue", | ||
"tslib": "^2.0.0", | ||
"typescript": "^4.9.4", | ||
"typescript": "^5.4.5", | ||
"ethers": "5.5.4" | ||
}, | ||
"dependencies": { | ||
"joi": "17.9.1" | ||
"joi": "17.9.1", | ||
"viem": "2.10.5" | ||
} | ||
} |
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
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
665
2
+ Addedviem@2.10.5
+ 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.3(transitive)
+ Addedviem@2.10.5(transitive)
+ Addedws@8.13.0(transitive)