From 0b2bf13deff518c3ebbdaf4a72d2c162790906b7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 13 Jan 2023 16:09:33 -0300 Subject: using extendedStatus --- .../src/wallet/Transaction.tsx | 386 +++++++++++++++------ 1 file changed, 274 insertions(+), 112 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet/Transaction.tsx') diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index c6fa9ec68..5ed05f87f 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -18,6 +18,7 @@ import { AbsoluteTime, AmountJson, Amounts, + ExtendedStatus, Location, MerchantInfo, NotificationType, @@ -60,11 +61,12 @@ import { WarningBox, } from "../components/styled/index.js"; import { Time } from "../components/Time.js"; -import { alertFromError } from "../context/alert.js"; +import { alertFromError, useAlertContext } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; import { useTranslationContext } from "../context/translation.js"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Button } from "../mui/Button.js"; +import { SafeHandler } from "../mui/handlers.js"; import { Pages } from "../NavigationBar.js"; interface Props { @@ -116,6 +118,12 @@ export function TransactionPage({ onSend={async () => { null; }} + onCancel={async () => { + await api.wallet.call(WalletApiOperation.AbortTransaction, { + transactionId, + }); + goToWalletHistory(currency); + }} onDelete={async () => { await api.wallet.call(WalletApiOperation.DeleteTransaction, { transactionId, @@ -141,6 +149,7 @@ export function TransactionPage({ export interface WalletTransactionProps { transaction: Transaction; onSend: () => Promise; + onCancel: () => Promise; onDelete: () => Promise; onRetry: () => Promise; onRefund: (id: string) => Promise; @@ -155,18 +164,29 @@ const PurchaseDetailsTable = styled.table` } `; -export function TransactionView({ +type TransactionTemplateProps = Omit< + Omit, + "onBack" +> & { + children: ComponentChildren; +}; + +function TransactionTemplate({ transaction, onDelete, onRetry, onSend, - onRefund, -}: WalletTransactionProps): VNode { + onCancel, + children, +}: TransactionTemplateProps): VNode { + const { i18n } = useTranslationContext(); const [confirmBeforeForget, setConfirmBeforeForget] = useState(false); + const [confirmBeforeCancel, setConfirmBeforeCancel] = useState(false); + const { safely } = useAlertContext(); async function doCheckBeforeForget(): Promise { if ( - transaction.pending && + transaction.extendedStatus === ExtendedStatus.Pending && transaction.type === TransactionType.Withdrawal ) { setConfirmBeforeForget(true); @@ -175,97 +195,64 @@ export function TransactionView({ } } - const SHOWING_RETRY_THRESHOLD_SECS = 30; - - const { i18n } = useTranslationContext(); - - function TransactionTemplate({ - children, - }: { - children: ComponentChildren; - }): VNode { - const showSend = false; - // (transaction.type === TransactionType.PeerPullCredit || - // transaction.type === TransactionType.PeerPushDebit) && - // !transaction.info.completed; - const showRetry = - transaction.error !== undefined || - transaction.timestamp.t_s === "never" || - (transaction.pending && - differenceInSeconds(new Date(), transaction.timestamp.t_s * 1000) > - SHOWING_RETRY_THRESHOLD_SECS); - - return ( - -
- {transaction?.error ? ( - transaction.error.code === 7025 ? ( - - - Follow this link to the{` `} - KYC verifier - - - ) : ( - i18n.str`No more information has been provided` - ), - }} - /> - ) : ( - - ) - ) : undefined} - {transaction.pending && ( - - This transaction is not completed - - )} -
-
{children}
-
-
- {showSend ? ( - - ) : null} -
-
- {showRetry ? ( - - ) : null} - -
-
-
- ); + async function doCheckBeforeCancel(): Promise { + setConfirmBeforeCancel(true); } - if (transaction.type === TransactionType.Withdrawal) { - const total = Amounts.parseOrThrow(transaction.amountEffective); - const chosen = Amounts.parseOrThrow(transaction.amountRaw); - return ( - + const SHOWING_RETRY_THRESHOLD_SECS = 30; + + const showSend = false; + // (transaction.type === TransactionType.PeerPullCredit || + // transaction.type === TransactionType.PeerPushDebit) && + // !transaction.info.completed; + const showRetry = + transaction.error !== undefined || + transaction.timestamp.t_s === "never" || + (transaction.extendedStatus === ExtendedStatus.Pending && + differenceInSeconds(new Date(), transaction.timestamp.t_s * 1000) > + SHOWING_RETRY_THRESHOLD_SECS); + + const transactionStillActive = + transaction.extendedStatus !== ExtendedStatus.Aborted && + transaction.extendedStatus !== ExtendedStatus.Done && + transaction.extendedStatus !== ExtendedStatus.Failed; + return ( + +
+ {transaction?.error ? ( + transaction.error.code === 7025 ? ( + + + Follow this link to the{` `} + KYC verifier + + + ) : ( + i18n.str`No more information has been provided` + ), + }} + /> + ) : ( + + ) + ) : undefined} + {transaction.extendedStatus === ExtendedStatus.Pending && ( + + This transaction is not completed + + )} {confirmBeforeForget ? ( @@ -282,18 +269,134 @@ export function TransactionView({ - ) : undefined} + {confirmBeforeCancel ? ( + + +
+ Caution! +
+
+ + Doing a cancelation while the transaction still active might + result in lost coins. Do you still want to cancel the + transaction? + +
+
+ + + +
+
+
+ ) : undefined} +
+
{children}
+
+
+ {showSend ? ( + + ) : null} +
+
+ {showRetry ? ( + + ) : null} + {transactionStillActive ? ( + + ) : ( + + )} +
+
+
+ ); +} + +export function TransactionView({ + transaction, + onDelete, + onRetry, + onSend, + onRefund, + onCancel, +}: WalletTransactionProps): VNode { + const { i18n } = useTranslationContext(); + const { safely } = useAlertContext(); + + if (transaction.type === TransactionType.Withdrawal) { + const total = Amounts.parseOrThrow(transaction.amountEffective); + const chosen = Amounts.parseOrThrow(transaction.amountRaw); + return ( +
- {!transaction.pending ? undefined : transaction.withdrawalDetails + {transaction.extendedStatus !== + ExtendedStatus.Pending ? undefined : transaction.withdrawalDetails .type === WithdrawalType.ManualTransfer ? ( +
@@ -529,7 +642,13 @@ export function TransactionView({ const total = Amounts.parseOrThrow(transaction.amountRaw); const payto = parsePaytoUri(transaction.targetPaytoUri); return ( - +
+
+
+
- - @@ -678,10 +815,10 @@ export function TransactionView({ return (
{text.substring(0, 64)}...
- -
@@ -691,7 +828,13 @@ export function TransactionView({ if (transaction.type === TransactionType.PeerPullCredit) { const total = Amounts.parseOrThrow(transaction.amountEffective); return ( - +
- {transaction.pending /** pending is not-pay */ && ( + {transaction.extendedStatus === + ExtendedStatus.Pending /** pending is not-pay */ && ( } @@ -738,7 +882,13 @@ export function TransactionView({ if (transaction.type === TransactionType.PeerPullDebit) { const total = Amounts.parseOrThrow(transaction.amountEffective); return ( - +
+
+