diff options
author | Sebastian <sebasjm@gmail.com> | 2023-09-25 12:18:59 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-09-25 14:50:46 -0300 |
commit | 820f953b96b2b2852c32dc16a2fa920c6c717788 (patch) | |
tree | 584cbc88f22e4900d5e1a87156f7a05a4ecfc636 /packages/demobank-ui/src/hooks | |
parent | 4041a76a58503572c6fe8edc87658afc946a11e0 (diff) | |
download | wallet-core-820f953b96b2b2852c32dc16a2fa920c6c717788.tar.xz |
check config number
Diffstat (limited to 'packages/demobank-ui/src/hooks')
-rw-r--r-- | packages/demobank-ui/src/hooks/config.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/packages/demobank-ui/src/hooks/config.ts b/packages/demobank-ui/src/hooks/config.ts new file mode 100644 index 000000000..4b22e8ad3 --- /dev/null +++ b/packages/demobank-ui/src/hooks/config.ts @@ -0,0 +1,51 @@ +import { LibtoolVersion } from "@gnu-taler/taler-util"; +import { useApiContext } from "@gnu-taler/web-util/browser"; +import { useEffect, useState } from "preact/hooks"; +import { getInitialBackendBaseURL } from "./backend.js"; + +/** + * Protocol version spoken with the bank. + * + * Uses libtool's current:revision:age versioning. + */ +export const BANK_INTEGRATION_PROTOCOL_VERSION = "0:0:0"; + +async function getConfigState( + request: ReturnType<typeof useApiContext>["request"], +): Promise<SandboxBackend.Config | undefined> { + try { + const url = getInitialBackendBaseURL(); + const result = await request<SandboxBackend.Config>( + url, + `config`, + ); + return result.data; + } catch (error) { + return undefined; + } +} + +export function useConfigState(): boolean | undefined { + const [checked, setChecked] = useState<boolean>() + const { request } = useApiContext(); + + useEffect(() => { + + getConfigState(request) + .then((result) => { + if (!result) { + setChecked(false) + } else { + const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, result.version) + setChecked(r?.compatible); + } + }) + .catch((error) => { + setChecked(false); + }); + }); + + return checked; +} + + |