diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Payment')
4 files changed, 52 insertions, 6 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Payment/index.ts b/packages/taler-wallet-webextension/src/cta/Payment/index.ts index f0270b96c..80822b381 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/index.ts @@ -18,6 +18,7 @@ import { AmountJson, PreparePayResult, PreparePayResultAlreadyConfirmed, + PreparePayResultInsufficientBalance, PreparePayResultPaymentPossible, } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; @@ -26,7 +27,7 @@ import { ButtonHandler } from "../../mui/handlers.js"; import { compose, StateViewMap } from "../../utils/index.js"; import { wxApi } from "../../wxApi.js"; import { useComponentState } from "./state.js"; -import { BaseView, LoadingUriView } from "./views.js"; +import { BaseView, LoadingUriView, LostView } from "./views.js"; export interface Props { talerPayUri?: string; @@ -40,6 +41,7 @@ export type State = | State.LoadingUriError | State.Ready | State.NoEnoughBalance + | State.Lost | State.NoBalanceForCurrency | State.Confirmed; @@ -62,12 +64,15 @@ export namespace State { } export interface NoBalanceForCurrency extends BaseInfo { status: "no-balance-for-currency"; - payStatus: PreparePayResult; + payStatus: + | PreparePayResultInsufficientBalance + | PreparePayResultPaymentPossible + | PreparePayResultAlreadyConfirmed; balance: undefined; } export interface NoEnoughBalance extends BaseInfo { status: "no-enough-balance"; - payStatus: PreparePayResult; + payStatus: PreparePayResultInsufficientBalance; balance: AmountJson; } export interface Ready extends BaseInfo { @@ -77,6 +82,11 @@ export namespace State { balance: AmountJson; } + export interface Lost { + status: "lost"; + error: undefined; + } + export interface Confirmed extends BaseInfo { status: "confirmed"; payStatus: PreparePayResultAlreadyConfirmed; @@ -89,6 +99,7 @@ const viewMapping: StateViewMap<State> = { "loading-uri": LoadingUriView, "no-balance-for-currency": BaseView, "no-enough-balance": BaseView, + lost: LostView, confirmed: BaseView, ready: BaseView, }; diff --git a/packages/taler-wallet-webextension/src/cta/Payment/state.ts b/packages/taler-wallet-webextension/src/cta/Payment/state.ts index 49d022320..b90b1e495 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/state.ts @@ -82,6 +82,14 @@ export function useComponentState( }; } const { payStatus } = hook.response; + + if (payStatus.status === PreparePayResultType.Lost) { + return { + status: "lost", + error: undefined, + }; + } + const amount = Amounts.parseOrThrow(payStatus.amountRaw); const foundBalance = hook.response.balance.balances.find( diff --git a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx index 7d5a7694e..fd437d5d2 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx @@ -44,6 +44,7 @@ export const NoBalance = createExample(BaseView, { uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, + talerUri: "taler://pay/..", noncePriv: "", proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { @@ -73,6 +74,7 @@ export const NoEnoughBalance = createExample(BaseView, { uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, + talerUri: "taler://pay/..", noncePriv: "", proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { @@ -102,6 +104,7 @@ export const EnoughBalanceButRestricted = createExample(BaseView, { uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, + talerUri: "taler://pay/..", noncePriv: "", proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { @@ -136,6 +139,7 @@ export const PaymentPossible = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10", amountRaw: "USD:10", noncePriv: "", @@ -176,6 +180,7 @@ export const PaymentPossibleWithFee = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", noncePriv: "", @@ -213,6 +218,7 @@ export const TicketWithAProductList = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", noncePriv: "", @@ -269,6 +275,7 @@ export const TicketWithShipping = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.PaymentPossible, + talerUri: "taler://pay/..", amountEffective: "USD:10.20", amountRaw: "USD:10", noncePriv: "", @@ -315,6 +322,7 @@ export const AlreadyConfirmedByOther = createExample(BaseView, { uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { status: PreparePayResultType.AlreadyConfirmed, + talerUri: "taler://pay/..", amountEffective: "USD:10", amountRaw: "USD:10", contractTerms: { diff --git a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx index d9b6eaa02..6b502a87f 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx @@ -26,6 +26,7 @@ import { import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Amount } from "../../components/Amount.js"; +import { ErrorMessage } from "../../components/ErrorMessage.js"; import { LoadingError } from "../../components/LoadingError.js"; import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; @@ -43,6 +44,7 @@ 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 { assertUnreachable } from "../../utils/index.js"; import { MerchantDetails, PurchaseDetails } from "../../wallet/Transaction.js"; import { State } from "./index.js"; @@ -63,8 +65,24 @@ type SupportedStates = | State.NoBalanceForCurrency | State.NoEnoughBalance; +export function LostView(state: State.Lost): VNode { + const { i18n } = useTranslationContext(); + + return ( + <ErrorMessage + title={<i18n.Translate>Could not load pay status</i18n.Translate>} + description={ + <i18n.Translate> + The proposal was lost, another should be downloaded + </i18n.Translate> + } + /> + ); +} + export function BaseView(state: SupportedStates): VNode { const { i18n } = useTranslationContext(); + const contractTerms: ContractTerms = state.payStatus.contractTerms; const price = { @@ -399,8 +417,9 @@ export function ButtonsSection({ </Fragment> ); } + if (payStatus.status === PreparePayResultType.Lost) { + return <Fragment />; + } - const error: never = payStatus; - - return <Fragment />; + assertUnreachable(payStatus); } |