aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/utils/converter.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/aml-backoffice-ui/src/utils/converter.ts')
-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!;
+}