diff options
author | Sebastian <sebasjm@gmail.com> | 2023-09-26 15:18:43 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-09-26 15:18:43 -0300 |
commit | 1e4f21cc76345f3881ea8e5ea0e94d27d26da609 (patch) | |
tree | 4f921a15b8b146adf479e0068639a49553da4cc1 /packages/demobank-ui/src/hooks/config.ts | |
parent | dcdf8fb6a067b4e40b13f1c0f106758cfba76309 (diff) |
lang selector and fix logout
Diffstat (limited to 'packages/demobank-ui/src/hooks/config.ts')
-rw-r--r-- | packages/demobank-ui/src/hooks/config.ts | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/packages/demobank-ui/src/hooks/config.ts b/packages/demobank-ui/src/hooks/config.ts index 4cf677d35..bb5134510 100644 --- a/packages/demobank-ui/src/hooks/config.ts +++ b/packages/demobank-ui/src/hooks/config.ts @@ -18,23 +18,29 @@ async function getConfigState( return result.data; } -export function useConfigState(): undefined | true | string | HttpError<SandboxBackend.SandboxError> { - const [checked, setChecked] = useState<true | string | HttpError<SandboxBackend.SandboxError>>() +type Result = undefined + | { type: "ok", result: SandboxBackend.Config } + | { type: "wrong", result: SandboxBackend.Config } + | { type: "error", result: HttpError<SandboxBackend.SandboxError> } + +export function useConfigState(): Result { + const [checked, setChecked] = useState<Result>() const { request } = useApiContext(); useEffect(() => { getConfigState(request) - .then((s) => { - const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, s.version) + .then((result) => { + const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, result.version) if (r?.compatible) { - setChecked(true); + setChecked({ type: "ok",result }); } else { - setChecked(s.version) + setChecked({ type: "wrong",result }) } }) .catch((error: unknown) => { if (error instanceof RequestError) { - setChecked(error.cause); + const result = error.cause + setChecked({ type:"error", result }); } }); }, []); |