diff options
author | Sebastian <sebasjm@gmail.com> | 2022-11-16 16:04:52 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-11-16 16:05:13 -0300 |
commit | 1a63d56bfdd091cc7aefdf1e25f3a074bfdf5e0e (patch) | |
tree | 7255cf4a5b51af4807e2a01a370497413a78968f /packages/taler-wallet-webextension/src/cta | |
parent | 53164dc47b1138235a0c797affaa6fb37ea43239 (diff) | |
download | wallet-core-1a63d56bfdd091cc7aefdf1e25f3a074bfdf5e0e.tar.xz |
fix #7411, also making the backup payment visible
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
19 files changed, 548 insertions, 409 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts index 27f05ce03..4ce81dad8 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts @@ -15,7 +15,11 @@ */ /* eslint-disable react-hooks/rules-of-hooks */ -import { Amounts, TalerErrorDetail, TalerProtocolTimestamp } from "@gnu-taler/taler-util"; +import { + Amounts, + TalerErrorDetail, + TalerProtocolTimestamp, +} from "@gnu-taler/taler-util"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { isFuture, parse } from "date-fns"; import { useState } from "preact/hooks"; @@ -32,7 +36,9 @@ export function useComponentState( ): RecursiveState<State> { const amount = Amounts.parseOrThrow(amountStr); - const hook = useAsyncAsHook(() => api.wallet.call(WalletApiOperation.ListExchanges, {})); + const hook = useAsyncAsHook(() => + api.wallet.call(WalletApiOperation.ListExchanges, {}), + ); if (!hook) { return { @@ -51,7 +57,7 @@ export function useComponentState( return () => { const [subject, setSubject] = useState<string | undefined>(); - const [timestamp, setTimestamp] = useState<string | undefined>() + const [timestamp, setTimestamp] = useState<string | undefined>(); const [operationError, setOperationError] = useState< TalerErrorDetail | undefined @@ -70,45 +76,51 @@ export function useComponentState( const exchange = selectedExchange.selected; const hook = useAsyncAsHook(async () => { - const resp = await api.wallet.call(WalletApiOperation.PreparePeerPullPayment, { - amount: amountStr, - exchangeBaseUrl: exchange.exchangeBaseUrl, - }) - return resp - }) + const resp = await api.wallet.call( + WalletApiOperation.PreparePeerPullPayment, + { + amount: amountStr, + exchangeBaseUrl: exchange.exchangeBaseUrl, + }, + ); + return resp; + }); if (!hook) { return { status: "loading", - error: undefined - } + error: undefined, + }; } if (hook.hasError) { return { status: "loading-uri", - error: hook - } + error: hook, + }; } - const { amountEffective, amountRaw } = hook.response - const requestAmount = Amounts.parseOrThrow(amountRaw) - const toBeReceived = Amounts.parseOrThrow(amountEffective) + const { amountEffective, amountRaw } = hook.response; + const requestAmount = Amounts.parseOrThrow(amountRaw); + const toBeReceived = Amounts.parseOrThrow(amountEffective); - let purse_expiration: TalerProtocolTimestamp | undefined = undefined + let purse_expiration: TalerProtocolTimestamp | undefined = undefined; let timestampError: string | undefined = undefined; - const t = timestamp === undefined ? undefined : parse(timestamp, "dd/MM/yyyy", new Date()) + const t = + timestamp === undefined + ? undefined + : parse(timestamp, "dd/MM/yyyy", new Date()); if (t !== undefined) { if (Number.isNaN(t.getTime())) { - timestampError = 'Should have the format "dd/MM/yyyy"' + timestampError = 'Should have the format "dd/MM/yyyy"'; } else { if (!isFuture(t)) { - timestampError = 'Should be in the future' + timestampError = "Should be in the future"; } else { purse_expiration = { - t_s: t.getTime() / 1000 - } + t_s: t.getTime() / 1000, + }; } } } @@ -116,14 +128,17 @@ export function useComponentState( async function accept(): Promise<void> { if (!subject || !purse_expiration) return; try { - const resp = await api.wallet.call(WalletApiOperation.InitiatePeerPullPayment, { - exchangeBaseUrl: exchange.exchangeBaseUrl, - partialContractTerms: { - amount: Amounts.stringify(amount), - summary: subject, - purse_expiration + const resp = await api.wallet.call( + WalletApiOperation.InitiatePeerPullPayment, + { + exchangeBaseUrl: exchange.exchangeBaseUrl, + partialContractTerms: { + amount: Amounts.stringify(amount), + summary: subject, + purse_expiration, + }, }, - }); + ); onSuccess(resp.transactionId); } catch (e) { @@ -134,12 +149,18 @@ export function useComponentState( throw Error("error trying to accept"); } } - const unableToCreate = !subject || Amounts.isZero(amount) || !purse_expiration + const unableToCreate = + !subject || Amounts.isZero(amount) || !purse_expiration; return { status: "ready", subject: { - error: subject === undefined ? undefined : !subject ? "Can't be empty" : undefined, + error: + subject === undefined + ? undefined + : !subject + ? "Can't be empty" + : undefined, value: subject ?? "", onInput: async (e) => setSubject(e), }, @@ -147,8 +168,8 @@ export function useComponentState( error: timestampError, value: timestamp === undefined ? "" : timestamp, onInput: async (e) => { - setTimestamp(e) - } + setTimestamp(e); + }, }, doSelectExchange: selectedExchange.doSelect, exchangeUrl: exchange.exchangeBaseUrl, diff --git a/packages/taler-wallet-webextension/src/cta/InvoicePay/index.ts b/packages/taler-wallet-webextension/src/cta/InvoicePay/index.ts index 693803587..6e16b528c 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoicePay/index.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoicePay/index.ts @@ -18,7 +18,7 @@ import { AbsoluteTime, AmountJson, PreparePayResult, - TalerErrorDetail + TalerErrorDetail, } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; diff --git a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts index 457827127..1846794fc 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts @@ -21,7 +21,7 @@ import { PreparePayResult, PreparePayResultType, TalerErrorDetail, - TalerProtocolTimestamp + TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; @@ -41,10 +41,12 @@ export function useComponentState( return { p2p, balance }; }); - useEffect(() => api.listener.onUpdateNotification( - [NotificationType.CoinWithdrawn], - hook?.retry - )); + useEffect(() => + api.listener.onUpdateNotification( + [NotificationType.CoinWithdrawn], + hook?.retry, + ), + ); const [operationError, setOperationError] = useState< TalerErrorDetail | undefined @@ -63,10 +65,7 @@ export function useComponentState( }; } - const { - contractTerms, - peerPullPaymentIncomingId, - } = hook.response.p2p; + const { contractTerms, peerPullPaymentIncomingId } = hook.response.p2p; const amountStr: string = contractTerms?.amount; const amount = Amounts.parseOrThrow(amountStr); @@ -134,9 +133,12 @@ export function useComponentState( async function accept(): Promise<void> { try { - const resp = await api.wallet.call(WalletApiOperation.AcceptPeerPullPayment, { - peerPullPaymentIncomingId, - }); + const resp = await api.wallet.call( + WalletApiOperation.AcceptPeerPullPayment, + { + peerPullPaymentIncomingId, + }, + ); onSuccess(resp.transactionId); } catch (e) { if (e instanceof TalerError) { diff --git a/packages/taler-wallet-webextension/src/cta/Payment/index.ts b/packages/taler-wallet-webextension/src/cta/Payment/index.ts index b4e59e666..f0270b96c 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/index.ts @@ -15,8 +15,10 @@ */ import { - AmountJson, PreparePayResult, - PreparePayResultAlreadyConfirmed, PreparePayResultPaymentPossible + AmountJson, + PreparePayResult, + PreparePayResultAlreadyConfirmed, + PreparePayResultPaymentPossible, } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Payment/state.ts b/packages/taler-wallet-webextension/src/cta/Payment/state.ts index 414bc2000..49d022320 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/state.ts @@ -15,10 +15,11 @@ */ import { - Amounts, ConfirmPayResultType, + Amounts, + ConfirmPayResultType, NotificationType, PreparePayResultType, - TalerErrorCode + TalerErrorCode, } from "@gnu-taler/taler-util"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; @@ -35,17 +36,24 @@ export function useComponentState( const hook = useAsyncAsHook(async () => { if (!talerPayUri) throw Error("ERROR_NO-URI-FOR-PAYMENT"); - const payStatus = await api.wallet.call(WalletApiOperation.PreparePayForUri, { - talerPayUri: talerPayUri - }); + const payStatus = await api.wallet.call( + WalletApiOperation.PreparePayForUri, + { + talerPayUri: talerPayUri, + }, + ); const balance = await api.wallet.call(WalletApiOperation.GetBalances, {}); return { payStatus, balance, uri: talerPayUri }; }, []); - useEffect(() => api.listener.onUpdateNotification( - [NotificationType.CoinWithdrawn], - hook?.retry - ), [hook]); + useEffect( + () => + api.listener.onUpdateNotification( + [NotificationType.CoinWithdrawn], + hook?.retry, + ), + [hook], + ); const hookResponse = !hook || hook.hasError ? undefined : hook.response; diff --git a/packages/taler-wallet-webextension/src/cta/Payment/test.ts b/packages/taler-wallet-webextension/src/cta/Payment/test.ts index 8aa099fdc..b02ac6274 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/test.ts @@ -20,11 +20,13 @@ */ import { - Amounts, ConfirmPayResult, + Amounts, + ConfirmPayResult, ConfirmPayResultType, - NotificationType, PreparePayResultInsufficientBalance, + NotificationType, + PreparePayResultInsufficientBalance, PreparePayResultPaymentPossible, - PreparePayResultType + PreparePayResultType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; @@ -42,11 +44,9 @@ describe("Payment CTA states", () => { onSuccess: async () => { null; }, - } + }; const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState(props, mock), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -66,7 +66,7 @@ describe("Payment CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should response with no balance", async () => { @@ -78,18 +78,24 @@ describe("Payment CTA states", () => { onSuccess: async () => { null; }, - } + }; - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.InsufficientBalance, - amountRaw: "USD:10", - } as PreparePayResultInsufficientBalance) - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { balances: [] }) + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.InsufficientBalance, + amountRaw: "USD:10", + } as PreparePayResultInsufficientBalance, + ); + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { balances: [] }, + ); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState(props, mock), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -102,7 +108,7 @@ describe("Payment CTA states", () => { { const r = pullLastResultOrThrow(); if (r.status !== "no-balance-for-currency") { - expect(r).eq({}) + expect(r).eq({}); return; } expect(r.balance).undefined; @@ -110,7 +116,7 @@ describe("Payment CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should not be able to pay if there is no enough balance", async () => { @@ -122,25 +128,33 @@ describe("Payment CTA states", () => { onSuccess: async () => { null; }, - } - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.InsufficientBalance, - amountRaw: "USD:10", - } as PreparePayResultInsufficientBalance) - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { - balances: [{ - available: "USD:5", - hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", - requiresUserInput: false, - }] - }) + }; + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.InsufficientBalance, + amountRaw: "USD:10", + } as PreparePayResultInsufficientBalance, + ); + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { + balances: [ + { + available: "USD:5", + hasPendingTransactions: false, + pendingIncoming: "USD:0", + pendingOutgoing: "USD:0", + requiresUserInput: false, + }, + ], + }, + ); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState(props, mock), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -158,7 +172,7 @@ describe("Payment CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should be able to pay (without fee)", async () => { @@ -170,25 +184,33 @@ describe("Payment CTA states", () => { onSuccess: async () => { null; }, - } - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.PaymentPossible, - amountRaw: "USD:10", - amountEffective: "USD:10", - } as PreparePayResultPaymentPossible) - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { - balances: [{ - available: "USD:15", - hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", - requiresUserInput: false, - }] - }) + }; + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.PaymentPossible, + amountRaw: "USD:10", + amountEffective: "USD:10", + } as PreparePayResultPaymentPossible, + ); + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { + balances: [ + { + available: "USD:15", + hasPendingTransactions: false, + pendingIncoming: "USD:0", + pendingOutgoing: "USD:0", + requiresUserInput: false, + }, + ], + }, + ); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState(props, mock), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -201,8 +223,8 @@ describe("Payment CTA states", () => { { const r = pullLastResultOrThrow(); if (r.status !== "ready") { - expect(r).eq({}) - return + expect(r).eq({}); + return; } expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:10")); @@ -210,7 +232,7 @@ describe("Payment CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should be able to pay (with fee)", async () => { @@ -222,29 +244,33 @@ describe("Payment CTA states", () => { onSuccess: async () => { null; }, - } - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.PaymentPossible, - amountRaw: "USD:9", - amountEffective: "USD:10", - } as PreparePayResultPaymentPossible) - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { - balances: [{ - available: "USD:15", - hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", - requiresUserInput: false, - }] - }) + }; + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.PaymentPossible, + amountRaw: "USD:9", + amountEffective: "USD:10", + } as PreparePayResultPaymentPossible, + ); + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { + balances: [ + { + available: "USD:15", + hasPendingTransactions: false, + pendingIncoming: "USD:0", + pendingOutgoing: "USD:0", + requiresUserInput: false, + }, + ], + }, + ); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState( - props, - mock - - ), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -263,7 +289,7 @@ describe("Payment CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should get confirmation done after pay successfully", async () => { @@ -275,33 +301,39 @@ describe("Payment CTA states", () => { onSuccess: async () => { null; }, - } - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.PaymentPossible, - amountRaw: "USD:9", - amountEffective: "USD:10", - } as PreparePayResultPaymentPossible) - - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { - balances: [{ - available: "USD:15", - hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", - requiresUserInput: false, - }] - }) + }; + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.PaymentPossible, + amountRaw: "USD:9", + amountEffective: "USD:10", + } as PreparePayResultPaymentPossible, + ); + + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { + balances: [ + { + available: "USD:15", + hasPendingTransactions: false, + pendingIncoming: "USD:0", + pendingOutgoing: "USD:0", + requiresUserInput: false, + }, + ], + }, + ); handler.addWalletCallResponse(WalletApiOperation.ConfirmPay, undefined, { type: ConfirmPayResultType.Done, contractTerms: {}, - } as ConfirmPayResult) + } as ConfirmPayResult); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState( - props, mock - ), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -314,7 +346,7 @@ describe("Payment CTA states", () => { { const r = pullLastResultOrThrow(); if (r.status !== "ready") { - expect(r).eq({}) + expect(r).eq({}); return; } expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); @@ -324,7 +356,7 @@ describe("Payment CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should not stay in ready state after pay with error", async () => { @@ -335,32 +367,38 @@ describe("Payment CTA states", () => { goToWalletManualWithdraw: nullFunction, onSuccess: nullFunction, }; - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.PaymentPossible, - amountRaw: "USD:9", - amountEffective: "USD:10", - } as PreparePayResultPaymentPossible) - - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { - balances: [{ - available: "USD:15", - hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", - requiresUserInput: false, - }] - }) + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.PaymentPossible, + amountRaw: "USD:9", + amountEffective: "USD:10", + } as PreparePayResultPaymentPossible, + ); + + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { + balances: [ + { + available: "USD:15", + hasPendingTransactions: false, + pendingIncoming: "USD:0", + pendingOutgoing: "USD:0", + requiresUserInput: false, + }, + ], + }, + ); handler.addWalletCallResponse(WalletApiOperation.ConfirmPay, undefined, { type: ConfirmPayResultType.Pending, lastError: { code: 1 }, - } as ConfirmPayResult) + } as ConfirmPayResult); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState( - props, mock - ), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -368,7 +406,7 @@ describe("Payment CTA states", () => { expect(error).undefined; } - expect(await waitForStateUpdate()).true + expect(await waitForStateUpdate()).true; { const r = pullLastResultOrThrow(); @@ -380,7 +418,7 @@ describe("Payment CTA states", () => { r.payHandler.onClick(); } - expect(await waitForStateUpdate()).true + expect(await waitForStateUpdate()).true; { const r = pullLastResultOrThrow(); @@ -402,7 +440,7 @@ describe("Payment CTA states", () => { await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should update balance if a coins is withdraw", async () => { @@ -415,46 +453,62 @@ describe("Payment CTA states", () => { onSuccess: async () => { null; }, - } + }; - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.PaymentPossible, - amountRaw: "USD:9", - amountEffective: "USD:10", - } as PreparePayResultPaymentPossible) - - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { - balances: [{ - available: "USD:10", - hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", - requiresUserInput: false, - }] - }) - - handler.addWalletCallResponse(WalletApiOperation.PreparePayForUri, undefined, { - status: PreparePayResultType.PaymentPossible, - amountRaw: "USD:9", - amountEffective: "USD:10", - } as PreparePayResultPaymentPossible) - - handler.addWalletCallResponse(WalletApiOperation.GetBalances, {}, { - balances: [{ - available: "USD:15", - hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", - requiresUserInput: false, - }] - }) + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.PaymentPossible, + amountRaw: "USD:9", + amountEffective: "USD:10", + } as PreparePayResultPaymentPossible, + ); + + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { + balances: [ + { + available: "USD:10", + hasPendingTransactions: false, + pendingIncoming: "USD:0", + pendingOutgoing: "USD:0", + requiresUserInput: false, + }, + ], + }, + ); + + handler.addWalletCallResponse( + WalletApiOperation.PreparePayForUri, + undefined, + { + status: PreparePayResultType.PaymentPossible, + amountRaw: "USD:9", + amountEffective: "USD:10", + } as PreparePayResultPaymentPossible, + ); + + handler.addWalletCallResponse( + WalletApiOperation.GetBalances, + {}, + { + balances: [ + { + available: "USD:15", + hasPendingTransactions: false, + pendingIncoming: "USD:0", + pendingOutgoing: "USD:0", + requiresUserInput: false, + }, + ], + }, + ); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState( - props, mock - ), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -467,8 +521,8 @@ describe("Payment CTA states", () => { { const r = pullLastResultOrThrow(); if (r.status !== "ready") { - expect(r).eq({}) - return + expect(r).eq({}); + return; } expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:10")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); @@ -483,8 +537,8 @@ describe("Payment CTA states", () => { { const r = pullLastResultOrThrow(); if (r.status !== "ready") { - expect(r).eq({}) - return + expect(r).eq({}); + return; } expect(r.balance).deep.equal(Amounts.parseOrThrow("USD:15")); expect(r.amount).deep.equal(Amounts.parseOrThrow("USD:9")); @@ -493,6 +547,6 @@ describe("Payment CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); }); diff --git a/packages/taler-wallet-webextension/src/cta/Recovery/state.ts b/packages/taler-wallet-webextension/src/cta/Recovery/state.ts index 750fd22f7..3a5d94e2e 100644 --- a/packages/taler-wallet-webextension/src/cta/Recovery/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Recovery/state.ts @@ -48,7 +48,9 @@ export function useComponentState( const recovery = info; async function recoverBackup(): Promise<void> { - await wxApi.wallet.call(WalletApiOperation.ImportBackupRecovery, { recovery }); + await wxApi.wallet.call(WalletApiOperation.ImportBackupRecovery, { + recovery, + }); onSuccess(); } diff --git a/packages/taler-wallet-webextension/src/cta/Refund/index.ts b/packages/taler-wallet-webextension/src/cta/Refund/index.ts index 6bd976aab..099f72919 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/index.ts @@ -25,7 +25,7 @@ import { IgnoredView, InProgressView, LoadingUriView, - ReadyView + ReadyView, } from "./views.js"; export interface Props { diff --git a/packages/taler-wallet-webextension/src/cta/Refund/state.ts b/packages/taler-wallet-webextension/src/cta/Refund/state.ts index 65a895fc3..94c5567d6 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/state.ts @@ -29,13 +29,17 @@ export function useComponentState( const info = useAsyncAsHook(async () => { if (!talerRefundUri) throw Error("ERROR_NO-URI-FOR-REFUND"); - const refund = await api.wallet.call(WalletApiOperation.PrepareRefund, { talerRefundUri }); + const refund = await api.wallet.call(WalletApiOperation.PrepareRefund, { + talerRefundUri, + }); return { refund, uri: talerRefundUri }; }); - useEffect(() => api.listener.onUpdateNotification( - [NotificationType.RefreshMelted], - info?.retry) + useEffect(() => + api.listener.onUpdateNotification( + [NotificationType.RefreshMelted], + info?.retry, + ), ); if (!info) { @@ -52,7 +56,7 @@ export function useComponentState( const doAccept = async (): Promise<void> => { const res = await api.wallet.call(WalletApiOperation.ApplyRefund, { - talerRefundUri: uri + talerRefundUri: uri, }); onSuccess(res.transactionId); diff --git a/packages/taler-wallet-webextension/src/cta/Refund/test.ts b/packages/taler-wallet-webextension/src/cta/Refund/test.ts index 41996c133..927c45981 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/test.ts @@ -21,7 +21,10 @@ import { AmountJson, - Amounts, NotificationType, OrderShortInfo, PrepareRefundResult + Amounts, + NotificationType, + OrderShortInfo, + PrepareRefundResult, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; @@ -45,7 +48,7 @@ describe("Refund CTA states", () => { null; }, }, - mock + mock, // { // prepareRefund: async () => ({}), // applyRefund: async () => ({}), @@ -73,7 +76,7 @@ describe("Refund CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should be ready after loading", async () => { @@ -86,7 +89,7 @@ describe("Refund CTA states", () => { onSuccess: async () => { null; }, - } + }; handler.addWalletCallResponse(WalletApiOperation.PrepareRefund, undefined, { awaiting: "EUR:2", @@ -103,12 +106,13 @@ describe("Refund CTA states", () => { orderId: "orderId1", summary: "the summary", } as OrderShortInfo, - }) + }); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = mountHook(() => useComponentState( - props, mock + props, + mock, // { // prepareRefund: async () => // ({ @@ -154,7 +158,7 @@ describe("Refund CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should be ignored after clicking the ignore button", async () => { @@ -167,7 +171,7 @@ describe("Refund CTA states", () => { onSuccess: async () => { null; }, - } + }; handler.addWalletCallResponse(WalletApiOperation.PrepareRefund, undefined, { awaiting: "EUR:2", @@ -184,7 +188,7 @@ describe("Refund CTA states", () => { orderId: "orderId1", summary: "the summary", } as OrderShortInfo, - }) + }); // handler.addWalletCall(WalletApiOperation.ApplyRefund) // handler.addWalletCall(WalletApiOperation.PrepareRefund, undefined, { // awaiting: "EUR:1", @@ -205,7 +209,8 @@ describe("Refund CTA states", () => { const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = mountHook(() => useComponentState( - props, mock + props, + mock, // { // prepareRefund: async () => // ({ @@ -242,11 +247,11 @@ describe("Refund CTA states", () => { const state = pullLastResultOrThrow(); if (state.status !== "ready") { - expect(state).eq({}) + expect(state).eq({}); return; } if (state.error) { - expect(state).eq({}) + expect(state).eq({}); return; } expect(state.accept.onClick).not.undefined; @@ -264,18 +269,18 @@ describe("Refund CTA states", () => { const state = pullLastResultOrThrow(); if (state.status !== "ignored") { - expect(state).eq({}) + expect(state).eq({}); return; } if (state.error) { - expect(state).eq({}) + expect(state).eq({}); return; } expect(state.merchantName).eq("the merchant name"); } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should be in progress when doing refresh", async () => { @@ -288,7 +293,7 @@ describe("Refund CTA states", () => { onSuccess: async () => { null; }, - } + }; handler.addWalletCallResponse(WalletApiOperation.PrepareRefund, undefined, { awaiting: "EUR:2", @@ -305,7 +310,7 @@ describe("Refund CTA states", () => { orderId: "orderId1", summary: "the summary", } as OrderShortInfo, - }) + }); handler.addWalletCallResponse(WalletApiOperation.PrepareRefund, undefined, { awaiting: "EUR:1", effectivePaid: "EUR:2", @@ -321,7 +326,7 @@ describe("Refund CTA states", () => { orderId: "orderId1", summary: "the summary", } as OrderShortInfo, - }) + }); handler.addWalletCallResponse(WalletApiOperation.PrepareRefund, undefined, { awaiting: "EUR:0", effectivePaid: "EUR:2", @@ -337,14 +342,10 @@ describe("Refund CTA states", () => { orderId: "orderId1", summary: "the summary", } as OrderShortInfo, - }) + }); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = - mountHook(() => - useComponentState( - props, mock - ), - ); + mountHook(() => useComponentState(props, mock)); { const { status, error } = pullLastResultOrThrow(); @@ -358,7 +359,7 @@ describe("Refund CTA states", () => { const state = pullLastResultOrThrow(); if (state.status !== "in-progress") { - expect(state).eq({}) + expect(state).eq({}); return; } if (state.error) expect.fail(); @@ -367,7 +368,7 @@ describe("Refund CTA states", () => { expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")); // expect(state.progress).closeTo(1 / 3, 0.01) - handler.notifyEventFromWallet(NotificationType.RefreshMelted) + handler.notifyEventFromWallet(NotificationType.RefreshMelted); } expect(await waitForStateUpdate()).true; @@ -376,7 +377,7 @@ describe("Refund CTA states", () => { const state = pullLastResultOrThrow(); if (state.status !== "in-progress") { - expect(state).eq({}) + expect(state).eq({}); return; } if (state.error) expect.fail(); @@ -385,7 +386,7 @@ describe("Refund CTA states", () => { expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:2")); // expect(state.progress).closeTo(2 / 3, 0.01) - handler.notifyEventFromWallet(NotificationType.RefreshMelted) + handler.notifyEventFromWallet(NotificationType.RefreshMelted); } expect(await waitForStateUpdate()).true; @@ -394,7 +395,7 @@ describe("Refund CTA states", () => { const state = pullLastResultOrThrow(); if (state.status !== "ready") { - expect(state).eq({}) + expect(state).eq({}); return; } if (state.error) expect.fail(); @@ -404,6 +405,6 @@ describe("Refund CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); }); diff --git a/packages/taler-wallet-webextension/src/cta/Tip/index.ts b/packages/taler-wallet-webextension/src/cta/Tip/index.ts index 520d854f2..ff917008f 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/index.ts @@ -25,7 +25,7 @@ import { AcceptedView, IgnoredView, LoadingUriView, - ReadyView + ReadyView, } from "./views.js"; export interface Props { diff --git a/packages/taler-wallet-webextension/src/cta/Tip/state.ts b/packages/taler-wallet-webextension/src/cta/Tip/state.ts index 00e1fddad..ea9ba1b37 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/state.ts @@ -26,7 +26,9 @@ export function useComponentState( ): State { const tipInfo = useAsyncAsHook(async () => { if (!talerTipUri) throw Error("ERROR_NO-URI-FOR-TIP"); - const tip = await api.wallet.call(WalletApiOperation.PrepareTip, { talerTipUri }); + const tip = await api.wallet.call(WalletApiOperation.PrepareTip, { + talerTipUri, + }); return { tip }; }); @@ -46,7 +48,9 @@ export function useComponentState( const { tip } = tipInfo.response; const doAccept = async (): Promise<void> => { - const res = await api.wallet.call(WalletApiOperation.AcceptTip, { walletTipId: tip.walletTipId }); + const res = await api.wallet.call(WalletApiOperation.AcceptTip, { + walletTipId: tip.walletTipId, + }); //FIX: this may not be seen since we are moving to the success also tipInfo.retry(); diff --git a/packages/taler-wallet-webextension/src/cta/Tip/test.ts b/packages/taler-wallet-webextension/src/cta/Tip/test.ts index 69badbede..e57b9ec4d 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/test.ts @@ -65,11 +65,10 @@ describe("Tip CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should be ready for accepting the tip", async () => { - const { handler, mock } = createWalletApiMock(); handler.addWalletCallResponse(WalletApiOperation.PrepareTip, undefined, { @@ -79,9 +78,9 @@ describe("Tip CTA states", () => { tipAmountEffective: "EUR:1", walletTipId: "tip_id", expirationTimestamp: { - t_s: 1 + t_s: 1, }, - tipAmountRaw: "" + tipAmountRaw: "", }); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = @@ -112,7 +111,7 @@ describe("Tip CTA states", () => { const state = pullLastResultOrThrow(); if (state.status !== "ready") { - expect(state).eq({ status: "ready" }) + expect(state).eq({ status: "ready" }); return; } if (state.error) expect.fail(); @@ -132,9 +131,9 @@ describe("Tip CTA states", () => { tipAmountEffective: "EUR:1", walletTipId: "tip_id", expirationTimestamp: { - t_s: 1 + t_s: 1, }, - tipAmountRaw: "" + tipAmountRaw: "", }); expect(await waitForStateUpdate()).true; @@ -142,7 +141,7 @@ describe("Tip CTA states", () => { const state = pullLastResultOrThrow(); if (state.status !== "accepted") { - expect(state).eq({ status: "accepted" }) + expect(state).eq({ status: "accepted" }); return; } if (state.error) expect.fail(); @@ -151,7 +150,7 @@ describe("Tip CTA states", () => { expect(state.exchangeBaseUrl).eq("exchange url"); } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should be ignored after clicking the ignore button", async () => { @@ -165,7 +164,7 @@ describe("Tip CTA states", () => { expirationTimestamp: { t_s: 1, }, - tipAmountRaw: "" + tipAmountRaw: "", }); const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = @@ -203,7 +202,7 @@ describe("Tip CTA states", () => { } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); it("should render accepted if the tip has been used previously", async () => { @@ -255,6 +254,6 @@ describe("Tip CTA states", () => { expect(state.exchangeBaseUrl).eq("exchange url"); } await assertNoPendingUpdate(); - expect(handler.getCallingQueueState()).eq("empty") + expect(handler.getCallingQueueState()).eq("empty"); }); }); diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts index 089f46047..c5e143f42 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts @@ -14,7 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { Amounts, TalerErrorDetail, TalerProtocolTimestamp } from "@gnu-taler/taler-util"; +import { + Amounts, + TalerErrorDetail, + TalerProtocolTimestamp, +} from "@gnu-taler/taler-util"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { format, isFuture, parse } from "date-fns"; import { useState } from "preact/hooks"; @@ -29,52 +33,57 @@ export function useComponentState( const amount = Amounts.parseOrThrow(amountStr); const [subject, setSubject] = useState<string | undefined>(); - const [timestamp, setTimestamp] = useState<string | undefined>() + const [timestamp, setTimestamp] = useState<string | undefined>(); const [operationError, setOperationError] = useState< TalerErrorDetail | undefined >(undefined); - const hook = useAsyncAsHook(async () => { - const resp = await api.wallet.call(WalletApiOperation.PreparePeerPushPayment, { - amount: amountStr - }) - return resp - }) + const resp = await api.wallet.call( + WalletApiOperation.PreparePeerPushPayment, + { + amount: amountStr, + }, + ); + return resp; + }); if (!hook) { return { status: "loading", - error: undefined - } + error: undefined, + }; } if (hook.hasError) { return { status: "loading-uri", - error: hook - } + error: hook, + }; } - const { amountEffective, amountRaw } = hook.response - const debitAmount = Amounts.parseOrThrow(amountRaw) - const toBeReceived = Amounts.parseOrThrow(amountEffective) + const { amountEffective, amountRaw } = hook.response; + const debitAmount = Amounts.parseOrThrow(amountRaw); + const toBeReceived = Amounts.parseOrThrow(amountEffective); - let purse_expiration: TalerProtocolTimestamp | undefined = undefined + let purse_expiration: TalerProtocolTimestamp | undefined = undefined; let timestampError: string | undefined = undefined; - const t = timestamp === undefined ? undefined : parse(timestamp, "dd/MM/yyyy", new Date()) + const t = + timestamp === undefined + ? undefined + : parse(timestamp, "dd/MM/yyyy", new Date()); if (t !== undefined) { if (Number.isNaN(t.getTime())) { - timestampError = 'Should have the format "dd/MM/yyyy"' + timestampError = 'Should have the format "dd/MM/yyyy"'; } else { if (!isFuture(t)) { - timestampError = 'Should be in the future' + timestampError = "Should be in the future"; } else { purse_expiration = { - t_s: t.getTime() / 1000 - } + t_s: t.getTime() / 1000, + }; } } } @@ -82,13 +91,16 @@ export function useComponentState( async function accept(): Promise<void> { if (!subject || !purse_expiration) return; try { - const resp = await api.wallet.call(WalletApiOperation.InitiatePeerPushPayment, { - partialContractTerms: { - summary: subject, - amount: amountStr, - purse_expiration + const resp = await api.wallet.call( + WalletApiOperation.InitiatePeerPushPayment, + { + partialContractTerms: { + summary: subject, + amount: amountStr, + purse_expiration, + }, }, - }); + ); onSuccess(resp.transactionId); } catch (e) { if (e instanceof TalerError) { @@ -99,7 +111,8 @@ export function useComponentState( } } - const unableToCreate = !subject || Amounts.isZero(amount) || !purse_expiration + const unableToCreate = + !subject || Amounts.isZero(amount) || !purse_expiration; return { status: "ready", @@ -107,7 +120,12 @@ export function useComponentState( onClick: onClose, }, subject: { - error: subject === undefined ? undefined : !subject ? "Can't be empty" : undefined, + error: + subject === undefined + ? undefined + : !subject + ? "Can't be empty" + : undefined, value: subject ?? "", onInput: async (e) => setSubject(e), }, @@ -115,8 +133,8 @@ export function useComponentState( error: timestampError, value: timestamp === undefined ? "" : timestamp, onInput: async (e) => { - setTimestamp(e) - } + setTimestamp(e); + }, }, create: { onClick: unableToCreate ? undefined : accept, diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts index 954243fe8..399f1e290 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts @@ -17,7 +17,7 @@ import { AbsoluteTime, AmountJson, - TalerErrorDetail + TalerErrorDetail, } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts index 4b860559e..e8fb99ab7 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts @@ -18,7 +18,7 @@ import { AbsoluteTime, Amounts, TalerErrorDetail, - TalerProtocolTimestamp + TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; @@ -52,10 +52,7 @@ export function useComponentState( }; } - const { - contractTerms, - peerPushPaymentIncomingId, - } = hook.response; + const { contractTerms, peerPushPaymentIncomingId } = hook.response; const amount: string = contractTerms?.amount; const summary: string | undefined = contractTerms?.summary; @@ -64,9 +61,12 @@ export function useComponentState( async function accept(): Promise<void> { try { - const resp = await api.wallet.call(WalletApiOperation.AcceptPeerPushPayment, { - peerPushPaymentIncomingId, - }); + const resp = await api.wallet.call( + WalletApiOperation.AcceptPeerPushPayment, + { + peerPushPaymentIncomingId, + }, + ); onSuccess(resp.transactionId); } catch (e) { if (e instanceof TalerError) { 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"); }); }); |