mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
24 lines
517 B
TypeScript
24 lines
517 B
TypeScript
import BigNumber from 'bignumber.js';
|
|
|
|
import type { Unit } from 'types/unit';
|
|
|
|
import { WEI, GWEI } from 'lib/consts';
|
|
|
|
export default function getValueWithUnit(value: string | number, unit: Unit = 'wei') {
|
|
let unitBn: BigNumber.Value;
|
|
switch (unit) {
|
|
case 'wei':
|
|
unitBn = WEI;
|
|
break;
|
|
case 'gwei':
|
|
unitBn = GWEI;
|
|
break;
|
|
default:
|
|
unitBn = new BigNumber(1);
|
|
}
|
|
|
|
const valueBn = new BigNumber(value);
|
|
const valueCurr = valueBn.dividedBy(unitBn);
|
|
return valueCurr;
|
|
}
|