From ec904b996d64aa7dee0ece729c66d23752938614 Mon Sep 17 00:00:00 2001 From: "frankind.eth" Date: Mon, 18 Mar 2024 17:32:23 -0300 Subject: [PATCH] refactor: Include ValidityPeriod logic --- src/price.ts | 4 ++-- src/time.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/price.ts b/src/price.ts index 62065e1..b6a0a0b 100644 --- a/src/price.ts +++ b/src/price.ts @@ -1,10 +1,10 @@ import { Currency, PriceCurrencyFormat } from "./currency"; import { approxScaleBigInt } from "./number"; -export type Price = { +export interface Price { value: bigint; currency: Currency; -}; +} // An ExchangeRates object maps different currencies to their rate in USD, // which is a number value. One example of an ExchangeRates object would be: diff --git a/src/time.ts b/src/time.ts index 1f6b680..52acea8 100644 --- a/src/time.ts +++ b/src/time.ts @@ -134,3 +134,19 @@ export function prettyTimestampDiffFromNow(timestamp: bigint): string { return "less than an hour"; } } + +export interface ValidityPeriod { + validFrom: bigint; + validUntil: bigint; +} + +export const createValidityPeriod = ( + validFrom: bigint, + validUntil: bigint +): ValidityPeriod => { + if (validFrom > validUntil) + throw new Error( + "Error creating ValidityPeriod. validFrom must be less than validUntil" + ); + return { validFrom, validUntil }; +};