Files
TheGame/packages/web/utils/mathHelper.ts

19 lines
546 B
TypeScript

import { BigNumberish, ethers } from 'ethers';
export const isPow2 = (int: number): boolean =>
int > 0 && (int & (int - 1)) === 0;
export const weiToEth = (amount?: BigNumberish) => {
if (amount === undefined) {
throw new Error('`amount` is `undefined` in `weiToEth`.');
}
return Number(ethers.formatEther(amount || 0));
};
export const ethToWei = (amount?: BigNumberish) => {
if (amount === undefined) {
throw new Error('`amount` is `undefined` in `ethToWei`.');
}
return ethers.parseEther((amount || 0).toString());
};