@m3s/wallet
Version:
A flexible wallet interface supporting multiple blockchain wallet types, including EVM wallets and Web3Auth integration
39 lines • 1.09 kB
JavaScript
import { AdapterError, WalletErrorCode } from "@m3s/shared";
import { ethers } from "ethers";
export function toWei(value, decimals) {
if (typeof value === 'bigint') {
return value.toString();
}
const s = String(value).trim();
if (!s || s === '0') {
return '0';
}
try {
return ethers.parseUnits(s, decimals).toString();
}
catch (err) {
throw new AdapterError(`Invalid value format: ${value}`, {
methodName: 'toWei',
code: WalletErrorCode.InvalidInput,
cause: err
});
}
}
export function toBigInt(value) {
try {
if (typeof value === "bigint")
return value;
if (typeof value === "number")
return BigInt(value);
// allow hex or decimal strings
return BigInt(value.trim());
}
catch (err) {
throw new AdapterError(`Invalid BigInt value: ${value}`, {
methodName: "toBigInt",
code: WalletErrorCode.InvalidInput,
cause: err
});
}
}
//# sourceMappingURL=units.js.map