summaryrefslogtreecommitdiff
path: root/packages/demobank-ui
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-03-07 09:34:06 -0300
committerSebastian <sebasjm@gmail.com>2024-03-07 09:34:28 -0300
commit2b76e32d5714fc410085b5a5ab5c1f4333190fe6 (patch)
treef890abb9b01c240561d29d489b345b0350b60e7a /packages/demobank-ui
parentb059cf4b16663ef2db70a2c2d7af0a6ba5ce2688 (diff)
downloadwallet-core-2b76e32d5714fc410085b5a5ab5c1f4333190fe6.tar.gz
wallet-core-2b76e32d5714fc410085b5a5ab5c1f4333190fe6.tar.bz2
wallet-core-2b76e32d5714fc410085b5a5ab5c1f4333190fe6.zip
time component
Diffstat (limited to 'packages/demobank-ui')
-rw-r--r--packages/demobank-ui/src/components/Cashouts/views.tsx60
-rw-r--r--packages/demobank-ui/src/components/Time.tsx71
-rw-r--r--packages/demobank-ui/src/components/Transactions/views.tsx15
-rw-r--r--packages/demobank-ui/src/pages/BankFrame.tsx6
-rw-r--r--packages/demobank-ui/src/pages/SolveChallengePage.tsx8
-rw-r--r--packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx12
6 files changed, 124 insertions, 48 deletions
diff --git a/packages/demobank-ui/src/components/Cashouts/views.tsx b/packages/demobank-ui/src/components/Cashouts/views.tsx
index 90ee6bc2f..09e986dd4 100644
--- a/packages/demobank-ui/src/components/Cashouts/views.tsx
+++ b/packages/demobank-ui/src/components/Cashouts/views.tsx
@@ -15,7 +15,9 @@
*/
import {
+ AbsoluteTime,
Amounts,
+ Duration,
HttpStatusCode,
TalerError,
assertUnreachable,
@@ -31,6 +33,7 @@ import { useConversionInfo } from "../../hooks/circuit.js";
import { RenderAmount } from "../../pages/PaytoWireTransferForm.js";
import { ErrorLoadingWithDebug } from "../ErrorLoadingWithDebug.js";
import { State } from "./index.js";
+import { Time } from "../Time.js";
export function FailedView({ error }: State.Failed) {
const { i18n } = useTranslationContext();
@@ -141,12 +144,6 @@ export function ReadyView({
</th>
</tr>
{txs.map((item) => {
- const creationTime =
- item.creation_time.t_s === "never"
- ? ""
- : format(item.creation_time.t_s * 1000, "HH:mm:ss", {
- locale: dateLocale,
- });
return (
<a
name="cashout details"
@@ -157,14 +154,17 @@ export function ReadyView({
cid: String(item.id),
})}
>
- <td class="relative py-2 pl-2 pr-2 text-sm ">
- <div class="font-medium text-gray-900">
- {creationTime}
- </div>
- {
- //FIXME: implement responsive view
- }
- {/* <dl class="font-normal sm:hidden">
+ <td class="relative py-2 pl-2 pr-2 text-sm ">
+ <div class="font-medium text-gray-900">
+ <Time format="HH:mm:ss"
+ timestamp={AbsoluteTime.fromProtocolTimestamp(item.creation_time)}
+ // relative={Duration.fromSpec({ days: 1 })}
+ />
+ </div>
+ {
+ //FIXME: implement responsive view
+ }
+ {/* <dl class="font-normal sm:hidden">
<dt class="sr-only sm:hidden"><i18n.Translate>Amount</i18n.Translate></dt>
<dd class="mt-1 truncate text-gray-700">
{item.negative ? i18n.str`sent` : i18n.str`received`} {item.amount ? (
@@ -185,24 +185,24 @@ export function ReadyView({
</pre>
</dd>
</dl> */}
- </td>
- <td class="hidden sm:table-cell px-3 py-3.5 text-sm text-red-600 cursor-pointer">
- <RenderAmount
- value={Amounts.parseOrThrow(item.amount_debit)}
- spec={resp.body.regional_currency_specification}
- />
- </td>
- <td class="hidden sm:table-cell px-3 py-3.5 text-sm text-green-600 cursor-pointer">
- <RenderAmount
- value={Amounts.parseOrThrow(item.amount_credit)}
- spec={resp.body.fiat_currency_specification}
- />
- </td>
+ </td>
+ <td class="hidden sm:table-cell px-3 py-3.5 text-sm text-red-600 cursor-pointer">
+ <RenderAmount
+ value={Amounts.parseOrThrow(item.amount_debit)}
+ spec={resp.body.regional_currency_specification}
+ />
+ </td>
+ <td class="hidden sm:table-cell px-3 py-3.5 text-sm text-green-600 cursor-pointer">
+ <RenderAmount
+ value={Amounts.parseOrThrow(item.amount_credit)}
+ spec={resp.body.fiat_currency_specification}
+ />
+ </td>
- <td class="hidden sm:table-cell px-3 py-3.5 text-sm text-gray-500 break-all min-w-md">
+ <td class="hidden sm:table-cell px-3 py-3.5 text-sm text-gray-500 break-all min-w-md">
- {item.subject}
- </td>
+ {item.subject}
+ </td>
</a>
);
})}
diff --git a/packages/demobank-ui/src/components/Time.tsx b/packages/demobank-ui/src/components/Time.tsx
new file mode 100644
index 000000000..39ce33f60
--- /dev/null
+++ b/packages/demobank-ui/src/components/Time.tsx
@@ -0,0 +1,71 @@
+/*
+ This file is part of GNU Taler
+ (C) 2022 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+import { AbsoluteTime, Duration } from "@gnu-taler/taler-util";
+import { useTranslationContext } from "@gnu-taler/web-util/browser";
+import { formatISO, format, formatDuration, intervalToDuration } from "date-fns";
+import { Fragment, h, VNode } from "preact";
+
+/**
+ *
+ * @param timestamp time to be formatted
+ * @param relative duration threshold, if the difference is lower
+ * the timestamp will be formatted as relative time from "now"
+ *
+ * @returns
+ */
+export function Time({
+ timestamp,
+ relative,
+ format: formatString,
+}: {
+ timestamp: AbsoluteTime | undefined;
+ relative?: Duration,
+ format: string;
+}): VNode {
+ const { i18n, dateLocale } = useTranslationContext()
+ if (!timestamp) return <Fragment />
+
+ if (timestamp.t_ms === "never") {
+ return <time >{i18n.str`never`}</time>
+ }
+
+ const now = AbsoluteTime.now();
+ const diff = AbsoluteTime.difference(now, timestamp)
+ if (relative && now.t_ms !== "never" && Duration.cmp(diff, relative) === -1) {
+ const d = intervalToDuration({
+ start: now.t_ms,
+ end: timestamp.t_ms
+ })
+ d.seconds = 0
+ const duration = formatDuration(d, { locale: dateLocale })
+ const isFuture = AbsoluteTime.cmp(now, timestamp) < 0
+ if (isFuture) {
+ return <time dateTime={formatISO(timestamp.t_ms)}>
+ <i18n.Translate>in {duration}</i18n.Translate>
+ </time>
+ } else {
+ return <time dateTime={formatISO(timestamp.t_ms)}>
+ <i18n.Translate>{duration} ago</i18n.Translate>
+ </time>
+ }
+ }
+ return (
+ <time dateTime={formatISO(timestamp.t_ms)}>
+ {format(timestamp.t_ms, formatString, { locale: dateLocale })}
+ </time>
+ );
+}
diff --git a/packages/demobank-ui/src/components/Transactions/views.tsx b/packages/demobank-ui/src/components/Transactions/views.tsx
index cdf134b2f..7da9fc5a9 100644
--- a/packages/demobank-ui/src/components/Transactions/views.tsx
+++ b/packages/demobank-ui/src/components/Transactions/views.tsx
@@ -20,6 +20,8 @@ import { Fragment, VNode, h } from "preact";
import { useBankCoreApiContext } from "../../context/config.js";
import { RenderAmount } from "../../pages/PaytoWireTransferForm.js";
import { State } from "./index.js";
+import { Duration } from "@gnu-taler/taler-util";
+import { Time } from "../Time.js";
export function ReadyView({
transactions,
@@ -107,19 +109,18 @@ export function ReadyView({
</th>
</tr>
{txs.map((item) => {
- const time =
- item.when.t_ms === "never"
- ? ""
- : format(item.when.t_ms, "HH:mm:ss", {
- locale: dateLocale,
- });
return (
<tr
key={idx}
class="border-b border-gray-200 last:border-none"
>
<td class="relative py-2 pl-2 pr-2 text-sm ">
- <div class="font-medium text-gray-900">{time}</div>
+ <div class="font-medium text-gray-900">
+ <Time format="HH:mm:ss"
+ timestamp={item.when}
+ // relative={Duration.fromSpec({ days: 1 })}
+ />
+ </div>
<dl class="font-normal sm:hidden">
<dt class="sr-only sm:hidden">
<i18n.Translate>Amount</i18n.Translate>
diff --git a/packages/demobank-ui/src/pages/BankFrame.tsx b/packages/demobank-ui/src/pages/BankFrame.tsx
index b6bfe1cfb..e1b8d6b83 100644
--- a/packages/demobank-ui/src/pages/BankFrame.tsx
+++ b/packages/demobank-ui/src/pages/BankFrame.tsx
@@ -17,12 +17,12 @@
import { Amounts, TalerError, TranslatedString } from "@gnu-taler/taler-util";
import {
Footer,
- GlobalNotificationsBanner,
Header,
Loading,
+ ToastBanner,
notifyError,
notifyException,
- useTranslationContext,
+ useTranslationContext
} from "@gnu-taler/web-util/browser";
import { ComponentChildren, VNode, h } from "preact";
import { useEffect, useErrorBoundary } from "preact/hooks";
@@ -146,7 +146,7 @@ export function BankFrame({
<div class="fixed z-20 w-full">
<div class="mx-auto w-4/5">
- <GlobalNotificationsBanner />
+ <ToastBanner />
</div>
</div>
diff --git a/packages/demobank-ui/src/pages/SolveChallengePage.tsx b/packages/demobank-ui/src/pages/SolveChallengePage.tsx
index b7fc82a94..1bafbc3eb 100644
--- a/packages/demobank-ui/src/pages/SolveChallengePage.tsx
+++ b/packages/demobank-ui/src/pages/SolveChallengePage.tsx
@@ -17,6 +17,7 @@
import {
AbsoluteTime,
Amounts,
+ Duration,
HttpStatusCode,
TalerCorebankApi,
TalerError,
@@ -47,6 +48,7 @@ import { undefinedIfEmpty } from "../utils.js";
import { RenderAmount } from "./PaytoWireTransferForm.js";
import { OperationNotFound } from "./WithdrawalQRCode.js";
import { useNavigationContext } from "../context/navigation.js";
+import { Time } from "../components/Time.js";
export function SolveChallengePage({
onChallengeCompleted,
@@ -533,9 +535,9 @@ function ChallengeDetails({
<i18n.Translate>Sent at</i18n.Translate>
</dt>
<dd class="mt-1 text-sm leading-6 text-gray-700 sm:col-span-2 sm:mt-0">
- {format(challenge.sent.t_ms, "dd/MM/yyyy HH:mm:ss", {
- locale: dateLocale,
- })}
+ <Time format="dd/MM/yyyy HH:mm:ss"
+ timestamp={challenge.sent}
+ relative={Duration.fromSpec({ days: 1 })} />
</dd>
</div>
)}
diff --git a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx
index f4b2130a9..33115c16a 100644
--- a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx
+++ b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx
@@ -14,7 +14,9 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
import {
+ AbsoluteTime,
Amounts,
+ Duration,
HttpStatusCode,
TalerError,
assertUnreachable,
@@ -30,6 +32,7 @@ import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js
import { useCashoutDetails, useConversionInfo } from "../../hooks/circuit.js";
import { RouteDefinition } from "../../route.js";
import { RenderAmount } from "../PaytoWireTransferForm.js";
+import { Time } from "../../components/Time.js";
interface Props {
id: string;
@@ -131,11 +134,10 @@ export function ShowCashoutDetails({ id, routeClose }: Props): VNode {
<i18n.Translate>Created</i18n.Translate>
</dt>
<dd class="text-sm ">
- {format(
- result.body.creation_time.t_s * 1000,
- "dd/MM/yyyy HH:mm:ss",
- { locale: dateLocale },
- )}
+ <Time format="dd/MM/yyyy HH:mm:ss"
+ timestamp={AbsoluteTime.fromProtocolTimestamp(result.body.creation_time)}
+ // relative={Duration.fromSpec({ days: 1 })}
+ />
</dd>
</div>
) : undefined}