15 lines
398 B
TypeScript
15 lines
398 B
TypeScript
import { Decimal } from '../../common/decimal';
|
|
|
|
const MISSING_PROTO_COMPONENT = 0;
|
|
|
|
const NANO = 1_000_000_000n;
|
|
|
|
export type ProtoDecimal = { nano?: number | string; units?: number | string };
|
|
|
|
export function decimal(value: ProtoDecimal): Decimal {
|
|
return {
|
|
value: BigInt(value.units ?? MISSING_PROTO_COMPONENT) * NANO + BigInt(value.nano ?? MISSING_PROTO_COMPONENT),
|
|
scale: 9,
|
|
};
|
|
}
|