From e4ea2019430fb3c4b788f67427fbd743f604b7e5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 14 May 2022 18:09:33 -0300 Subject: feat: awaiting refund --- .../src/wallet/History.stories.tsx | 4 + .../src/wallet/Transaction.stories.tsx | 4 + .../src/wallet/Transaction.tsx | 208 ++++++++++++++------- 3 files changed, 144 insertions(+), 72 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet') diff --git a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx index 92f1dea1b..3080a866e 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx @@ -78,6 +78,9 @@ const exampleData = { summary: "the summary", fulfillmentMessage: "", }, + refundPending: undefined, + totalRefundEffective: "USD:0", + totalRefundRaw: "USD:0", proposalId: "1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0", status: PaymentStatus.Accepted, } as TransactionPayment, @@ -112,6 +115,7 @@ const exampleData = { summary: "the summary", fulfillmentMessage: "", }, + refundPending: undefined, } as TransactionRefund, }; diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx index b4dfb6ce0..f162543ae 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx @@ -83,6 +83,9 @@ const exampleData = { summary: "Essay: Why the Devil's Advocate Doesn't Help Reach the Truth", fulfillmentMessage: "", }, + refundPending: undefined, + totalRefundEffective: "USD:0", + totalRefundRaw: "USD:0", proposalId: "1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0", status: PaymentStatus.Accepted, } as TransactionPayment, @@ -117,6 +120,7 @@ const exampleData = { summary: "the summary", fulfillmentMessage: "", }, + refundPending: undefined, } as TransactionRefund, }; diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index bcf6114a1..3377f98c7 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -40,7 +40,6 @@ import { ButtonPrimary, CenteredDialog, InfoBox, - LargeText, ListOfProducts, Overlay, RowBorderGray, @@ -51,6 +50,7 @@ import { import { Time } from "../components/Time.js"; import { useTranslationContext } from "../context/translation.js"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; +import { Pages } from "../NavigationBar.js"; import * as wxApi from "../wxApi.js"; interface Props { @@ -344,6 +344,17 @@ export function TransactionView({ Amounts.parseOrThrow(transaction.amountRaw), ).amount; + const refundFee = Amounts.sub( + Amounts.parseOrThrow(transaction.totalRefundRaw), + Amounts.parseOrThrow(transaction.totalRefundEffective), + ).amount; + const refunded = Amounts.isNonZero( + Amounts.parseOrThrow(transaction.totalRefundRaw), + ); + const pendingRefund = + transaction.refundPending === undefined + ? undefined + : Amounts.parseOrThrow(transaction.refundPending); return ( @@ -360,18 +371,54 @@ export function TransactionView({ text={} kind="negative" /> - Purchase amount} - text={} - kind="neutral" - /> - Fee} - text={} - kind="negative" - /> + {Amounts.isNonZero(fee) && ( + + Purchase amount} + text={} + kind="neutral" + /> + Purchase Fee} + text={} + kind="negative" + /> + + )} + {refunded && ( + + Total refunded} + text={} + kind="positive" + /> + {Amounts.isNonZero(refundFee) && ( + + Refund amount} + text={} + kind="neutral" + /> + Refund fee} + text={} + kind="negative" + /> + + )} + + )} + {pendingRefund !== undefined && Amounts.isNonZero(pendingRefund) && ( + Refund pending} + text={} + kind="positive" + /> + )} Merchant} text={transaction.info.merchant.name} @@ -447,18 +494,22 @@ export function TransactionView({ text={} kind="neutral" /> - Deposit amount} - text={} - kind="positive" - /> - Fee} - text={} - kind="negative" - /> + {Amounts.isNonZero(fee) && ( + + Deposit amount} + text={} + kind="positive" + /> + Fee} + text={} + kind="negative" + /> + + )} {payto && } ); @@ -485,18 +536,22 @@ export function TransactionView({ text={} kind="negative" /> - Refresh amount} - text={} - kind="neutral" - /> - Fee} - text={} - kind="negative" - /> + {Amounts.isNonZero(fee) && ( + + Refresh amount} + text={} + kind="neutral" + /> + Fee} + text={} + kind="negative" + /> + + )} ); } @@ -522,18 +577,22 @@ export function TransactionView({ text={} kind="positive" /> - Received amount} - text={} - kind="neutral" - /> - Fee} - text={} - kind="negative" - /> + {Amounts.isNonZero(fee) && ( + + Received amount} + text={} + kind="neutral" + /> + Fee} + text={} + kind="negative" + /> + + )} ); } @@ -559,37 +618,42 @@ export function TransactionView({ text={} kind="positive" /> - Refund amount} - text={} - kind="neutral" - /> - Fee} - text={} - kind="negative" - /> + {Amounts.isNonZero(fee) && ( + + Refund amount} + text={} + kind="neutral" + /> + Fee} + text={} + kind="negative" + /> + + )} Merchant} text={transaction.info.merchant.name} kind="neutral" /> + Purchase} text={ - transaction.info.fulfillmentUrl ? ( - - {transaction.info.summary} - - ) : ( - transaction.info.summary - ) + + {transaction.info.summary} + } kind="neutral" /> -- cgit v1.2.3