aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/pages/WithdrawalQRCode.tsx')
-rw-r--r--packages/demobank-ui/src/pages/WithdrawalQRCode.tsx163
1 files changed, 5 insertions, 158 deletions
diff --git a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
index 9976babdb..25c571e28 100644
--- a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
+++ b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
@@ -18,23 +18,17 @@ import {
Amounts,
HttpStatusCode,
Logger,
- TranslatedString,
WithdrawUriResult,
- parsePaytoUri,
- parseWithdrawUri,
- stringifyWithdrawUri,
+ parsePaytoUri
} from "@gnu-taler/taler-util";
-import { ErrorType, RequestError, notify, notifyError, notifyInfo, useTranslationContext } from "@gnu-taler/web-util/browser";
+import { ErrorType, notifyInfo, useTranslationContext } from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { Loading } from "../components/Loading.js";
-import { useAccessAPI, useWithdrawalDetails } from "../hooks/access.js";
+import { useWithdrawalDetails } from "../hooks/access.js";
import { useSettings } from "../hooks/settings.js";
import { handleNotOkResult } from "./HomePage.js";
-import { QrCodeSection, QrCodeSectionSimpler } from "./QrCodeSection.js";
+import { QrCodeSection } from "./QrCodeSection.js";
import { WithdrawalConfirmationQuestion } from "./WithdrawalConfirmationQuestion.js";
-import { useEffect, useState } from "preact/hooks";
-import { buildRequestErrorMessage } from "../utils.js";
-import { getInitialBackendBaseURL } from "../hooks/backend.js";
const logger = new Logger("WithdrawalQRCode");
@@ -54,18 +48,11 @@ export function WithdrawalQRCode({
const [settings, updateSettings] = useSettings();
const { i18n } = useTranslationContext();
const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId);
+
if (!result.ok) {
if (result.loading) {
return <Loading />;
}
- if (
- result.type === ErrorType.CLIENT &&
- result.status === HttpStatusCode.NotFound
- ) {
- onClose()
- return <div>operation not found</div>;
- }
- // onLoadNotOk();
return handleNotOkResult(i18n)(result);
}
const { data } = result;
@@ -127,22 +114,6 @@ export function WithdrawalQRCode({
</div>
</div>
</div>
- <div class="mt-4">
- <div class="flex items-center justify-between">
- <span class="flex flex-grow flex-col">
- <span class="text-sm text-black font-medium leading-6 " id="availability-label">
- <i18n.Translate>Do not show this again</i18n.Translate>
- </span>
- </span>
- <button type="button" data-enabled={!settings.showWithdrawalSuccess} class="bg-indigo-600 data-[enabled=false]:bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" role="switch" aria-checked="false" aria-labelledby="availability-label" aria-describedby="availability-description"
-
- onClick={() => {
- updateSettings("showWithdrawalSuccess", !settings.showWithdrawalSuccess);
- }}>
- <span aria-hidden="true" data-enabled={!settings.showWithdrawalSuccess} class="translate-x-5 data-[enabled=false]:translate-x-0 pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
- </button>
- </div>
- </div>
<div class="mt-5 sm:mt-6">
<button type="button"
class="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
@@ -182,7 +153,6 @@ export function WithdrawalQRCode({
the exchange is selcted but no account
</div>
}
-
return (
<WithdrawalConfirmationQuestion
withdrawUri={withdrawUri}
@@ -198,126 +168,3 @@ export function WithdrawalQRCode({
/>
);
}
-
-
-export function WithdrawalOperationState({
- currency,
- currentOperation,
- onClose,
-}: {currency:string, currentOperation: string, onClose: () => void}): VNode {
- const { i18n } = useTranslationContext();
- const [settings, updateSettings] = useSettings()
- const { createWithdrawal } = useAccessAPI();
-
- const amount = settings.maxWithdrawalAmount
- async function doSilentStart() {
- //FIXME: if amount is not enough use balance
- const parsedAmount = Amounts.parseOrThrow(`${currency}:${amount}`)
-
- try {
- const result = await createWithdrawal({
- amount: Amounts.stringify(parsedAmount),
- });
- const uri = parseWithdrawUri(result.data.taler_withdraw_uri);
- if (!uri) {
- return notifyError(
- i18n.str`Server responded with an invalid withdraw URI`,
- i18n.str`Withdraw URI: ${result.data.taler_withdraw_uri}`);
- } else {
- updateSettings("currentWithdrawalOperationId", uri.withdrawalOperationId)
- }
- } catch (error) {
- if (error instanceof RequestError) {
- notify(
- buildRequestErrorMessage(i18n, error.cause, {
- onClientError: (status) =>
- status === HttpStatusCode.Forbidden
- ? i18n.str`The operation was rejected due to insufficient funds`
- : undefined,
- }),
- );
- } else {
- notifyError(
- i18n.str`Operation failed, please report`,
- (error instanceof Error
- ? error.message
- : JSON.stringify(error)) as TranslatedString
- )
- }
- }
- }
-
- useEffect(() => {
- doSilentStart()
- }, [settings.fastWithdrawal, amount])
-
- const result = useWithdrawalDetails(currentOperation);
- if (!result.ok) {
- if (result.loading) {
- return <Loading />;
- }
- if (
- result.type === ErrorType.CLIENT &&
- result.status === HttpStatusCode.NotFound
- ) {
- onClose()
- return <div>operation not found</div>;
- }
- // onLoadNotOk();
- return handleNotOkResult(i18n)(result);
- }
- const { data } = result;
-
- const baseUrl = getInitialBackendBaseURL()
- const uri = stringifyWithdrawUri({
- bankIntegrationApiBaseUrl: `${baseUrl}/integration-api`,
- withdrawalOperationId: currentOperation,
- });
- const parsedUri = parseWithdrawUri(uri);
-
- if (data.aborted) {
- return <div>
- the operation was aborted, you can create another one
- </div>
- }
-
- if (data.confirmation_done) {
- return <div>
- the wire transfer is made, you coin should arrive shortly
- </div>
- }
- if (!parsedUri) {
- return <div>
- the operation is not valid, create another one
- </div>
- }
- if (!data.selection_done) {
- return (
- <QrCodeSectionSimpler
- withdrawUri={parsedUri}
- onAborted={() => {
- notifyInfo(i18n.str`Operation canceled`);
- onClose()
- }}
- />
- );
- }
-
- if (!data.selected_reserve_pub) {
- return <div>
- the exchange is selcted but no reserve pub
- </div>
- }
-
- const account = !data.selected_exchange_account ? undefined : parsePaytoUri(data.selected_exchange_account)
-
- if (!account) {
- return <div>
- the exchange is selected but no account
- </div>
- }
-
- return <div>
- the operation is wating for the question to be answered
- </div>;
-} \ No newline at end of file