import type { Money } from '../../common/money.types'; import { Decimal, formatDecimal } 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 rubMoney(value?: ProtoDecimal & { currency?: string }): Money | null { return value?.currency?.trim().toUpperCase() === 'RUB' ? { currency: 'RUB', value: formatDecimal(decimal(value)) } : null; } export function decimal(value: ProtoDecimal): Decimal { return { value: BigInt(value.units ?? MISSING_PROTO_COMPONENT) * NANO + BigInt(value.nano ?? MISSING_PROTO_COMPONENT), scale: 9, }; }