/* This file is part of GNU Taler (C) 2021-2023 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 */ /** * * @author Sebastian Javier Marchano (sebasjm) */ import { Amounts, parsePaytoUri, stringifyPaytoUri, } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { format } from "date-fns"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { QR } from "../../../../components/exception/QR.js"; import { FormProvider } from "../../../../components/form/FormProvider.js"; import { Input } from "../../../../components/form/Input.js"; import { InputCurrency } from "../../../../components/form/InputCurrency.js"; import { InputDate } from "../../../../components/form/InputDate.js"; import { TextField } from "../../../../components/form/TextField.js"; import { SimpleModal } from "../../../../components/modal/index.js"; import { MerchantBackend } from "../../../../declaration.js"; import { useRewardDetails } from "../../../../hooks/reserves.js"; import { RewardInfo } from "./RewardInfo.js"; import { ShowAccountsOfReserveAsQRWithLink } from "../create/CreatedSuccessfully.js"; import { datetimeFormatForSettings, useSettings } from "../../../../hooks/useSettings.js"; type Entity = MerchantBackend.Rewards.ReserveDetail; type CT = MerchantBackend.ContractTerms; interface Props { onBack: () => void; selected: Entity; id: string; } export function DetailPage({ id, selected, onBack }: Props): VNode { const { i18n } = useTranslationContext(); const didExchangeAckTransfer = Amounts.isNonZero( Amounts.parseOrThrow(selected.exchange_initial_amount), ); return (
name="creation_time" label={i18n.str`Created at`} readonly /> name="expiration_time" label={i18n.str`Valid until`} readonly /> name="merchant_initial_amount" label={i18n.str`Created balance`} readonly /> name="exchange_url" label={i18n.str`Exchange URL`} readonly > {selected.exchange_url} {didExchangeAckTransfer && ( name="exchange_initial_amount" label={i18n.str`Exchange balance`} readonly /> name="pickup_amount" label={i18n.str`Picked up`} readonly /> name="committed_amount" label={i18n.str`Committed`} readonly /> )} {didExchangeAckTransfer ? (

Rewards

{selected.rewards && selected.rewards.length > 0 ? ( ) : ( )} ) : selected.accounts ? ( ) : undefined}
); } function EmptyTable(): VNode { const { i18n } = useTranslationContext(); return (

No reward has been authorized from this reserve

); } interface TableProps { rewards: MerchantBackend.Rewards.RewardStatusEntry[]; } function Table({ rewards }: TableProps): VNode { const { i18n } = useTranslationContext(); return (
{rewards.map((t, i) => { return ; })}
Authorized Picked up Reason Expiration
); } function RewardRow({ id, entry, }: { id: string; entry: MerchantBackend.Rewards.RewardStatusEntry; }) { const [selected, setSelected] = useState(false); const result = useRewardDetails(id); const [settings] = useSettings(); if (result.loading) { return ( ... ... ... ... ); } if (!result.ok) { return ( ... {/* authorized */} {entry.total_amount} {entry.reason} ... {/* expired */} ); } const info = result.data; function onSelect() { setSelected(true); } return ( {selected && ( setSelected(false)} > )} {info.total_authorized} {info.total_picked_up} {info.reason} {info.expiration.t_s === "never" ? "never" : format(info.expiration.t_s * 1000, datetimeFormatForSettings(settings))} ); }