diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/InvoiceCreate')
3 files changed, 41 insertions, 39 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts index 0eefb2092..fe0b0f5f7 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts @@ -35,7 +35,6 @@ export type State = | State.Ready; export namespace State { - export interface Loading { status: "loading"; error: undefined; @@ -59,8 +58,8 @@ export namespace State { status: "ready"; create: ButtonHandler; subject: TextFieldHandler; - toBeReceived: AmountJson, - chosenAmount: AmountJson, + toBeReceived: AmountJson; + chosenAmount: AmountJson; exchangeUrl: string; invalid: boolean; error: undefined; @@ -71,10 +70,12 @@ export namespace State { const viewMapping: StateViewMap<State> = { loading: Loading, "loading-uri": LoadingUriView, - "created": CreatedView, - "ready": ReadyView, + created: CreatedView, + ready: ReadyView, }; - -export const InvoiceCreatePage = compose("InvoiceCreatePage", (p: Props) => useComponentState(p, wxApi), viewMapping) - +export const InvoiceCreatePage = compose( + "InvoiceCreatePage", + (p: Props) => useComponentState(p, wxApi), + viewMapping, +); diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts index 804d216eb..8f57582d6 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts @@ -25,21 +25,22 @@ 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 [talerUri, setTalerUri] = useState(""); const hook = useAsyncAsHook(api.listExchanges); - const [exchangeIdx, setExchangeIdx] = useState("0") - const [operationError, setOperationError] = useState<TalerErrorDetail | undefined>(undefined) - + const [exchangeIdx, setExchangeIdx] = useState("0"); + const [operationError, setOperationError] = useState< + TalerErrorDetail | undefined + >(undefined); if (!hook) { return { status: "loading", error: undefined, - } + }; } if (hook.hasError) { return { @@ -54,62 +55,65 @@ export function useComponentState( talerUri, error: undefined, cancel: { - onClick: onClose + onClick: onClose, }, copyToClipboard: { onClick: async () => { navigator.clipboard.writeText(talerUri); - } + }, }, - } + }; } - const exchanges = hook.response.exchanges.filter(e => e.currency === amount.currency); - const exchangeMap = exchanges.reduce((prev, cur, idx) => ({ ...prev, [String(idx)]: cur.exchangeBaseUrl }), {} as Record<string, string>) + const exchanges = hook.response.exchanges.filter( + (e) => e.currency === amount.currency, + ); + const exchangeMap = exchanges.reduce( + (prev, cur, idx) => ({ ...prev, [String(idx)]: cur.exchangeBaseUrl }), + {} as Record<string, string>, + ); const selected = exchanges[Number(exchangeIdx)]; async function accept(): Promise<string> { try { - const resp = await api.initiatePeerPullPayment({ amount: Amounts.stringify(amount), exchangeBaseUrl: selected.exchangeBaseUrl, 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 { status: "ready", subject: { error: !subject ? "cant be empty" : undefined, value: subject, - onInput: async (e) => setSubject(e) + onInput: async (e) => setSubject(e), }, invalid: !subject || Amounts.isZero(amount), exchangeUrl: selected.exchangeBaseUrl, create: { onClick: async () => { const uri = await accept(); - setTalerUri(uri) - } + setTalerUri(uri); + }, }, cancel: { - onClick: onClose + onClick: onClose, }, chosenAmount: amount, toBeReceived: amount, error: undefined, - operationError - } + operationError, + }; } diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/test.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/test.ts index 631e76d01..eae4d4ca2 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/test.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/test.ts @@ -22,10 +22,7 @@ import { expect } from "chai"; describe("test description", () => { - it("should assert", () => { - - expect([]).deep.equals([]) + expect([]).deep.equals([]); }); -}) - +}); |