/* 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, Timestamp } from "@gnu-taler/taler-util"; import { ProviderInfo, ProviderPaymentType } from "@gnu-taler/taler-wallet-core"; import { formatDuration, intervalToDuration } from "date-fns"; import { VNode } from "preact"; import { useRef, useState } from "preact/hooks"; import { useBackupStatus } from "../hooks/useProvidersByCurrency"; import * as wxApi from "../wxApi"; interface Props { currency: string; } export function ProviderPage({ currency }: Props): VNode { const status = useBackupStatus() const [adding, setAdding] = useState(false) if (!status) { return
Loading...
} if (adding) { return { console.log(value) wxApi.addBackupProvider(value).then(_ => history.go(-1)) setAdding(false) }} /> } const info = status.providers[currency]; return { null }} onDelete={() => { null }} onBack={() => { history.go(-1); }} onAddProvider={() => { setAdding(true) }} />; } function AddProviderView({ onConfirm }: { onConfirm: (s: string) => void }) { const textInput = useRef(null) return
} export interface ViewProps { currency: string; info?: ProviderInfo; onDelete: () => void; onSync: () => void; onBack: () => void; onAddProvider: () => void; } export function ProviderView({ currency, info, onDelete, onSync, onBack, onAddProvider }: ViewProps): VNode { function Footer() { return
{info && } {info && } {!info && }
} function Error() { if (info?.lastError) { return

{info.lastError.hint}

} if (info?.backupProblem) { switch (info.backupProblem.type) { case "backup-conflicting-device": return

There is another backup from {info.backupProblem.otherDeviceId}

case "backup-unreadable": return

Backup is not readable

default: return

Unkown backup problem: {JSON.stringify(info.backupProblem)}

} } return null } function colorByStatus(status: ProviderPaymentType | undefined) { switch (status) { case ProviderPaymentType.InsufficientBalance: return 'rgb(223, 117, 20)' case ProviderPaymentType.Unpaid: return 'rgb(202, 60, 60)' case ProviderPaymentType.Paid: return 'rgb(28, 184, 65)' case ProviderPaymentType.Pending: return 'gray' case ProviderPaymentType.InsufficientBalance: return 'rgb(202, 60, 60)' case ProviderPaymentType.TermsChanged: return 'rgb(202, 60, 60)' default: break; } return undefined } return (
{info?.paymentStatus.type} {info && From {info.syncProviderBaseUrl} }

{currency}

{info &&
{info.terms?.annualFee} / year
}
{daysSince(info?.lastSuccessfulBackupTimestamp)}
) } function daysSince(d?: Timestamp) { if (!d || d.t_ms === 'never') return 'never synced' const duration = intervalToDuration({ start: d.t_ms, end: new Date(), }) const str = formatDuration(duration, { delimiter: ', ', format: [ duration?.years ? 'years' : ( duration?.months ? 'months' : ( duration?.days ? 'days' : ( duration?.hours ? 'hours' : ( duration?.minutes ? 'minutes' : 'seconds' ) ) ) ) ] }) return `synced ${str} ago` }