diff options
author | Sebastian <sebasjm@gmail.com> | 2023-05-25 18:08:20 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-05-26 09:26:09 -0300 |
commit | 64e3705669e7c12b8013704654f17cf8eaf659d4 (patch) | |
tree | b0572d228b34740f307da4c59e6e5fa0e3e1f808 /packages/exchange-backoffice-ui/src/handlers/InputAmount.tsx | |
parent | dad7d48ed2d7cd6f17466889395b49023e4b5097 (diff) |
cases, account details and new-form screen
Diffstat (limited to 'packages/exchange-backoffice-ui/src/handlers/InputAmount.tsx')
-rw-r--r-- | packages/exchange-backoffice-ui/src/handlers/InputAmount.tsx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/exchange-backoffice-ui/src/handlers/InputAmount.tsx b/packages/exchange-backoffice-ui/src/handlers/InputAmount.tsx new file mode 100644 index 000000000..9be9dd4d0 --- /dev/null +++ b/packages/exchange-backoffice-ui/src/handlers/InputAmount.tsx @@ -0,0 +1,34 @@ +import { AmountJson, Amounts, TranslatedString } from "@gnu-taler/taler-util"; +import { VNode, h } from "preact"; +import { InputLine, UIFormProps } from "./InputLine.js"; +import { useField } from "./useField.js"; + +export function InputAmount<T extends object, K extends keyof T>( + props: { currency?: string } & UIFormProps<T, K>, +): VNode { + const { value } = useField<T, K>(props.name); + const currency = + !value || !(value as any).currency + ? props.currency + : (value as any).currency; + return ( + <InputLine<T, K> + type="text" + before={{ + type: "text", + text: currency as TranslatedString, + }} + converter={{ + //@ts-ignore + fromStringUI: (v): AmountJson => { + return Amounts.parseOrThrow(`${currency}:${v}`); + }, + //@ts-ignore + toStringUI: (v: AmountJson) => { + return v === undefined ? "" : Amounts.stringifyValue(v); + }, + }} + {...props} + /> + ); +} |