summaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/home/WithdrawalQRCode.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-12-07 16:07:42 -0300
committerSebastian <sebasjm@gmail.com>2022-12-07 16:08:20 -0300
commit46835d5155a561ddf9f3e21bbb81c823c3eab943 (patch)
tree51011d2bae21b66695e3854ed49b9c63f5f35255 /packages/demobank-ui/src/pages/home/WithdrawalQRCode.tsx
parent1c6369677ab272196da314d95825273c6fff8d5f (diff)
downloadwallet-core-46835d5155a561ddf9f3e21bbb81c823c3eab943.tar.gz
wallet-core-46835d5155a561ddf9f3e21bbb81c823c3eab943.tar.bz2
wallet-core-46835d5155a561ddf9f3e21bbb81c823c3eab943.zip
no-fix: user logger instead of console.log
Diffstat (limited to 'packages/demobank-ui/src/pages/home/WithdrawalQRCode.tsx')
-rw-r--r--packages/demobank-ui/src/pages/home/WithdrawalQRCode.tsx104
1 files changed, 104 insertions, 0 deletions
diff --git a/packages/demobank-ui/src/pages/home/WithdrawalQRCode.tsx b/packages/demobank-ui/src/pages/home/WithdrawalQRCode.tsx
new file mode 100644
index 000000000..d5b8794d3
--- /dev/null
+++ b/packages/demobank-ui/src/pages/home/WithdrawalQRCode.tsx
@@ -0,0 +1,104 @@
+import { Logger } from "@gnu-taler/taler-util";
+import { Fragment, h, VNode } from "preact";
+import useSWR from "swr";
+import { PageStateType, usePageContext } from "../../context/pageState.js";
+import { useTranslationContext } from "../../context/translation.js";
+import { QrCodeSection } from "./QrCodeSection.js";
+import { WithdrawalConfirmationQuestion } from "./WithdrawalConfirmationQuestion.js";
+
+const logger = new Logger("WithdrawalQRCode");
+/**
+ * Offer the QR code (and a clickable taler://-link) to
+ * permit the passing of exchange and reserve details to
+ * the bank. Poll the backend until such operation is done.
+ */
+export function WithdrawalQRCode({
+ withdrawalId,
+ talerWithdrawUri,
+}: {
+ withdrawalId: string;
+ talerWithdrawUri: string;
+}): VNode {
+ // turns true when the wallet POSTed the reserve details:
+ const { pageState, pageStateSetter } = usePageContext();
+ const { i18n } = useTranslationContext();
+ const abortButton = (
+ <a
+ class="pure-button btn-cancel"
+ onClick={() => {
+ pageStateSetter((prevState: PageStateType) => {
+ return {
+ ...prevState,
+ withdrawalId: undefined,
+ talerWithdrawUri: undefined,
+ withdrawalInProgress: false,
+ };
+ });
+ }}
+ >{i18n.str`Abort`}</a>
+ );
+
+ logger.trace(`Showing withdraw URI: ${talerWithdrawUri}`);
+ // waiting for the wallet:
+
+ const { data, error } = useSWR(
+ `integration-api/withdrawal-operation/${withdrawalId}`,
+ { refreshInterval: 1000 },
+ );
+
+ if (typeof error !== "undefined") {
+ logger.error(
+ `withdrawal (${withdrawalId}) was never (correctly) created at the bank...`,
+ error,
+ );
+ pageStateSetter((prevState: PageStateType) => ({
+ ...prevState,
+
+ error: {
+ title: i18n.str`withdrawal (${withdrawalId}) was never (correctly) created at the bank...`,
+ },
+ }));
+ return (
+ <Fragment>
+ <br />
+ <br />
+ {abortButton}
+ </Fragment>
+ );
+ }
+
+ // data didn't arrive yet and wallet didn't communicate:
+ if (typeof data === "undefined")
+ return <p>{i18n.str`Waiting the bank to create the operation...`}</p>;
+
+ /**
+ * Wallet didn't communicate withdrawal details yet:
+ */
+ logger.trace("withdrawal status", data);
+ if (data.aborted)
+ pageStateSetter((prevState: PageStateType) => {
+ const { withdrawalId, talerWithdrawUri, ...rest } = prevState;
+ return {
+ ...rest,
+ withdrawalInProgress: false,
+
+ error: {
+ title: i18n.str`This withdrawal was aborted!`,
+ },
+ };
+ });
+
+ if (!data.selection_done) {
+ return (
+ <QrCodeSection
+ talerWithdrawUri={talerWithdrawUri}
+ abortButton={abortButton}
+ />
+ );
+ }
+ /**
+ * Wallet POSTed the withdrawal details! Ask the
+ * user to authorize the operation (here CAPTCHA).
+ */
+ return <WithdrawalConfirmationQuestion />;
+}