summaryrefslogtreecommitdiff
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.tsx75
1 files changed, 44 insertions, 31 deletions
diff --git a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
index 1a4157d06..9c5f83eca 100644
--- a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
+++ b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
@@ -14,30 +14,35 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { Logger, parseWithdrawUri } from "@gnu-taler/taler-util";
import {
+ HttpStatusCode,
+ Logger,
+ WithdrawUriResult,
+} from "@gnu-taler/taler-util";
+import {
+ ErrorType,
HttpResponsePaginated,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
import { Fragment, h, VNode } from "preact";
import { Loading } from "../components/Loading.js";
-import { PageStateType } from "../context/pageState.js";
+import {
+ ObservedStateType,
+ notifyError,
+ notifyInfo,
+} from "../context/pageState.js";
import { useWithdrawalDetails } from "../hooks/access.js";
import { QrCodeSection } from "./QrCodeSection.js";
import { WithdrawalConfirmationQuestion } from "./WithdrawalConfirmationQuestion.js";
+import { handleNotOkResult } from "./HomePage.js";
const logger = new Logger("WithdrawalQRCode");
interface Props {
- account: string;
- withdrawalId: string;
- talerWithdrawUri: string;
- onError: (e: PageStateType["error"]) => void;
+ withdrawUri: WithdrawUriResult;
onAborted: () => void;
onConfirmed: () => void;
- onLoadNotOk: <T>(
- error: HttpResponsePaginated<T, SandboxBackend.SandboxError>,
- ) => VNode;
+ onLoadNotOk: () => void;
}
/**
* Offer the QR code (and a clickable taler://-link) to
@@ -45,43 +50,46 @@ interface Props {
* the bank. Poll the backend until such operation is done.
*/
export function WithdrawalQRCode({
- account,
- withdrawalId,
- talerWithdrawUri,
+ withdrawUri,
onConfirmed,
onAborted,
- onError,
onLoadNotOk,
}: Props): VNode {
const { i18n } = useTranslationContext();
-
- const result = useWithdrawalDetails(account, withdrawalId);
+ const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId);
if (!result.ok) {
- return onLoadNotOk(result);
+ if (result.loading) {
+ return <Loading />;
+ }
+ if (
+ result.type === ErrorType.CLIENT &&
+ result.status === HttpStatusCode.NotFound
+ ) {
+ return <div>operation not found</div>;
+ }
+ console.log("result", result);
+ onLoadNotOk();
+ return handleNotOkResult(i18n)(result);
}
const { data } = result;
logger.trace("withdrawal status", data);
- if (data.aborted) {
+ if (data.aborted || data.confirmation_done) {
// signal that this withdrawal is aborted
// will redirect to account info
+ notifyInfo(i18n.str`Operation was completed from other session`);
onAborted();
return <Loading />;
}
- const parsedUri = parseWithdrawUri(talerWithdrawUri);
- if (!parsedUri) {
- onError({
- title: i18n.str`The Withdrawal URI is not valid: "${talerWithdrawUri}"`,
- });
- return <Loading />;
- }
-
if (!data.selection_done) {
return (
<QrCodeSection
- talerWithdrawUri={talerWithdrawUri}
- onAborted={onAborted}
+ withdrawUri={withdrawUri}
+ onAborted={() => {
+ notifyInfo(i18n.str`Operation canceled`);
+ onAborted();
+ }}
/>
);
}
@@ -90,10 +98,15 @@ export function WithdrawalQRCode({
// user to authorize the operation (here CAPTCHA).
return (
<WithdrawalConfirmationQuestion
- withdrawalId={parsedUri.withdrawalOperationId}
- onError={onError}
- onConfirmed={onConfirmed}
- onAborted={onAborted}
+ withdrawUri={withdrawUri}
+ onConfirmed={() => {
+ notifyInfo(i18n.str`Operation confirmed`);
+ onConfirmed();
+ }}
+ onAborted={() => {
+ notifyInfo(i18n.str`Operation canceled`);
+ onAborted();
+ }}
/>
);
}