/*
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 {
AmountJson,
Amounts,
AmountString,
PaytoUri,
} from "@gnu-taler/taler-util";
import { DepositFee } from "@gnu-taler/taler-wallet-core/src/operations/deposits";
import { Fragment, h, VNode } from "preact";
import { useEffect, useState } from "preact/hooks";
import { Part } from "../components/Part";
import { SelectList } from "../components/SelectList";
import {
ButtonPrimary,
ErrorText,
Input,
InputWithLabel,
} from "../components/styled";
import { useAsyncAsHook } from "../hooks/useAsyncAsHook";
import * as wxApi from "../wxApi";
interface Props {
currency: string;
}
export function DepositPage({ currency }: Props): VNode {
const [success, setSuccess] = useState(false);
const state = useAsyncAsHook(async () => {
const balance = await wxApi.getBalance();
const bs = balance.balances.filter((b) => b.available.startsWith(currency));
const currencyBalance =
bs.length === 0
? Amounts.getZero(currency)
: Amounts.parseOrThrow(bs[0].available);
const knownAccounts = await wxApi.listKnownBankAccounts(currency);
return { accounts: knownAccounts.accounts, currencyBalance };
});
const accounts =
state === undefined ? [] : state.hasError ? [] : state.response.accounts;
const currencyBalance =
state === undefined
? Amounts.getZero(currency)
: state.hasError
? Amounts.getZero(currency)
: state.response.currencyBalance;
async function doSend(account: string, amount: AmountString): Promise {
await wxApi.createDepositGroup(account, amount);
setSuccess(true);
}
async function getFeeForAmount(
account: string,
amount: AmountString,
): Promise {
return await wxApi.getFeeForDeposit(account, amount);
}
if (accounts.length === 0) return