taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 7869e72c5fc7d12aca4822c23cbed2d076d3fc87
parent 411b0e10bd8179adc080d3881ddf19ec8274e5cc
Author: Sebastian <sebasjm@gmail.com>
Date:   Tue, 22 Oct 2024 12:32:51 -0300

fix #9227

Diffstat:
Mpackages/bank-ui/src/pages/admin/AdminHome.tsx | 51++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/packages/bank-ui/src/pages/admin/AdminHome.tsx b/packages/bank-ui/src/pages/admin/AdminHome.tsx @@ -18,6 +18,7 @@ import { AmountString, Amounts, CurrencySpecification, + Duration, HttpStatusCode, TalerCorebankApi, TalerError, @@ -90,15 +91,15 @@ export function AdminHome({ ); } -function getDateForTimeframe( +function getDateForTimeframeStart( date: AbsoluteTime, timeframe: TalerCorebankApi.MonitorTimeframeParam, locale: Locale, ): string { if (date.t_ms === "never") return "--"; switch (timeframe) { - case TalerCorebankApi.MonitorTimeframeParam.hour: - return `${format(date.t_ms, "HH", { locale })}hs`; + case TalerCorebankApi.MonitorTimeframeParam.hour: + return `${format(date.t_ms, "HH:00", { locale })}hs`; case TalerCorebankApi.MonitorTimeframeParam.day: return format(date.t_ms, "EEEE", { locale }); case TalerCorebankApi.MonitorTimeframeParam.month: @@ -111,6 +112,42 @@ function getDateForTimeframe( assertUnreachable(timeframe); } +function getDateForTimeframeEnd( + date: AbsoluteTime, + timeframe: TalerCorebankApi.MonitorTimeframeParam, + locale: Locale, +): string { + if (date.t_ms === "never") return "--"; + switch (timeframe) { + case TalerCorebankApi.MonitorTimeframeParam.hour: { + const end = AbsoluteTime.addDuration(date, Duration.fromSpec({hours: 1})) + if (end.t_ms === "never") throw Error(`abs time plus 1 hour duration can't be 'never'`) + return `${format(end.t_ms, "HH:00", { locale })}hs`; + } + case TalerCorebankApi.MonitorTimeframeParam.day: { + const end = AbsoluteTime.addDuration(date, Duration.fromSpec({days: 1})) + if (end.t_ms === "never") throw Error(`abs time plus 1 day duration can't be 'never'`) + return format(end.t_ms, "EEEE", { locale }); + } + case TalerCorebankApi.MonitorTimeframeParam.month: { + const end = AbsoluteTime.addDuration(date, Duration.fromSpec({months: 1})) + if (end.t_ms === "never") throw Error(`abs time plus 1 month duration can't be 'never'`) + return format(end.t_ms, "MMMM", { locale }); + } + case TalerCorebankApi.MonitorTimeframeParam.year: { + const end = AbsoluteTime.addDuration(date, Duration.fromSpec({years: 1})) + if (end.t_ms === "never") throw Error(`abs time plus 1 year duration can't be 'never'`) + return format(end.t_ms, "yyyy", { locale }); + } + case TalerCorebankApi.MonitorTimeframeParam.decade: { + const end = AbsoluteTime.addDuration(date, Duration.fromSpec({years: 10})) + if (end.t_ms === "never") throw Error(`abs time plus 10 years duration can't be 'never'`) + return format(end.t_ms, "yyyy", { locale }); + } + } + assertUnreachable(timeframe); +} + export function getTimeframesForDate( time: Date, timeframe: TalerCorebankApi.MonitorTimeframeParam, @@ -413,12 +450,12 @@ function Metrics({ <div class="w-full flex justify-between"> <h1 class="text-base text-gray-900 mt-5"> - {i18n.str`Trading volume on ${getDateForTimeframe( + {i18n.str`Trading volume from ${getDateForTimeframeStart( params.current, metricType, dateLocale, - )} compared to ${getDateForTimeframe( - params.previous, + )} to ${getDateForTimeframeEnd( + params.current, metricType, dateLocale, )}`} @@ -554,7 +591,7 @@ function MetricValue({ <div class="flex flex-col"> <div class="flex justify-end items-baseline text-2xl font-semibold text-indigo-600"> <small class="ml-2 text-sm font-medium text-gray-500"> - <i18n.Translate>from</i18n.Translate>{" "} + <i18n.Translate>previous</i18n.Translate>{" "} {!previous ? ( "-" ) : (