import { Amounts, BackupBackupProviderTerms, i18n } from "@gnu-taler/taler-util"; import { Fragment, VNode } from "preact"; import { useState } from "preact/hooks"; import * as wxApi from "../wxApi"; interface Props { currency: string; onBack: () => void; } function getJsonIfOk(r: Response) { if (r.ok) { return r.json() } else { if (r.status >= 400 && r.status < 500) { throw new Error(`URL may not be right: (${r.status}) ${r.statusText}`) } else { throw new Error(`Try another server: (${r.status}) ${r.statusText || 'internal server error'}`) } } } export function ProviderAddPage({ onBack }: Props): VNode { const [verifying, setVerifying] = useState<{ url: string, provider: BackupBackupProviderTerms } | undefined>(undefined) const [readingTerms, setReadingTerms] = useState(undefined) const alreadyCheckedTheTerms = readingTerms === false if (!verifying) { return { return fetch(`${url}/config`) .catch(e => { throw new Error(`Network error`) }) .then(getJsonIfOk) .then((provider) => { setVerifying({ url, provider }); return undefined }) .catch((e) => e.message) }} /> } if (readingTerms) { return setReadingTerms(undefined)} onAccept={() => setReadingTerms(false)} /> } return { setVerifying(undefined); }} onShowTerms={() => { setReadingTerms(true) }} onConfirm={() => { wxApi.addBackupProvider(verifying.url).then(onBack) }} /> } interface TermsOfServiceProps { onCancel: () => void; onAccept: () => void; } function TermsOfService({ onCancel, onAccept }: TermsOfServiceProps) { return
Here we will place the complete text of terms of service
} export interface SetUrlViewProps { initialValue?: string; onCancel: () => void; onVerify: (s: string) => Promise; withError?: string; } import arrowDown from '../../static/img/chevron-down.svg'; export function SetUrlView({ initialValue, onCancel, onVerify, withError }: SetUrlViewProps) { const [value, setValue] = useState(initialValue || "") const [error, setError] = useState(withError) const [showErrorDetail, setShowErrorDetail] = useState(false); return
Add backup provider for saving coins

Backup provider URL

https://
setValue(e.currentTarget.value)} />

Backup providers may charge for their service

{error &&

Could not get provider information

{showErrorDetail &&
{error}
}
}
} export interface ConfirmProviderViewProps { provider: BackupBackupProviderTerms, url: string, onCancel: () => void; onConfirm: () => void; onShowTerms: () => void; termsChecked: boolean; } export function ConfirmProviderView({ url, termsChecked, onShowTerms, provider, onCancel, onConfirm }: ConfirmProviderViewProps) { return
Verify provider service terms for {url} backup provider

{Amounts.isZero(provider.annual_fee) ? 'free of charge' : provider.annual_fee} for a year of backup service

{provider.storage_limit_in_megabytes} megabytes of storage

}