aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/utils
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-05-03 08:43:53 -0300
committerSebastian <sebasjm@gmail.com>2024-05-03 08:44:07 -0300
commit20353eda268efa962959bead466b59823bfb9b29 (patch)
tree868d016693f09b40e2c55893d3aed72eca505ecb /packages/aml-backoffice-ui/src/utils
parentfa4c7039f4ebeb6ad3cf19237ad7b138519ac142 (diff)
downloadwallet-core-20353eda268efa962959bead466b59823bfb9b29.tar.xz
form hook now takes the shape of the form (do not rely on initial value)
Diffstat (limited to 'packages/aml-backoffice-ui/src/utils')
-rw-r--r--packages/aml-backoffice-ui/src/utils/converter.ts25
1 files changed, 24 insertions, 1 deletions
diff --git a/packages/aml-backoffice-ui/src/utils/converter.ts b/packages/aml-backoffice-ui/src/utils/converter.ts
index cca764a81..25a824697 100644
--- a/packages/aml-backoffice-ui/src/utils/converter.ts
+++ b/packages/aml-backoffice-ui/src/utils/converter.ts
@@ -14,7 +14,8 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { TalerExchangeApi } from "@gnu-taler/taler-util";
+import { AmountJson, Amounts, TalerExchangeApi } from "@gnu-taler/taler-util";
+import { StringConverter } from "@gnu-taler/web-util/browser";
export const amlStateConverter = {
toStringUI: stringifyAmlState,
@@ -45,3 +46,25 @@ function parseAmlState(s: string | undefined): TalerExchangeApi.AmlState {
throw Error(`unknown AML state: ${s}`);
}
}
+
+const amountConverter: StringConverter<AmountJson> = {
+ fromStringUI(v: string | undefined): AmountJson {
+ // FIXME: requires currency
+ return Amounts.parse(`NETZBON:${v}`) ?? Amounts.zeroOfCurrency("NETZBON");
+ },
+ toStringUI(v: unknown): string {
+ return v === undefined ? "" : Amounts.stringifyValue(v as AmountJson);
+ },
+};
+
+export function getConverterById(id: string | undefined): StringConverter<unknown> {
+ if (id === "Taler.Amount") {
+ // @ts-expect-error check this
+ return amountConverter;
+ }
+ if (id === "TalerExchangeApi.AmlState") {
+ // @ts-expect-error check this
+ return amlStateConverter;
+ }
+ return undefined!;
+}