aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-11-22 15:43:39 -0300
committerSebastian <sebasjm@gmail.com>2022-11-22 15:43:39 -0300
commit88618df7b870732f4f29a80686dd4f4cf20887f8 (patch)
tree07eb8deb17cbd430c3f1f6a5767980cf67ddf296 /packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
parentdc08d7d20eb805d95e7a74b1b6d5275e9e790953 (diff)
downloadwallet-core-88618df7b870732f4f29a80686dd4f4cf20887f8.tar.xz
amount field
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx')
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx141
1 files changed, 0 insertions, 141 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
deleted file mode 100644
index e2284a466..000000000
--- a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2022 Taler Systems S.A.
-
- GNU 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.
-
- GNU 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
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-import {
- AcceptManualWithdrawalResult,
- AmountJson,
- Amounts,
- NotificationType,
- parsePaytoUri,
- PaytoUri,
-} from "@gnu-taler/taler-util";
-import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { h, VNode } from "preact";
-import { useEffect, useState } from "preact/hooks";
-import { Loading } from "../components/Loading.js";
-import { LoadingError } from "../components/LoadingError.js";
-import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
-import { wxApi } from "../wxApi.js";
-import { CreateManualWithdraw } from "./CreateManualWithdraw.js";
-import { ReserveCreated } from "./ReserveCreated.js";
-
-interface Props {
- amount?: string;
- onCancel: () => Promise<void>;
-}
-
-export function ManualWithdrawPage({ amount, onCancel }: Props): VNode {
- const [success, setSuccess] = useState<
- | {
- response: AcceptManualWithdrawalResult;
- exchangeBaseUrl: string;
- amount: AmountJson;
- paytoURI: PaytoUri | undefined;
- payto: string;
- }
- | undefined
- >(undefined);
- const [error, setError] = useState<string | undefined>(undefined);
-
- const state = useAsyncAsHook(() =>
- wxApi.wallet.call(WalletApiOperation.ListExchanges, {}),
- );
- useEffect(() => {
- return wxApi.listener.onUpdateNotification(
- [NotificationType.ExchangeAdded],
- state?.retry,
- );
- });
- const { i18n } = useTranslationContext();
-
- async function doCreate(
- exchangeBaseUrl: string,
- amount: AmountJson,
- ): Promise<void> {
- try {
- const response = await wxApi.wallet.call(
- WalletApiOperation.AcceptManualWithdrawal,
- {
- exchangeBaseUrl: exchangeBaseUrl,
- amount: Amounts.stringify(amount),
- },
- );
- const payto = response.exchangePaytoUris[0];
- const paytoURI = parsePaytoUri(payto);
- setSuccess({ exchangeBaseUrl, response, amount, paytoURI, payto });
- } catch (e) {
- if (e instanceof Error) {
- setError(e.message);
- } else {
- setError("unexpected error");
- }
- setSuccess(undefined);
- }
- }
-
- if (success) {
- return (
- <ReserveCreated
- reservePub={success.response.reservePub}
- paytoURI={success.paytoURI}
- // payto={success.payto}
- exchangeBaseUrl={success.exchangeBaseUrl}
- amount={success.amount}
- onCancel={onCancel}
- />
- );
- }
-
- if (!state) {
- return <Loading />;
- }
- if (state.hasError) {
- return (
- <LoadingError
- title={
- <i18n.Translate>
- Could not load the list of known exchanges
- </i18n.Translate>
- }
- error={state}
- />
- );
- }
-
- const exchangeList = state.response.exchanges.reduce(
- (p, c) => ({
- ...p,
- [c.exchangeBaseUrl]: c.currency || "??",
- }),
- {} as Record<string, string>,
- );
-
- const parsedAmount = !amount ? undefined : Amounts.parse(amount);
- const currency = parsedAmount?.currency;
- const amountValue = !parsedAmount
- ? undefined
- : Amounts.stringifyValue(parsedAmount);
- return (
- <CreateManualWithdraw
- error={error}
- exchangeUrlWithCurrency={exchangeList}
- onCreate={doCreate}
- initialCurrency={currency}
- initialAmount={amountValue}
- />
- );
-}