diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/TransferCreate')
3 files changed, 31 insertions, 33 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts index c23d42e11..1794b837b 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts @@ -35,7 +35,6 @@ export type State = | State.Ready; export namespace State { - export interface Loading { status: "loading"; error: undefined; @@ -59,9 +58,9 @@ export namespace State { status: "ready"; invalid: boolean; create: ButtonHandler; - toBeReceived: AmountJson, - chosenAmount: AmountJson, - subject: TextFieldHandler, + toBeReceived: AmountJson; + chosenAmount: AmountJson; + subject: TextFieldHandler; error: undefined; operationError?: TalerErrorDetail; } @@ -70,10 +69,12 @@ export namespace State { const viewMapping: StateViewMap<State> = { loading: Loading, "loading-uri": LoadingUriView, - "created": CreatedView, - "ready": ReadyView, + created: CreatedView, + ready: ReadyView, }; - -export const TransferCreatePage = compose("TransferCreatePage", (p: Props) => useComponentState(p, wxApi), viewMapping) - +export const TransferCreatePage = compose( + "TransferCreatePage", + (p: Props) => useComponentState(p, wxApi), + viewMapping, +); diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts index f11526c0e..e6397f2e9 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts @@ -24,11 +24,13 @@ export function useComponentState( { amount: amountStr, onClose }: Props, api: typeof wxApi, ): State { - const amount = Amounts.parseOrThrow(amountStr) + const amount = Amounts.parseOrThrow(amountStr); const [subject, setSubject] = useState(""); - const [talerUri, setTalerUri] = useState("") - const [operationError, setOperationError] = useState<TalerErrorDetail | undefined>(undefined) + const [talerUri, setTalerUri] = useState(""); + const [operationError, setOperationError] = useState< + TalerErrorDetail | undefined + >(undefined); if (talerUri) { return { @@ -41,28 +43,26 @@ export function useComponentState( copyToClipboard: { onClick: async () => { navigator.clipboard.writeText(talerUri); - } + }, }, - } + }; } - async function accept(): Promise<string> { try { - const resp = await api.initiatePeerPushPayment({ amount: Amounts.stringify(amount), partialContractTerms: { - summary: subject - } - }) - return resp.talerUri + summary: subject, + }, + }); + return resp.talerUri; } 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 { @@ -74,17 +74,17 @@ export function useComponentState( subject: { error: !subject ? "cant be empty" : undefined, value: subject, - onInput: async (e) => setSubject(e) + onInput: async (e) => setSubject(e), }, create: { onClick: async () => { const uri = await accept(); - setTalerUri(uri) - } + setTalerUri(uri); + }, }, chosenAmount: amount, toBeReceived: amount, error: undefined, - operationError - } + operationError, + }; } diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/test.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/test.ts index 631e76d01..eae4d4ca2 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/test.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/test.ts @@ -22,10 +22,7 @@ import { expect } from "chai"; describe("test description", () => { - it("should assert", () => { - - expect([]).deep.equals([]) + expect([]).deep.equals([]); }); -}) - +}); |