From f9ccb9415739864321f3ea482ce94695f775b9af Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 21 Jul 2022 10:36:15 -0300 Subject: withdraw as module --- .../taler-wallet-webextension/src/utils/index.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'packages/taler-wallet-webextension/src/utils') diff --git a/packages/taler-wallet-webextension/src/utils/index.ts b/packages/taler-wallet-webextension/src/utils/index.ts index aab748f90..a48352840 100644 --- a/packages/taler-wallet-webextension/src/utils/index.ts +++ b/packages/taler-wallet-webextension/src/utils/index.ts @@ -19,6 +19,7 @@ import { Amounts, GetExchangeTosResult, } from "@gnu-taler/taler-util"; +import { VNode } from "preact"; function getJsonIfOk(r: Response): Promise { if (r.ok) { @@ -190,3 +191,24 @@ export interface TermsDocumentPdf { type: "pdf"; location: URL; } + +export type StateFunc = (p: S) => VNode; + +export type StateViewMap = { + [S in StateType as S["status"]]: StateFunc; +}; + +export function compose( + name: string, + hook: (p: PType) => SType, + vs: StateViewMap, +): (p: PType) => VNode { + const Component = (p: PType): VNode => { + const state = hook(p); + const s = state.status as unknown as SType["status"]; + const c = vs[s] as unknown as StateFunc; + return c(state); + }; + Component.name = `${name}`; + return Component; +} -- cgit v1.2.3