From e4f3acfeb2ae6a24c579e7ba8d89625f398d2ee6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 10 Sep 2022 23:21:44 -0300 Subject: fix #7343 --- .../src/cta/Payment/views.tsx | 140 +++++++++++---------- 1 file changed, 74 insertions(+), 66 deletions(-) (limited to 'packages/taler-wallet-webextension/src/cta/Payment/views.tsx') diff --git a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx index c43745909..c799607ad 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx @@ -16,9 +16,12 @@ import { AbsoluteTime, + AmountJson, Amounts, ConfirmPayResultType, ContractTerms, + PreparePayResult, + PreparePayResultPaymentPossible, PreparePayResultType, Product, } from "@gnu-taler/taler-util"; @@ -42,6 +45,7 @@ import { import { Time } from "../../components/Time.js"; import { useTranslationContext } from "../../context/translation.js"; import { Button } from "../../mui/Button.js"; +import { ButtonHandler } from "../../mui/handlers.js"; import { MerchantDetails, PurchaseDetails } from "../../wallet/Transaction.js"; import { State } from "./index.js"; @@ -164,7 +168,11 @@ export function BaseView(state: SupportedStates): VNode { )}
@@ -276,9 +284,9 @@ function ShowImportantMessage({ state }: { state: SupportedStates }): VNode { } if (state.status == "completed") { - const { payResult, payHandler } = state; - if (payHandler.error) { - return ; + const { payResult, paymentError } = state; + if (paymentError) { + return ; } if (payResult.type === ConfirmPayResultType.Done) { return ( @@ -307,15 +315,11 @@ function ShowImportantMessage({ state }: { state: SupportedStates }): VNode { return ; } -function PayWithMobile({ state }: { state: SupportedStates }): VNode { +export function PayWithMobile({ uri }: { uri: string }): VNode { const { i18n } = useTranslationContext(); const [showQR, setShowQR] = useState(false); - const privateUri = - state.payStatus.status !== PreparePayResultType.AlreadyConfirmed - ? `${state.uri}&n=${state.payStatus.noncePriv}` - : state.uri; return (
setShowQR((qr) => !qr)}> @@ -327,10 +331,10 @@ function PayWithMobile({ state }: { state: SupportedStates }): VNode { {showQR && (
- + Scan the QR code or   - + click here @@ -340,50 +344,60 @@ function PayWithMobile({ state }: { state: SupportedStates }): VNode { ); } -function ButtonsSection({ - state, - goToWalletManualWithdraw, -}: { - state: SupportedStates; +interface ButtonSectionProps { + payStatus: PreparePayResult; + payHandler: ButtonHandler | undefined; + balance: AmountJson | undefined; + uri: string; + amount: AmountJson; goToWalletManualWithdraw: (currency: string) => Promise; -}): VNode { +} + +export function ButtonsSection({ + payStatus, + uri, + payHandler, + balance, + amount, + goToWalletManualWithdraw, +}: ButtonSectionProps): VNode { const { i18n } = useTranslationContext(); - if (state.status === "ready") { + if (payStatus.status === PreparePayResultType.PaymentPossible) { + const privateUri = `${uri}&n=${payStatus.noncePriv}`; + return (
- +
); } - if ( - state.status === "no-enough-balance" || - state.status === "no-balance-for-currency" - ) { - // if (state.payStatus.status === PreparePayResultType.InsufficientBalance) { + + if (payStatus.status === PreparePayResultType.InsufficientBalance) { let BalanceMessage = ""; - if (!state.balance) { + if (!balance) { BalanceMessage = i18n.str`You have no balance for this currency. Withdraw digital cash first.`; } else { - const balanceShouldBeEnough = - Amounts.cmp(state.balance, state.amount) !== -1; + const balanceShouldBeEnough = Amounts.cmp(balance, amount) !== -1; if (balanceShouldBeEnough) { - BalanceMessage = i18n.str`Could not find enough coins to pay this order. Even if you have enough ${state.balance.currency} some restriction may apply.`; + BalanceMessage = i18n.str`Could not find enough coins to pay. Even if you have enough ${balance.currency} some restriction may apply.`; } else { - BalanceMessage = i18n.str`Your current balance is not enough for this order.`; + BalanceMessage = i18n.str`Your current balance is not enough.`; } } + const uriPrivate = `${uri}&n=${payStatus.noncePriv}`; + return (
@@ -393,51 +407,45 @@ function ButtonsSection({
- +
); - // } - } - if (state.status === "confirmed") { - if (state.payStatus.status === PreparePayResultType.AlreadyConfirmed) { - return ( - -
- {state.payStatus.paid && - state.payStatus.contractTerms.fulfillment_message && ( - Merchant message} - text={state.payStatus.contractTerms.fulfillment_message} - kind="neutral" - /> - )} -
- {!state.payStatus.paid && } -
- ); - } } - - if (state.status === "completed") { - if (state.payResult.type === ConfirmPayResultType.Pending) { - return ( + if (payStatus.status === PreparePayResultType.AlreadyConfirmed) { + return ( +
-
-

- Processing... -

-
+ {payStatus.paid && payStatus.contractTerms.fulfillment_message && ( + Merchant message} + text={payStatus.contractTerms.fulfillment_message} + kind="neutral" + /> + )}
- ); - } + {!payStatus.paid && } +
+ ); } + // if (state.status === "completed") { + // if (state.payResult.type === ConfirmPayResultType.Pending) { + // return ( + //
+ //
+ //

+ // Processing... + //

+ //
+ //
+ // ); + // } + // } + return ; } -- cgit v1.2.3