/* This file is part of TALER (C) 2016 GNUnet e.V. 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. 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 TALER; see the file COPYING. If not, see */ import { i18n } from "@gnu-taler/taler-util"; import { ProviderInfo, ProviderPaymentStatus, ProviderPaymentType, } from "@gnu-taler/taler-wallet-core"; import { Fragment, h, VNode } from "preact"; import { ErrorMessage } from "../components/ErrorMessage"; import { Loading } from "../components/Loading"; import { LoadingError } from "../components/LoadingError"; import { Button, ButtonDestructive, ButtonPrimary, PaymentStatus, SmallLightText, } from "../components/styled"; import { Time } from "../components/Time"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook"; import * as wxApi from "../wxApi"; interface Props { pid: string; onBack: () => void; } export function ProviderDetailPage({ pid: providerURL, onBack }: Props): VNode { async function getProviderInfo(): Promise { //create a first list of backup info by currency const status = await wxApi.getBackupInfo(); const providers = status.providers.filter( (p) => p.syncProviderBaseUrl === providerURL, ); return providers.length ? providers[0] : null; } const state = useAsyncAsHook(getProviderInfo); if (!state) { return ; } if (state.hasError) { return ( There was an error loading the provider detail for "{providerURL}" } error={state} /> ); } return ( wxApi.syncOneProvider(providerURL)} onDelete={async () => wxApi.removeProvider(providerURL).then(onBack)} onBack={onBack} onExtend={() => { null; }} /> ); } export interface ViewProps { url: string; info: ProviderInfo | null; onDelete: () => void; onSync: () => void; onBack: () => void; onExtend: () => void; } export function ProviderView({ info, url, onDelete, onSync, onBack, onExtend, }: ViewProps): VNode { if (info === null) { return (

There is not known provider with url "{url}".

); } const lb = info.lastSuccessfulBackupTimestamp; const isPaid = info.paymentStatus.type === ProviderPaymentType.Paid || info.paymentStatus.type === ProviderPaymentType.TermsChanged; return (

{info.name}{" "} {info.syncProviderBaseUrl}

{isPaid ? "Paid" : "Unpaid"}

Last backup: {" "}

Back up {info.terms && (

Provider fee: {" "} {info.terms && info.terms.annualFee}{" "} per year

)}

{descriptionByStatus(info.paymentStatus)}

Extend {info.paymentStatus.type === ProviderPaymentType.TermsChanged && (

terms has changed, extending the service will imply accepting the new terms of service

  old -> new
fee {info.paymentStatus.oldTerms.annualFee} -> {info.paymentStatus.newTerms.annualFee}
storage {info.paymentStatus.oldTerms.storageLimitInMegabytes} -> {info.paymentStatus.newTerms.storageLimitInMegabytes}
)}
Remove provider
); } function Error({ info }: { info: ProviderInfo }): VNode { if (info.lastError) { return ( This provider has reported an error } description={info.lastError.hint} /> ); } if (info.backupProblem) { switch (info.backupProblem.type) { case "backup-conflicting-device": return ( There is conflict with another backup from{" "} {info.backupProblem.otherDeviceId} } /> ); case "backup-unreadable": return ( Backup is not readable} /> ); default: return ( Unknown backup problem: {JSON.stringify(info.backupProblem)} } /> ); } } return ; } function descriptionByStatus(status: ProviderPaymentStatus): VNode { switch (status.type) { case ProviderPaymentType.Paid: case ProviderPaymentType.TermsChanged: if (status.paidUntil.t_ms === "never") { return ( service paid ); } return ( Backup valid until: {" "} ); case ProviderPaymentType.Unpaid: case ProviderPaymentType.InsufficientBalance: case ProviderPaymentType.Pending: return ; } }