aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/hooks/config.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/hooks/config.ts')
-rw-r--r--packages/demobank-ui/src/hooks/config.ts20
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 });
}
});
}, []);