aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Payment/state.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-08-08 14:09:28 -0300
committerSebastian <sebasjm@gmail.com>2022-08-08 14:09:36 -0300
commit7a600514c6d43bbaeba6b962533415e59fc46057 (patch)
treed96c02537cda29f1637787a8fb8e659a37ea8c1f /packages/taler-wallet-webextension/src/cta/Payment/state.ts
parent4409d8384b77401489c2a92d3de20f79959ae34a (diff)
downloadwallet-core-7a600514c6d43bbaeba6b962533415e59fc46057.tar.xz
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)
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Payment/state.ts')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Payment/state.ts71
1 files changed, 39 insertions, 32 deletions
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<void> {
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
};
+
}