diff options
Diffstat (limited to 'packages/taler-util')
-rw-r--r-- | packages/taler-util/src/time.ts | 15 | ||||
-rw-r--r-- | packages/taler-util/src/walletTypes.ts | 61 |
2 files changed, 72 insertions, 4 deletions
diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts index 0ba684beb..9c25af400 100644 --- a/packages/taler-util/src/time.ts +++ b/packages/taler-util/src/time.ts @@ -343,6 +343,21 @@ export function durationAdd(d1: Duration, d2: Duration): Duration { return { d_ms: d1.d_ms + d2.d_ms }; } +export const codecForAbsoluteTime: Codec<AbsoluteTime> = { + decode(x: any, c?: Context): AbsoluteTime { + const t_ms = x.t_ms; + if (typeof t_ms === "string") { + if (t_ms === "never") { + return { t_ms: "never" }; + } + } else if (typeof t_ms === "number") { + return { t_ms }; + } + throw Error(`expected timestamp at ${renderContext(c)}`); + }, +}; + + export const codecForTimestamp: Codec<TalerProtocolTimestamp> = { decode(x: any, c?: Context): TalerProtocolTimestamp { // Compatibility, should be removed soon. diff --git a/packages/taler-util/src/walletTypes.ts b/packages/taler-util/src/walletTypes.ts index e79aa0b36..43570c44c 100644 --- a/packages/taler-util/src/walletTypes.ts +++ b/packages/taler-util/src/walletTypes.ts @@ -32,7 +32,7 @@ import { codecForAmountJson, codecForAmountString, } from "./amounts.js"; -import { codecForTimestamp, TalerProtocolTimestamp } from "./time.js"; +import { AbsoluteTime, codecForAbsoluteTime, codecForTimestamp, TalerProtocolTimestamp } from "./time.js"; import { buildCodecForObject, codecForString, @@ -733,6 +733,30 @@ export interface DenominationInfo { stampExpireDeposit: TalerProtocolTimestamp; } +export type Operation = "deposit" | "withdraw" | "refresh" | "refund"; +export type OperationMap<T> = { [op in Operation]: T }; + +export interface FeeDescription { + value: AmountJson; + from: AbsoluteTime; + until: AbsoluteTime; + fee?: AmountJson; +} + +export interface FeeDescriptionPair { + value: AmountJson; + from: AbsoluteTime; + until: AbsoluteTime; + left?: AmountJson; + right?: AmountJson; +} + +export interface TimePoint { + type: "start" | "end"; + moment: AbsoluteTime; + denom: DenominationInfo; +} + export interface ExchangeFullDetails { exchangeBaseUrl: string; currency: string; @@ -740,7 +764,7 @@ export interface ExchangeFullDetails { tos: ExchangeTos; auditors: ExchangeAuditor[]; wireInfo: WireInfo; - denominations: DenominationInfo[]; + feesDescription: OperationMap<FeeDescription[]>; } export interface ExchangeListItem { @@ -771,6 +795,35 @@ const codecForExchangeTos = (): Codec<ExchangeTos> => .property("content", codecOptional(codecForString())) .build("ExchangeTos"); +export const codecForFeeDescriptionPair = + (): Codec<FeeDescriptionPair> => + buildCodecForObject<FeeDescriptionPair>() + .property("value", codecForAmountJson()) + .property("from", codecForAbsoluteTime) + .property("until", codecForAbsoluteTime) + .property("left", codecOptional(codecForAmountJson())) + .property("right", codecOptional(codecForAmountJson())) + .build("FeeDescriptionPair"); + +export const codecForFeeDescription = + (): Codec<FeeDescription> => + buildCodecForObject<FeeDescription>() + .property("value", codecForAmountJson()) + .property("from", codecForAbsoluteTime) + .property("until", codecForAbsoluteTime) + .property("fee", codecOptional(codecForAmountJson())) + .build("FeeDescription"); + + +export const codecForFeesByOperations = + (): Codec<OperationMap<FeeDescription[]>> => + buildCodecForObject<OperationMap<FeeDescription[]>>() + .property("deposit", codecForList(codecForFeeDescription())) + .property("withdraw", codecForList(codecForFeeDescription())) + .property("refresh", codecForList(codecForFeeDescription())) + .property("refund", codecForList(codecForFeeDescription())) + .build("FeesByOperations"); + export const codecForExchangeFullDetails = (): Codec<ExchangeFullDetails> => buildCodecForObject<ExchangeFullDetails>() @@ -780,8 +833,8 @@ export const codecForExchangeFullDetails = .property("tos", codecForExchangeTos()) .property("auditors", codecForList(codecForExchangeAuditor())) .property("wireInfo", codecForWireInfo()) - .property("denominations", codecForList(codecForDenominationInfo())) - .build("ExchangeListItem"); + .property("feesDescription", codecForFeesByOperations()) + .build("ExchangeFullDetails"); export const codecForExchangeListItem = (): Codec<ExchangeListItem> => buildCodecForObject<ExchangeListItem>() |