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/wallet/History.tsx | 6 +- .../src/wallet/Transaction.stories.tsx | 8 +- .../src/wallet/Transaction.tsx | 174 +++++++++++---------- 3 files changed, 107 insertions(+), 81 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet') diff --git a/packages/taler-wallet-webextension/src/wallet/History.tsx b/packages/taler-wallet-webextension/src/wallet/History.tsx index c192b2ba7..e40c1ac5b 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.tsx @@ -143,7 +143,11 @@ export function HistoryView({ if (balances.length === 0 || !selectedCurrency) { return ( - + ); } return ( diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx index ae43a7b09..ba61e35f3 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx @@ -114,6 +114,12 @@ const exampleData = { tip: { ...commonTransaction, type: TransactionType.Tip, + // merchant: { + // name: "the merchant", + // logo: merchantIcon, + // website: "https://www.themerchant.taler", + // email: "contact@merchant.taler", + // }, merchantBaseUrl: "http://merchant.taler", } as TransactionTip, refund: { @@ -429,7 +435,7 @@ export const DepositBitcoin = createExample(TestedComponent, { transaction: { ...exampleData.deposit, amountRaw: "BITCOINBTC:0.0000011", - amountEffective: "BITCOINBTC:0.00000092", + amountEffective: "BITCOINBTC:0.00000092", targetPaytoUri: "payto://bitcoin/bcrt1q6ps8qs6v8tkqrnru4xqqqa6rfwcx5ufpdfqht4?amount=BTC:0.1&subject=0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00", }, diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index c42bf7066..e643fef18 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -16,18 +16,18 @@ import { AbsoluteTime, - amountFractionalLength, AmountJson, Amounts, Location, + MerchantInfo, NotificationType, + OrderShortInfo, parsePaytoUri, PaytoUri, stringifyPaytoUri, TalerProtocolTimestamp, Transaction, TransactionDeposit, - TransactionPayment, TransactionRefresh, TransactionRefund, TransactionTip, @@ -46,6 +46,7 @@ import { ErrorTalerOperation } from "../components/ErrorTalerOperation.js"; import { Loading } from "../components/Loading.js"; import { LoadingError } from "../components/LoadingError.js"; import { Kind, Part, PartCollapsible, PartPayto } from "../components/Part.js"; +import { ShowFullContractTermPopup } from "../components/ShowFullContractTermPopup.js"; import { CenteredDialog, InfoBox, @@ -319,10 +320,15 @@ export function TransactionView({ ? undefined : Amounts.parseOrThrow(transaction.refundPending); - const total = Amounts.sub( - Amounts.parseOrThrow(transaction.amountEffective), - Amounts.parseOrThrow(transaction.totalRefundEffective), - ).amount; + const price = { + raw: Amounts.parseOrThrow(transaction.amountRaw), + effective: Amounts.parseOrThrow(transaction.amountEffective), + }; + const refund = { + raw: Amounts.parseOrThrow(transaction.totalRefundRaw), + effective: Amounts.parseOrThrow(transaction.totalRefundEffective), + }; + const total = Amounts.sub(price.effective, refund.effective).amount; return ( @@ -404,45 +410,7 @@ export function TransactionView({ )} Merchant} - text={ - -
- {transaction.info.merchant.logo && ( -
- -
- )} -
-

{transaction.info.merchant.name}

- {transaction.info.merchant.website && ( - - - {transaction.info.merchant.website} - - - )} - {transaction.info.merchant.email && ( - - - {transaction.info.merchant.email} - - - )} -
-
-
- } + text={} kind="neutral" /> Details} - text={} + text={ + + } kind="neutral" />
@@ -521,12 +496,7 @@ export function TransactionView({ {/* Merchant} - text={transaction.info.merchant.name} - kind="neutral" - /> - Invoice ID} - text={transaction.info.orderId} + text={} kind="neutral" /> */} ; } +export function MerchantDetails({ + merchant, +}: { + merchant: MerchantInfo; +}): VNode { + return ( +
+ {merchant.logo && ( +
+ +
+ )} +
+

{merchant.name}

+ {merchant.website && ( + + {merchant.website} + + )} + {merchant.email && ( + + {merchant.email} + + )} +
+
+ ); +} + function DeliveryDetails({ date, location, @@ -703,57 +713,58 @@ function DeliveryDetails({ ); } -function PurchaseDetails({ - transaction, +export interface AmountWithFee { + effective: AmountJson; + raw: AmountJson; +} +export function PurchaseDetails({ + price, + refund, + info, + proposalId, }: { - transaction: TransactionPayment; + price: AmountWithFee; + refund?: AmountWithFee; + info: OrderShortInfo; + proposalId: string; }): VNode { const { i18n } = useTranslationContext(); - const partialFee = Amounts.sub( - Amounts.parseOrThrow(transaction.amountEffective), - Amounts.parseOrThrow(transaction.amountRaw), - ).amount; + const partialFee = Amounts.sub(price.effective, price.raw).amount; - const refundRaw = Amounts.parseOrThrow(transaction.totalRefundRaw); - - const refundFee = Amounts.sub( - refundRaw, - Amounts.parseOrThrow(transaction.totalRefundEffective), - ).amount; + const refundFee = !refund + ? Amounts.getZero(price.effective.currency) + : Amounts.sub(refund.raw, refund.effective).amount; const fee = Amounts.sum([partialFee, refundFee]).amount; - const hasProducts = - transaction.info.products && transaction.info.products.length > 0; + const hasProducts = info.products && info.products.length > 0; const hasShipping = - transaction.info.delivery_date !== undefined || - transaction.info.delivery_location !== undefined; + info.delivery_date !== undefined || info.delivery_location !== undefined; const showLargePic = (): void => { return; }; - const total = Amounts.sub( - Amounts.parseOrThrow(transaction.amountEffective), - Amounts.parseOrThrow(transaction.totalRefundEffective), - ).amount; + const total = !refund + ? price.effective + : Amounts.sub(price.effective, refund.effective).amount; return ( Price - + - {Amounts.isNonZero(refundRaw) && ( + {refund && Amounts.isNonZero(refund.raw) && ( Refunded - + )} @@ -784,7 +795,7 @@ function PurchaseDetails({ title={Products} text={ - {transaction.info.products?.map((p, k) => ( + {info.products?.map((p, k) => ( @@ -813,14 +824,19 @@ function PurchaseDetails({ title={Delivery} text={ } /> )} + + + + + ); } -- cgit v1.2.3