Socket
Socket
Sign inDemoInstall

@web3-onboard/common

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3-onboard/common - npm Package Compare versions

Comparing version 2.4.0-viem.2 to 2.4.0-viem.3

2

dist/utils.d.ts
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;

@@ -1,9 +0,8 @@

const addressRegex = /^0x[a-fA-F0-9]{40}$/;
import { formatEther, 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);
};

@@ -14,21 +13,4 @@ export const weiToEth = (wei) => {

const weiBigInt = BigInt(parseInt(wei));
const ethBalance = divideBigIntWithDecimalResolution(weiBigInt, BigInt('1000000000000000000'));
return ethBalance.toString();
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,6 @@ 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);
};
{
"name": "@web3-onboard/common",
"version": "2.4.0-viem.2",
"version": "2.4.0-viem.3",
"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.",

@@ -78,4 +78,5 @@ "keywords": [

"dependencies": {
"joi": "17.9.1"
"joi": "17.9.1",
"viem": "2.10.2"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc