From 545bf16cdfa824778c1450e64eaea236b9d81c49 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 3 Jul 2023 12:43:47 -0300 Subject: [PATCH] fix #7741 show QR with nonce --- .../src/components/PaymentButtons.tsx | 36 +++++++++++++------ .../src/cta/InvoicePay/state.ts | 1 - .../src/cta/Payment/stories.tsx | 20 +++++------ .../src/cta/Payment/views.tsx | 4 ++- 4 files changed, 39 insertions(+), 22 deletions(-) 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 diff --git a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts index c6512cd12..098f18921 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts @@ -102,7 +102,6 @@ export function useComponentState({ contractTermsHash: "asd", amountRaw: hook.response.p2p.amount, amountEffective: hook.response.p2p.amount, - noncePriv: "", } as PreparePayResult; const insufficientBalance: PreparePayResult = { diff --git a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx index 6572d1fd3..f030fa219 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx @@ -61,7 +61,7 @@ export const NoEnoughBalanceAvailable = tests.createExample(BaseView, { feeGapEstimate: "USD:1", }, talerUri: "taler://pay/..", - noncePriv: "", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { @@ -101,7 +101,7 @@ export const NoEnoughBalanceMaterial = tests.createExample(BaseView, { feeGapEstimate: "USD:1", }, talerUri: "taler://pay/..", - noncePriv: "", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { @@ -141,7 +141,7 @@ export const NoEnoughBalanceAgeAcceptable = tests.createExample(BaseView, { feeGapEstimate: "USD:1", }, talerUri: "taler://pay/..", - noncePriv: "", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { @@ -182,7 +182,7 @@ export const NoEnoughBalanceMerchantAcceptable = tests.createExample(BaseView, { feeGapEstimate: "USD:1", }, talerUri: "taler://pay/..", - noncePriv: "", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { @@ -224,7 +224,7 @@ export const NoEnoughBalanceMerchantDepositable = tests.createExample( feeGapEstimate: "USD:1", }, talerUri: "taler://pay/..", - noncePriv: "", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { @@ -265,7 +265,7 @@ export const NoEnoughBalanceFeeGap = tests.createExample(BaseView, { feeGapEstimate: "USD:1", }, talerUri: "taler://pay/..", - noncePriv: "", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { @@ -302,7 +302,7 @@ export const PaymentPossible = tests.createExample(BaseView, { talerUri: "taler://pay/..", amountEffective: "USD:10", amountRaw: "USD:10", - noncePriv: "", + contractTerms: { nonce: "123213123", merchant: { @@ -342,7 +342,7 @@ export const PaymentPossibleWithFee = tests.createExample(BaseView, { talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", - noncePriv: "", + contractTerms: { nonce: "123213123", merchant: { @@ -379,7 +379,7 @@ export const TicketWithAProductList = tests.createExample(BaseView, { talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", - noncePriv: "", + contractTerms: { nonce: "123213123", merchant: { @@ -435,7 +435,7 @@ export const TicketWithShipping = tests.createExample(BaseView, { talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", - noncePriv: "", + contractTerms: { nonce: "123213123", merchant: { diff --git a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx index b0911cb2f..0bdadef0e 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx @@ -47,7 +47,9 @@ export function BaseView(state: SupportedStates): VNode { const effective = "amountEffective" in state.payStatus - ? Amounts.parseOrThrow(state.payStatus.amountEffective) + ? state.payStatus.amountEffective + ? Amounts.parseOrThrow(state.payStatus.amountEffective) + : Amounts.zeroOfCurrency(state.amount.currency) : state.amount; return (