import { Amounts, BackupBackupProviderTerms, i18n } from "@gnu-taler/taler-util"; import { VNode } from "preact"; import { useState } from "preact/hooks"; import { Checkbox } from "../components/Checkbox"; import { ErrorMessage } from "../components/ErrorMessage"; import { Button, ButtonPrimary, Input, LightText, PopupBox, SmallTextLight } from "../components/styled/index"; 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) 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) }} /> } return { setVerifying(undefined); }} onConfirm={() => { wxApi.addBackupProvider(verifying.url).then(onBack) }} /> } export interface SetUrlViewProps { initialValue?: string; onCancel: () => void; onVerify: (s: string) => Promise; withError?: string; } export function SetUrlView({ initialValue, onCancel, onVerify, withError }: SetUrlViewProps) { const [value, setValue] = useState(initialValue || "") const [error, setError] = useState(withError) return

Add backup provider

Backup providers may charge for their service

setValue(e.currentTarget.value)} />

{ let url = value.startsWith('http://') || value.startsWith('https://') ? value : `https://${value}` url = url.endsWith('/') ? url.substring(0, url.length - 1) : url; return onVerify(url).then(r => r ? setError(r) : undefined) }}>Next
} export interface ConfirmProviderViewProps { provider: BackupBackupProviderTerms, url: string, onCancel: () => void; onConfirm: () => void; } export function ConfirmProviderView({ url, provider, onCancel, onConfirm }: ConfirmProviderViewProps) { const [accepted, setAccepted] = useState(false); return

Review terms of service

Provider URL: {url}
Please review and accept this provider's terms of service

1. Pricing

{Amounts.isZero(provider.annual_fee) ? 'free of charge' : `${provider.annual_fee} per year of service`}

2. Storage

{provider.storage_limit_in_megabytes} megabytes of storage per year of service

setAccepted(old => !old)} enabled={accepted}/>
}