@web3-onboard/common
Advanced tools
Comparing version 2.3.2 to 2.4.0-viemtest.1
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 } 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 } from './utils.js'; | ||
export * from './types.js'; | ||
export * from './validation.js'; |
import type { ConnectionInfo } from 'ethers/lib/utils'; | ||
import type 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,3 +78,3 @@ /** | ||
* A method that takes `WalletHelpers` and | ||
* returns an initialised `WalletModule` or array of `WalletModule`s. | ||
* returns an initialized `WalletModule` or array of `WalletModule`s. | ||
*/ | ||
@@ -121,3 +120,2 @@ export type WalletInit = (helpers: WalletHelpers) => WalletModule | WalletModule[] | null; | ||
appMetadata: AppMetadata | null; | ||
BigNumber: typeof ethers.BigNumber; | ||
EventEmitter: typeof EventEmitter; | ||
@@ -144,3 +142,3 @@ }; | ||
} | ||
export type AccountAddress = string; | ||
export type AccountAddress = Address; | ||
/** | ||
@@ -190,3 +188,3 @@ * An array of addresses | ||
} | ||
type Address = string; | ||
export type Address = `0x${string}`; | ||
type Message = string; | ||
@@ -193,0 +191,0 @@ export interface EthSignMessageRequest { |
@@ -1,1 +0,5 @@ | ||
export declare function weiToEth(wei: string): string; | ||
export declare const isAddress: (address: string) => address is `0x${string}`; | ||
export declare const weiHexToEth: (wei: string) => string; | ||
export declare const weiToEth: (wei: string) => string; | ||
export declare const ethToWeiBigInt: (eth: string | number) => bigint; | ||
export declare const bigIntToHex: (value: bigint) => string; |
@@ -1,4 +0,49 @@ | ||
import Bignumber from 'bignumber.js'; | ||
export function weiToEth(wei) { | ||
return new Bignumber(wei).div(1e18).toString(10); | ||
} | ||
const addressRegex = /^0x[a-fA-F0-9]{40}$/; | ||
export const isAddress = (address) => { | ||
return addressRegex.test(address); | ||
}; | ||
export const weiHexToEth = (wei) => { | ||
const weiBigInt = BigInt(parseInt(wei, 16)); | ||
const ethBalance = divideBigIntWithDecimalResolution(weiBigInt, BigInt('1000000000000000000')); | ||
return ethBalance.toString(); | ||
}; | ||
export const weiToEth = (wei) => { | ||
if (!wei) | ||
return wei; | ||
const weiBigInt = BigInt(parseInt(wei)); | ||
const ethBalance = divideBigIntWithDecimalResolution(weiBigInt, BigInt('1000000000000000000')); | ||
return ethBalance.toString(); | ||
}; | ||
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) => { | ||
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; | ||
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); | ||
}; | ||
export const bigIntToHex = (value) => { | ||
return `0x${value.toString(16)}`; | ||
}; |
{ | ||
"name": "@web3-onboard/common", | ||
"version": "2.3.2", | ||
"version": "2.4.0-viemtest.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.", | ||
@@ -73,9 +73,8 @@ "keywords": [ | ||
"tslib": "^2.0.0", | ||
"typescript": "^4.5.5" | ||
"typescript": "^4.9.4", | ||
"ethers": "5.5.4" | ||
}, | ||
"dependencies": { | ||
"bignumber.js": "^9.1.0", | ||
"ethers": "5.5.4", | ||
"joi": "17.9.1" | ||
} | ||
} |
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
23431
1
589
16
1
- 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)