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/TransferCreate/state.ts | |
parent | 860f10e6f004668d3109b5a1d96ddb2b26ddc2f5 (diff) | |
download | wallet-core-6ddb2de84245ae3914c92b2b2eb7399e7f04500e.tar.xz |
pretty
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts | 38 |
1 files changed, 19 insertions, 19 deletions
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, + }; } |