From 7a600514c6d43bbaeba6b962533415e59fc46057 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 8 Aug 2022 14:09:28 -0300 Subject: fixing #6096 merchant details and contract terms details factored out, to be used by other components tests and stories updated payment completed != confirmed (confirmed if paid by someone else) --- .../src/cta/Payment/index.ts | 16 +- .../src/cta/Payment/state.ts | 71 ++++---- .../src/cta/Payment/stories.tsx | 175 +++++++++++++------- .../src/cta/Payment/test.ts | 24 +-- .../src/cta/Payment/views.tsx | 178 +++++++++++++-------- 5 files changed, 292 insertions(+), 172 deletions(-) (limited to 'packages/taler-wallet-webextension/src/cta/Payment') diff --git a/packages/taler-wallet-webextension/src/cta/Payment/index.ts b/packages/taler-wallet-webextension/src/cta/Payment/index.ts index 0e67a4991..5c0f6f0d6 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/index.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { AmountJson, ConfirmPayResult, PreparePayResult } from "@gnu-taler/taler-util"; +import { AmountJson, ConfirmPayResult, PreparePayResult, PreparePayResultAlreadyConfirmed, PreparePayResultInsufficientBalance, PreparePayResultPaymentPossible } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; import { ButtonHandler } from "../../mui/handlers.js"; @@ -37,6 +37,7 @@ export type State = | State.Ready | State.NoEnoughBalance | State.NoBalanceForCurrency + | State.Completed | State.Confirmed; export namespace State { @@ -52,8 +53,6 @@ export namespace State { interface BaseInfo { amount: AmountJson; - totalFees: AmountJson; - payStatus: PreparePayResult; uri: string; error: undefined; goToWalletManualWithdraw: (currency?: string) => Promise; @@ -61,20 +60,30 @@ export namespace State { } export interface NoBalanceForCurrency extends BaseInfo { status: "no-balance-for-currency" + payStatus: PreparePayResult; balance: undefined; } export interface NoEnoughBalance extends BaseInfo { status: "no-enough-balance" + payStatus: PreparePayResult; balance: AmountJson; } export interface Ready extends BaseInfo { status: "ready"; + payStatus: PreparePayResultPaymentPossible; payHandler: ButtonHandler; balance: AmountJson; } export interface Confirmed extends BaseInfo { status: "confirmed"; + payStatus: PreparePayResultAlreadyConfirmed; + balance: AmountJson; + } + + export interface Completed extends BaseInfo { + status: "completed"; + payStatus: PreparePayResult; payResult: ConfirmPayResult; payHandler: ButtonHandler; balance: AmountJson; @@ -87,6 +96,7 @@ const viewMapping: StateViewMap = { "no-balance-for-currency": BaseView, "no-enough-balance": BaseView, confirmed: BaseView, + completed: 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 3c819ec8f..f75cef06f 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/state.ts @@ -78,20 +78,9 @@ export function useComponentState( (b) => Amounts.parseOrThrow(b.available).currency === amount.currency, ); - - let totalFees = Amounts.getZero(amount.currency); - if (payStatus.status === PreparePayResultType.PaymentPossible) { - const amountEffective: AmountJson = Amounts.parseOrThrow( - payStatus.amountEffective, - ); - totalFees = Amounts.sub(amountEffective, amount).amount; - } - const baseResult = { uri: hook.response.uri, amount, - totalFees, - payStatus, error: undefined, goBack, goToWalletManualWithdraw } @@ -100,12 +89,45 @@ export function useComponentState( return { status: "no-balance-for-currency", balance: undefined, + payStatus, ...baseResult, } } const foundAmount = Amounts.parseOrThrow(foundBalance.available); + if (payResult) { + return { + status: "completed", + balance: foundAmount, + payStatus, + payHandler: { + error: payErrMsg, + }, + payResult, + ...baseResult, + }; + } + + if (payStatus.status === PreparePayResultType.InsufficientBalance) { + return { + status: 'no-enough-balance', + balance: foundAmount, + payStatus, + ...baseResult, + } + } + + if (payStatus.status === PreparePayResultType.AlreadyConfirmed) { + return { + status: "confirmed", + balance: foundAmount, + payStatus, + ...baseResult, + }; + } + + async function doPayment(): Promise { try { if (payStatus.status !== "payment-possible") { @@ -138,34 +160,19 @@ export function useComponentState( } } - if (payStatus.status === PreparePayResultType.InsufficientBalance) { - return { - status: 'no-enough-balance', - balance: foundAmount, - ...baseResult, - } - } - const payHandler: ButtonHandler = { onClick: payErrMsg ? undefined : doPayment, error: payErrMsg, }; - if (!payResult) { - return { - status: "ready", - payHandler, - ...baseResult, - balance: foundAmount - }; - } - + // (payStatus.status === PreparePayResultType.PaymentPossible) return { - status: "confirmed", - balance: foundAmount, - payResult, - payHandler: {}, + status: "ready", + payHandler, + payStatus, ...baseResult, + balance: foundAmount }; + } diff --git a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx index 603a9cb33..877c1996a 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx @@ -21,11 +21,14 @@ import { Amounts, + ConfirmPayResultType, ContractTerms, PreparePayResultType, } from "@gnu-taler/taler-util"; +import merchantIcon from "../../../static-dev/merchant-icon.jpeg"; import { createExample } from "../../test-utils.js"; import { BaseView } from "./views.js"; +import beer from "../../../static-dev/beer.png"; export default { title: "cta/payment", @@ -34,25 +37,22 @@ export default { }; export const NoBalance = createExample(BaseView, { - status: "ready", + status: "no-balance-for-currency", error: undefined, amount: Amounts.parseOrThrow("USD:10"), balance: undefined, - payHandler: { - onClick: async () => { - null; - }, - }, - totalFees: Amounts.parseOrThrow("USD:0"), uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, noncePriv: "", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, summary: "some beers", amount: "USD:10", @@ -62,7 +62,7 @@ export const NoBalance = createExample(BaseView, { }); export const NoEnoughBalance = createExample(BaseView, { - status: "ready", + status: "no-enough-balance", error: undefined, amount: Amounts.parseOrThrow("USD:10"), balance: { @@ -70,21 +70,18 @@ export const NoEnoughBalance = createExample(BaseView, { fraction: 40000000, value: 9, }, - payHandler: { - onClick: async () => { - null; - }, - }, - totalFees: Amounts.parseOrThrow("USD:0"), uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, noncePriv: "", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, summary: "some beers", amount: "USD:10", @@ -94,7 +91,7 @@ export const NoEnoughBalance = createExample(BaseView, { }); export const EnoughBalanceButRestricted = createExample(BaseView, { - status: "ready", + status: "no-enough-balance", error: undefined, amount: Amounts.parseOrThrow("USD:10"), balance: { @@ -102,21 +99,18 @@ export const EnoughBalanceButRestricted = createExample(BaseView, { fraction: 40000000, value: 19, }, - payHandler: { - onClick: async () => { - null; - }, - }, - totalFees: Amounts.parseOrThrow("USD:0"), uri: "", payStatus: { status: PreparePayResultType.InsufficientBalance, noncePriv: "", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", contractTerms: { merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, summary: "some beers", amount: "USD:10", @@ -139,7 +133,6 @@ export const PaymentPossible = createExample(BaseView, { null; }, }, - totalFees: Amounts.parseOrThrow("USD:0"), uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { @@ -150,13 +143,19 @@ export const PaymentPossible = createExample(BaseView, { contractTerms: { nonce: "123213123", merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", + }, + pay_deadline: { + t_s: new Date().getTime() / 1000 + 60 * 60 * 3, }, amount: "USD:10", summary: "some beers", } as Partial as any, contractTermsHash: "123456", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", }, }); @@ -174,7 +173,6 @@ export const PaymentPossibleWithFee = createExample(BaseView, { null; }, }, - totalFees: Amounts.parseOrThrow("USD:0.20"), uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { @@ -185,18 +183,19 @@ export const PaymentPossibleWithFee = createExample(BaseView, { contractTerms: { nonce: "123213123", merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, amount: "USD:10", summary: "some beers", } as Partial as any, contractTermsHash: "123456", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", }, }); -import beer from "../../../static-dev/beer.png"; - export const TicketWithAProductList = createExample(BaseView, { status: "ready", error: undefined, @@ -211,7 +210,6 @@ export const TicketWithAProductList = createExample(BaseView, { null; }, }, - totalFees: Amounts.parseOrThrow("USD:0.20"), uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { @@ -222,7 +220,10 @@ export const TicketWithAProductList = createExample(BaseView, { contractTerms: { nonce: "123213123", merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, amount: "USD:10", summary: "some beers", @@ -247,11 +248,11 @@ export const TicketWithAProductList = createExample(BaseView, { ], } as Partial as any, contractTermsHash: "123456", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", }, }); -export const AlreadyConfirmedByOther = createExample(BaseView, { +export const TicketWithShipping = createExample(BaseView, { status: "ready", error: undefined, amount: Amounts.parseOrThrow("USD:10"), @@ -265,7 +266,52 @@ export const AlreadyConfirmedByOther = createExample(BaseView, { null; }, }, - totalFees: Amounts.parseOrThrow("USD:0.20"), + + uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", + payStatus: { + status: PreparePayResultType.PaymentPossible, + amountEffective: "USD:10.20", + amountRaw: "USD:10", + noncePriv: "", + contractTerms: { + nonce: "123213123", + merchant: { + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", + }, + amount: "USD:10", + summary: "banana pi set", + products: [ + { + description: "banana pi", + price: "USD:2", + quantity: 1, + }, + ], + delivery_date: { + t_s: new Date().getTime() / 1000 + 30 * 24 * 60 * 60, + }, + delivery_location: { + town: "Liverpool", + street: "Down st 1234", + }, + } as Partial as any, + contractTermsHash: "123456", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", + }, +}); + +export const AlreadyConfirmedByOther = createExample(BaseView, { + status: "confirmed", + error: undefined, + amount: Amounts.parseOrThrow("USD:10"), + balance: { + currency: "USD", + fraction: 40000000, + value: 11, + }, uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", payStatus: { @@ -274,19 +320,22 @@ export const AlreadyConfirmedByOther = createExample(BaseView, { amountRaw: "USD:10", contractTerms: { merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, summary: "some beers", amount: "USD:10", } as Partial as any, contractTermsHash: "123456", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", paid: false, }, }); export const AlreadyPaidWithoutFulfillment = createExample(BaseView, { - status: "ready", + status: "completed", error: undefined, amount: Amounts.parseOrThrow("USD:10"), balance: { @@ -294,33 +343,34 @@ export const AlreadyPaidWithoutFulfillment = createExample(BaseView, { fraction: 40000000, value: 11, }, - payHandler: { - onClick: async () => { - null; - }, - }, - totalFees: Amounts.parseOrThrow("USD:0.20"), uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", + payResult: { + type: ConfirmPayResultType.Done, + contractTerms: {} as any, + }, payStatus: { status: PreparePayResultType.AlreadyConfirmed, amountEffective: "USD:10", amountRaw: "USD:10", contractTerms: { merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, summary: "some beers", amount: "USD:10", } as Partial as any, contractTermsHash: "123456", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", paid: true, }, }); export const AlreadyPaidWithFulfillment = createExample(BaseView, { - status: "ready", + status: "completed", error: undefined, amount: Amounts.parseOrThrow("USD:10"), balance: { @@ -328,29 +378,34 @@ export const AlreadyPaidWithFulfillment = createExample(BaseView, { fraction: 40000000, value: 11, }, - payHandler: { - onClick: async () => { - null; - }, - }, - totalFees: Amounts.parseOrThrow("USD:0.20"), uri: "taler://pay/merchant-backend.taler/2021.242-01G2X4275RBWG/?c=66BE594PDZR24744J6EQK52XM0", + payResult: { + type: ConfirmPayResultType.Done, + contractTerms: { + fulfillment_message: "thanks for buying!", + fulfillment_url: "https://demo.taler.net", + } as Partial as any, + }, payStatus: { status: PreparePayResultType.AlreadyConfirmed, amountEffective: "USD:10", amountRaw: "USD:10", contractTerms: { merchant: { - name: "someone", + name: "the merchant", + logo: merchantIcon, + website: "https://www.themerchant.taler", + email: "contact@merchant.taler", }, + fulfillment_url: "https://demo.taler.net", fulfillment_message: "congratulations! you are looking at the fulfillment message! ", summary: "some beers", amount: "USD:10", } as Partial as any, contractTermsHash: "123456", - proposalId: "proposal1234", + proposalId: "96YY92RQZGF3V7TJSPN4SF9549QX7BRF88Q5PYFCSBNQ0YK4RPK0", paid: true, }, }); diff --git a/packages/taler-wallet-webextension/src/cta/Payment/test.ts b/packages/taler-wallet-webextension/src/cta/Payment/test.ts index aea70b7ca..afd881a72 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/test.ts @@ -204,7 +204,7 @@ describe("Payment CTA states", () => { if (r.status !== "ready") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:10")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:0")); + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:0")); expect(r.payHandler.onClick).not.undefined; } @@ -246,7 +246,7 @@ describe("Payment CTA states", () => { if (r.status !== "ready") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).not.undefined; } @@ -293,7 +293,7 @@ describe("Payment CTA states", () => { if (r.status !== "ready") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); if (r.payHandler.onClick === undefined) expect.fail(); r.payHandler.onClick(); } @@ -302,13 +302,13 @@ describe("Payment CTA states", () => { { const r = getLastResultOrThrow(); - if (r.status !== "confirmed") expect.fail(); + if (r.status !== "completed") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); - if (r.payResult.type !== ConfirmPayResultType.Done) expect.fail(); - expect(r.payResult.contractTerms).not.undefined; - expect(r.payHandler.onClick).undefined; + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); + // if (r.payResult.type !== ConfirmPayResultType.Done) expect.fail(); + // expect(r.payResult.contractTerms).not.undefined; + // expect(r.payHandler.onClick).undefined; } await assertNoPendingUpdate(); @@ -354,7 +354,7 @@ describe("Payment CTA states", () => { if (r.status !== "ready") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); if (r.payHandler.onClick === undefined) expect.fail(); r.payHandler.onClick(); } @@ -366,7 +366,7 @@ describe("Payment CTA states", () => { if (r.status !== "ready") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).undefined; if (r.payHandler.error === undefined) expect.fail(); //FIXME: error message here is bad @@ -425,7 +425,7 @@ describe("Payment CTA states", () => { if (r.status !== "ready") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:10")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).not.undefined; notifyCoinWithdrawn(Amounts.parseOrThrow("USD:5")); @@ -438,7 +438,7 @@ describe("Payment CTA states", () => { if (r.status !== "ready") expect.fail(); expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); - expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); + // expect(r.totalFees).deep.equal(Amounts.parseOrThrow("USD:1")); expect(r.payHandler.onClick).not.undefined; } diff --git a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx index a8c9a640a..4c2ddc0f2 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx @@ -15,6 +15,7 @@ */ import { + AbsoluteTime, Amounts, ConfirmPayResultType, ContractTerms, @@ -38,8 +39,10 @@ import { WalletAction, WarningBox, } from "../../components/styled/index.js"; +import { Time } from "../../components/Time.js"; import { useTranslationContext } from "../../context/translation.js"; import { Button } from "../../mui/Button.js"; +import { MerchantDetails, PurchaseDetails } from "../../wallet/Transaction.js"; import { State } from "./index.js"; export function LoadingUriView({ error }: State.LoadingUriError): VNode { @@ -56,6 +59,7 @@ export function LoadingUriView({ error }: State.LoadingUriError): VNode { type SupportedStates = | State.Ready | State.Confirmed + | State.Completed | State.NoBalanceForCurrency | State.NoEnoughBalance; @@ -63,6 +67,15 @@ export function BaseView(state: SupportedStates): VNode { const { i18n } = useTranslationContext(); const contractTerms: ContractTerms = state.payStatus.contractTerms; + const price = { + raw: state.amount, + effective: + "amountEffective" in state.payStatus + ? Amounts.parseOrThrow(state.payStatus.amountEffective) + : state.amount, + }; + const totalFees = Amounts.sub(price.effective, price.raw).amount; + return ( @@ -73,9 +86,9 @@ export function BaseView(state: SupportedStates): VNode { -
- {state.payStatus.status !== PreparePayResultType.InsufficientBalance && - Amounts.isNonZero(state.totalFees) && ( +
+ {/* {state.payStatus.status !== PreparePayResultType.InsufficientBalance && + Amounts.isNonZero(totalFees) && ( Total to pay} @@ -89,24 +102,43 @@ export function BaseView(state: SupportedStates): VNode { text={} kind="neutral" /> - {Amounts.isNonZero(state.totalFees) && ( + {Amounts.isNonZero(totalFees) && ( Fee} - text={} + text={} kind="negative" /> - )} + )} */} + Purchase} + text={contractTerms.summary} + kind="neutral" + /> Merchant} - text={contractTerms.merchant.name} + text={} kind="neutral" /> + {/*
{JSON.stringify(price)}
+
+
{JSON.stringify(state.payStatus, undefined, 2)}
*/} Purchase} - text={contractTerms.summary} + title={Details} + text={ + + } kind="neutral" /> {contractTerms.order_id && ( @@ -116,8 +148,19 @@ export function BaseView(state: SupportedStates): VNode { kind="neutral" /> )} - {contractTerms.products && contractTerms.products.length > 0 && ( - + {contractTerms.pay_deadline && ( + Valid until} + text={ +
; @@ -264,7 +307,7 @@ function ShowImportantMessage({ state }: { state: SupportedStates }): VNode { return ; } -function PayWithMobile({ state }: { state: State.Ready }): VNode { +function PayWithMobile({ state }: { state: SupportedStates }): VNode { const { i18n } = useTranslationContext(); const [showQR, setShowQR] = useState(false); @@ -286,7 +329,7 @@ function PayWithMobile({ state }: { state: State.Ready }): VNode {
- Scan the QR code or + Scan the QR code or   click here @@ -306,61 +349,66 @@ function ButtonsSection({ }): VNode { const { i18n } = useTranslationContext(); if (state.status === "ready") { - const { payStatus } = state; - if (payStatus.status === PreparePayResultType.PaymentPossible) { - return ( - -
- -
- -
- ); - } - if (payStatus.status === PreparePayResultType.InsufficientBalance) { - let BalanceMessage = ""; - if (!state.balance) { - BalanceMessage = i18n.str`You have no balance for this currency. Withdraw digital cash first.`; + return ( + +
+ +
+ +
+ ); + } + if ( + state.status === "no-enough-balance" || + state.status === "no-balance-for-currency" + ) { + // if (state.payStatus.status === PreparePayResultType.InsufficientBalance) { + let BalanceMessage = ""; + if (!state.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; + 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.`; } else { - const balanceShouldBeEnough = - Amounts.cmp(state.balance, state.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.`; - } else { - BalanceMessage = i18n.str`Your current balance is not enough for this order.`; - } + BalanceMessage = i18n.str`Your current balance is not enough for this order.`; } - return ( - -
- {BalanceMessage} -
-
- -
- -
- ); } - if (payStatus.status === PreparePayResultType.AlreadyConfirmed) { + return ( + +
+ {BalanceMessage} +
+
+ +
+ +
+ ); + // } + } + if (state.status === "confirmed") { + if (state.payStatus.status === PreparePayResultType.AlreadyConfirmed) { return (
- {payStatus.paid && + {state.payStatus.paid && state.payStatus.contractTerms.fulfillment_message && ( Merchant message} @@ -369,13 +417,13 @@ function ButtonsSection({ /> )}
- {!payStatus.paid && } + {!state.payStatus.paid && }
); } } - if (state.status === "confirmed") { + if (state.status === "completed") { if (state.payResult.type === ConfirmPayResultType.Pending) { return (
-- cgit v1.2.3