diff options
author | Sebastian <sebasjm@gmail.com> | 2022-07-21 10:36:15 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-07-21 10:36:30 -0300 |
commit | f9ccb9415739864321f3ea482ce94695f775b9af (patch) | |
tree | 9c1641b93603bce2bd2a89b70fddd307aff71c2a /packages/taler-wallet-webextension/src/utils/index.ts | |
parent | 84634a4ab4a61174f1d2e76b26d189bf92902c48 (diff) | |
download | wallet-core-f9ccb9415739864321f3ea482ce94695f775b9af.tar.xz |
withdraw as module
Diffstat (limited to 'packages/taler-wallet-webextension/src/utils/index.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/utils/index.ts | 22 |
1 files changed, 22 insertions, 0 deletions
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<any> { if (r.ok) { @@ -190,3 +191,24 @@ export interface TermsDocumentPdf { type: "pdf"; location: URL; } + +export type StateFunc<S> = (p: S) => VNode; + +export type StateViewMap<StateType extends { status: string }> = { + [S in StateType as S["status"]]: StateFunc<S>; +}; + +export function compose<SType extends { status: string }, PType>( + name: string, + hook: (p: PType) => SType, + vs: StateViewMap<SType>, +): (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<SType>; + return c(state); + }; + Component.name = `${name}`; + return Component; +} |