summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Withdraw
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-11-16 16:04:52 -0300
committerSebastian <sebasjm@gmail.com>2022-11-16 16:05:13 -0300
commit1a63d56bfdd091cc7aefdf1e25f3a074bfdf5e0e (patch)
tree7255cf4a5b51af4807e2a01a370497413a78968f /packages/taler-wallet-webextension/src/cta/Withdraw
parent53164dc47b1138235a0c797affaa6fb37ea43239 (diff)
downloadwallet-core-1a63d56bfdd091cc7aefdf1e25f3a074bfdf5e0e.tar.gz
wallet-core-1a63d56bfdd091cc7aefdf1e25f3a074bfdf5e0e.tar.bz2
wallet-core-1a63d56bfdd091cc7aefdf1e25f3a074bfdf5e0e.zip
fix #7411, also making the backup payment visible
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/index.ts2
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/state.ts63
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/test.ts137
3 files changed, 113 insertions, 89 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts
index 9a7acf9f1..68b314c07 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw/index.ts
@@ -23,7 +23,7 @@ import { compose, StateViewMap } from "../../utils/index.js";
import { wxApi } from "../../wxApi.js";
import {
useComponentStateFromParams,
- useComponentStateFromURI
+ useComponentStateFromURI,
} from "./state.js";
import { ExchangeSelectionPage } from "../../wallet/ExchangeSelection/index.js";
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
index 704ef1ac3..016027163 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
@@ -19,7 +19,7 @@ import {
AmountJson,
Amounts,
ExchangeListItem,
- ExchangeTosStatus
+ ExchangeTosStatus,
} from "@gnu-taler/taler-util";
import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { useState } from "preact/hooks";
@@ -35,7 +35,10 @@ export function useComponentStateFromParams(
api: typeof wxApi,
): RecursiveState<State> {
const uriInfoHook = useAsyncAsHook(async () => {
- const exchanges = await api.wallet.call(WalletApiOperation.ListExchanges, {});
+ const exchanges = await api.wallet.call(
+ WalletApiOperation.ListExchanges,
+ {},
+ );
return { amount: Amounts.parseOrThrow(amount), exchanges };
});
@@ -58,11 +61,14 @@ export function useComponentStateFromParams(
transactionId: string;
confirmTransferUrl: string | undefined;
}> {
- const res = await api.wallet.call(WalletApiOperation.AcceptManualWithdrawal, {
- exchangeBaseUrl: exchange,
- amount: Amounts.stringify(chosenAmount),
- restrictAge: ageRestricted,
- });
+ const res = await api.wallet.call(
+ WalletApiOperation.AcceptManualWithdrawal,
+ {
+ exchangeBaseUrl: exchange,
+ amount: Amounts.stringify(chosenAmount),
+ restrictAge: ageRestricted,
+ },
+ );
return {
confirmTransferUrl: undefined,
transactionId: res.transactionId,
@@ -93,9 +99,12 @@ export function useComponentStateFromURI(
const uriInfoHook = useAsyncAsHook(async () => {
if (!talerWithdrawUri) throw Error("ERROR_NO-URI-FOR-WITHDRAWAL");
- const uriInfo = await api.wallet.call(WalletApiOperation.GetWithdrawalDetailsForUri, {
- talerWithdrawUri,
- });
+ const uriInfo = await api.wallet.call(
+ WalletApiOperation.GetWithdrawalDetailsForUri,
+ {
+ talerWithdrawUri,
+ },
+ );
const { amount, defaultExchangeBaseUrl } = uriInfo;
return {
talerWithdrawUri,
@@ -126,11 +135,14 @@ export function useComponentStateFromURI(
transactionId: string;
confirmTransferUrl: string | undefined;
}> {
- const res = await api.wallet.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, {
- exchangeBaseUrl: exchange,
- talerWithdrawUri: uri,
- restrictAge: ageRestricted
- });
+ const res = await api.wallet.call(
+ WalletApiOperation.AcceptBankIntegratedWithdrawal,
+ {
+ exchangeBaseUrl: exchange,
+ talerWithdrawUri: uri,
+ restrictAge: ageRestricted,
+ },
+ );
return {
confirmTransferUrl: res.confirmTransferUrl,
transactionId: res.transactionId,
@@ -189,11 +201,14 @@ function exchangeSelectionState(
* about the withdrawal
*/
const amountHook = useAsyncAsHook(async () => {
- const info = await api.wallet.call(WalletApiOperation.GetWithdrawalDetailsForAmount, {
- exchangeBaseUrl: currentExchange.exchangeBaseUrl,
- amount: Amounts.stringify(chosenAmount),
- restrictAge: ageRestricted,
- });
+ const info = await api.wallet.call(
+ WalletApiOperation.GetWithdrawalDetailsForAmount,
+ {
+ exchangeBaseUrl: currentExchange.exchangeBaseUrl,
+ amount: Amounts.stringify(chosenAmount),
+ restrictAge: ageRestricted,
+ },
+ );
const withdrawAmount = {
raw: Amounts.parseOrThrow(info.amountRaw),
@@ -264,10 +279,10 @@ function exchangeSelectionState(
//TODO: calculate based on exchange info
const ageRestriction = ageRestrictionEnabled
? {
- list: ageRestrictionOptions,
- value: String(ageRestricted),
- onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
- }
+ list: ageRestrictionOptions,
+ value: String(ageRestricted),
+ onChange: async (v: string) => setAgeRestricted(parseInt(v, 10)),
+ }
: undefined;
return {
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts
index b4ba32f8a..7fd8188ce 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts
@@ -21,7 +21,9 @@
import {
Amounts,
- ExchangeEntryStatus, ExchangeListItem, ExchangeTosStatus
+ ExchangeEntryStatus,
+ ExchangeListItem,
+ ExchangeTosStatus,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { expect } from "chai";
@@ -70,13 +72,9 @@ describe("Withdraw CTA states", () => {
onSuccess: async () => {
null;
},
- }
+ };
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
- mountHook(() =>
- useComponentStateFromURI(
- props, mock
- ),
- );
+ mountHook(() => useComponentStateFromURI(props, mock));
{
const { status } = pullLastResultOrThrow();
@@ -96,7 +94,7 @@ describe("Withdraw CTA states", () => {
}
await assertNoPendingUpdate();
- expect(handler.getCallingQueueState()).eq("empty")
+ expect(handler.getCallingQueueState()).eq("empty");
});
it("should tell the user that there is not known exchange", async () => {
@@ -109,18 +107,18 @@ describe("Withdraw CTA states", () => {
onSuccess: async () => {
null;
},
- }
- handler.addWalletCallResponse(WalletApiOperation.GetWithdrawalDetailsForUri, undefined, {
- amount: "EUR:2",
- possibleExchanges: [],
- })
+ };
+ handler.addWalletCallResponse(
+ WalletApiOperation.GetWithdrawalDetailsForUri,
+ undefined,
+ {
+ amount: "EUR:2",
+ possibleExchanges: [],
+ },
+ );
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
- mountHook(() =>
- useComponentStateFromURI(
- props, mock
- ),
- );
+ mountHook(() => useComponentStateFromURI(props, mock));
{
const { status } = pullLastResultOrThrow();
@@ -138,7 +136,7 @@ describe("Withdraw CTA states", () => {
}
await assertNoPendingUpdate();
- expect(handler.getCallingQueueState()).eq("empty")
+ expect(handler.getCallingQueueState()).eq("empty");
});
it("should be able to withdraw if tos are ok", async () => {
@@ -151,26 +149,30 @@ describe("Withdraw CTA states", () => {
onSuccess: async () => {
null;
},
- }
- handler.addWalletCallResponse(WalletApiOperation.GetWithdrawalDetailsForUri, undefined, {
- amount: "ARS:2",
- possibleExchanges: exchanges,
- defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl
- })
- handler.addWalletCallResponse(WalletApiOperation.GetWithdrawalDetailsForAmount, undefined, {
- amountRaw: "ARS:2",
- amountEffective: "ARS:2",
- paytoUris: ["payto://"],
- tosAccepted: true,
- ageRestrictionOptions: []
- })
+ };
+ handler.addWalletCallResponse(
+ WalletApiOperation.GetWithdrawalDetailsForUri,
+ undefined,
+ {
+ amount: "ARS:2",
+ possibleExchanges: exchanges,
+ defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl,
+ },
+ );
+ handler.addWalletCallResponse(
+ WalletApiOperation.GetWithdrawalDetailsForAmount,
+ undefined,
+ {
+ amountRaw: "ARS:2",
+ amountEffective: "ARS:2",
+ paytoUris: ["payto://"],
+ tosAccepted: true,
+ ageRestrictionOptions: [],
+ },
+ );
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
- mountHook(() =>
- useComponentStateFromURI(
- props, mock
- ),
- );
+ mountHook(() => useComponentStateFromURI(props, mock));
{
const { status, error } = pullLastResultOrThrow();
@@ -203,7 +205,7 @@ describe("Withdraw CTA states", () => {
}
await assertNoPendingUpdate();
- expect(handler.getCallingQueueState()).eq("empty")
+ expect(handler.getCallingQueueState()).eq("empty");
});
it("should accept the tos before withdraw", async () => {
@@ -216,38 +218,45 @@ describe("Withdraw CTA states", () => {
onSuccess: async () => {
null;
},
- }
+ };
const exchangeWithNewTos = exchanges.map((e) => ({
...e,
tosStatus: ExchangeTosStatus.New,
}));
- handler.addWalletCallResponse(WalletApiOperation.GetWithdrawalDetailsForUri, undefined, {
- amount: "ARS:2",
- possibleExchanges: exchangeWithNewTos,
- defaultExchangeBaseUrl: exchangeWithNewTos[0].exchangeBaseUrl
- })
- handler.addWalletCallResponse(WalletApiOperation.GetWithdrawalDetailsForAmount, undefined, {
- amountRaw: "ARS:2",
- amountEffective: "ARS:2",
- paytoUris: ["payto://"],
- tosAccepted: false,
- ageRestrictionOptions: []
- })
-
-
- handler.addWalletCallResponse(WalletApiOperation.GetWithdrawalDetailsForUri, undefined, {
- amount: "ARS:2",
- possibleExchanges: exchanges,
- defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl
- })
+ handler.addWalletCallResponse(
+ WalletApiOperation.GetWithdrawalDetailsForUri,
+ undefined,
+ {
+ amount: "ARS:2",
+ possibleExchanges: exchangeWithNewTos,
+ defaultExchangeBaseUrl: exchangeWithNewTos[0].exchangeBaseUrl,
+ },
+ );
+ handler.addWalletCallResponse(
+ WalletApiOperation.GetWithdrawalDetailsForAmount,
+ undefined,
+ {
+ amountRaw: "ARS:2",
+ amountEffective: "ARS:2",
+ paytoUris: ["payto://"],
+ tosAccepted: false,
+ ageRestrictionOptions: [],
+ },
+ );
+
+ handler.addWalletCallResponse(
+ WalletApiOperation.GetWithdrawalDetailsForUri,
+ undefined,
+ {
+ amount: "ARS:2",
+ possibleExchanges: exchanges,
+ defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl,
+ },
+ );
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
- mountHook(() =>
- useComponentStateFromURI(
- props, mock
- ),
- );
+ mountHook(() => useComponentStateFromURI(props, mock));
{
const { status, error } = pullLastResultOrThrow();
@@ -297,6 +306,6 @@ describe("Withdraw CTA states", () => {
}
await assertNoPendingUpdate();
- expect(handler.getCallingQueueState()).eq("empty")
+ expect(handler.getCallingQueueState()).eq("empty");
});
});