From 545bf16cdfa824778c1450e64eaea236b9d81c49 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 3 Jul 2023 12:43:47 -0300 Subject: fix #7741 show QR with nonce --- .../src/components/PaymentButtons.tsx | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'packages/taler-wallet-webextension/src/components/PaymentButtons.tsx') diff --git a/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx b/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx index d85a2c78e..8cb1c49dd 100644 --- a/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx +++ b/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx @@ -21,6 +21,8 @@ import { PreparePayResult, PreparePayResultType, TranslatedString, + parsePayUri, + stringifyPayUri, } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; @@ -32,6 +34,8 @@ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Button } from "../mui/Button.js"; import { ButtonHandler } from "../mui/handlers.js"; import { assertUnreachable } from "../utils/index.js"; +import { useBackendContext } from "../context/backend.js"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; interface Props { payStatus: PreparePayResult; @@ -50,8 +54,6 @@ export function PaymentButtons({ }: Props): VNode { const { i18n } = useTranslationContext(); if (payStatus.status === PreparePayResultType.PaymentPossible) { - const privateUri = `${uri}&n=${payStatus.noncePriv}`; - return (
@@ -66,7 +68,7 @@ export function PaymentButtons({
- +
); } @@ -125,7 +127,6 @@ export function PaymentButtons({ default: assertUnreachable(reason); } - const uriPrivate = `${uri}&n=${payStatus.noncePriv}`; return ( @@ -141,7 +142,7 @@ export function PaymentButtons({ Get digital cash - + ); } @@ -159,7 +160,6 @@ export function PaymentButtons({ /> )} - {!payStatus.paid && } ); } @@ -169,20 +169,36 @@ export function PaymentButtons({ function PayWithMobile({ uri }: { uri: string }): VNode { const { i18n } = useTranslationContext(); + const api = useBackendContext(); - const [showQR, setShowQR] = useState(false); + const payUri = parsePayUri(uri); + const [showQR, setShowQR] = useState(undefined); + async function sharePrivatePaymentURI() { + if (!payUri) { + return; + } + if (!showQR) { + const result = await api.wallet.call(WalletApiOperation.SharePayment, { + merchantBaseUrl: payUri.merchantBaseUrl, + orderId: payUri.orderId, + }); + setShowQR(result.privatePayUri); + } else { + setShowQR(undefined); + } + } return (
- setShowQR((qr) => !qr)}> + {!showQR ? i18n.str`Pay with a mobile phone` : i18n.str`Hide QR`} {showQR && (
- + Scan the QR code or   - + click here -- cgit v1.2.3