summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/utils
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-07-21 10:36:15 -0300
committerSebastian <sebasjm@gmail.com>2022-07-21 10:36:30 -0300
commitf9ccb9415739864321f3ea482ce94695f775b9af (patch)
tree9c1641b93603bce2bd2a89b70fddd307aff71c2a /packages/taler-wallet-webextension/src/utils
parent84634a4ab4a61174f1d2e76b26d189bf92902c48 (diff)
downloadwallet-core-f9ccb9415739864321f3ea482ce94695f775b9af.tar.gz
wallet-core-f9ccb9415739864321f3ea482ce94695f775b9af.tar.bz2
wallet-core-f9ccb9415739864321f3ea482ce94695f775b9af.zip
withdraw as module
Diffstat (limited to 'packages/taler-wallet-webextension/src/utils')
-rw-r--r--packages/taler-wallet-webextension/src/utils/index.ts22
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;
+}