diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-16 14:29:35 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-16 14:29:35 -0300 |
commit | 6ddb2de84245ae3914c92b2b2eb7399e7f04500e (patch) | |
tree | 425cc377daf053e5283bee6986f6f437f25d7584 /packages/taler-wallet-webextension/src/cta/TransferPickup | |
parent | 860f10e6f004668d3109b5a1d96ddb2b26ddc2f5 (diff) | |
download | wallet-core-6ddb2de84245ae3914c92b2b2eb7399e7f04500e.tar.xz |
pretty
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/TransferPickup')
3 files changed, 46 insertions, 35 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts index 08428851e..914296062 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts @@ -14,7 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { AbsoluteTime, AmountJson, TalerErrorDetail } from "@gnu-taler/taler-util"; +import { + AbsoluteTime, + AmountJson, + TalerErrorDetail, +} from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; import { ButtonHandler } from "../../mui/handlers.js"; @@ -28,13 +32,9 @@ export interface Props { onClose: () => Promise<void>; } -export type State = - | State.Loading - | State.LoadingUriError - | State.Ready; +export type State = State.Loading | State.LoadingUriError | State.Ready; export namespace State { - export interface Loading { status: "loading"; error: undefined; @@ -51,7 +51,7 @@ export namespace State { } export interface Ready extends BaseInfo { status: "ready"; - amount: AmountJson, + amount: AmountJson; summary: string | undefined; expiration: AbsoluteTime | undefined; error: undefined; @@ -63,9 +63,11 @@ export namespace State { const viewMapping: StateViewMap<State> = { loading: Loading, "loading-uri": LoadingUriView, - "ready": ReadyView, + ready: ReadyView, }; - -export const TransferPickupPage = compose("TransferPickupPage", (p: Props) => useComponentState(p, wxApi), viewMapping) - +export const TransferPickupPage = compose( + "TransferPickupPage", + (p: Props) => useComponentState(p, wxApi), + viewMapping, +); diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts index ce4c7236d..d4c863608 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts @@ -14,7 +14,12 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { AbsoluteTime, Amounts, TalerErrorDetail, TalerProtocolTimestamp } from "@gnu-taler/taler-util"; +import { + AbsoluteTime, + Amounts, + TalerErrorDetail, + TalerProtocolTimestamp, +} from "@gnu-taler/taler-util"; import { TalerError } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; @@ -28,15 +33,17 @@ export function useComponentState( const hook = useAsyncAsHook(async () => { return await api.checkPeerPushPayment({ talerUri: talerPayPushUri, - }) - }, []) - const [operationError, setOperationError] = useState<TalerErrorDetail | undefined>(undefined) + }); + }, []); + const [operationError, setOperationError] = useState< + TalerErrorDetail | undefined + >(undefined); if (!hook) { return { status: "loading", error: undefined, - } + }; } if (hook.hasError) { return { @@ -45,24 +52,29 @@ export function useComponentState( }; } - const { amount: purseAmount, contractTerms, peerPushPaymentIncomingId } = hook.response + const { + amount: purseAmount, + contractTerms, + peerPushPaymentIncomingId, + } = hook.response; - const amount: string = contractTerms?.amount - const summary: string | undefined = contractTerms?.summary - const expiration: TalerProtocolTimestamp | undefined = contractTerms?.purse_expiration + const amount: string = contractTerms?.amount; + const summary: string | undefined = contractTerms?.summary; + const expiration: TalerProtocolTimestamp | undefined = + contractTerms?.purse_expiration; async function accept(): Promise<void> { try { const resp = await api.acceptPeerPushPayment({ - peerPushPaymentIncomingId - }) - await onClose() + peerPushPaymentIncomingId, + }); + await onClose(); } catch (e) { if (e instanceof TalerError) { - setOperationError(e.errorDetail) + setOperationError(e.errorDetail); } - console.error(e) - throw Error("error trying to accept") + console.error(e); + throw Error("error trying to accept"); } } return { @@ -70,13 +82,13 @@ export function useComponentState( amount: Amounts.parseOrThrow(amount), error: undefined, accept: { - onClick: accept + onClick: accept, }, summary, expiration: expiration ? AbsoluteTime.fromTimestamp(expiration) : undefined, cancel: { - onClick: onClose + onClick: onClose, }, - operationError - } + operationError, + }; } diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/test.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/test.ts index 631e76d01..eae4d4ca2 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/test.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/test.ts @@ -22,10 +22,7 @@ import { expect } from "chai"; describe("test description", () => { - it("should assert", () => { - - expect([]).deep.equals([]) + expect([]).deep.equals([]); }); -}) - +}); |