From 27201416c7d234361507e6055ce7ed42c11c650e Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 12 Sep 2022 10:57:13 -0300 Subject: ref #7323 --- packages/taler-util/src/time.ts | 15 +++++++++ packages/taler-util/src/walletTypes.ts | 61 +++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 4 deletions(-) (limited to 'packages/taler-util/src') 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 = { + 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 = { 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 = { [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; } export interface ExchangeListItem { @@ -771,6 +795,35 @@ const codecForExchangeTos = (): Codec => .property("content", codecOptional(codecForString())) .build("ExchangeTos"); +export const codecForFeeDescriptionPair = + (): Codec => + buildCodecForObject() + .property("value", codecForAmountJson()) + .property("from", codecForAbsoluteTime) + .property("until", codecForAbsoluteTime) + .property("left", codecOptional(codecForAmountJson())) + .property("right", codecOptional(codecForAmountJson())) + .build("FeeDescriptionPair"); + +export const codecForFeeDescription = + (): Codec => + buildCodecForObject() + .property("value", codecForAmountJson()) + .property("from", codecForAbsoluteTime) + .property("until", codecForAbsoluteTime) + .property("fee", codecOptional(codecForAmountJson())) + .build("FeeDescription"); + + +export const codecForFeesByOperations = + (): Codec> => + buildCodecForObject>() + .property("deposit", codecForList(codecForFeeDescription())) + .property("withdraw", codecForList(codecForFeeDescription())) + .property("refresh", codecForList(codecForFeeDescription())) + .property("refund", codecForList(codecForFeeDescription())) + .build("FeesByOperations"); + export const codecForExchangeFullDetails = (): Codec => buildCodecForObject() @@ -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 => buildCodecForObject() -- cgit v1.2.3