aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/hooks/config.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-10-01 12:50:43 -0300
committerSebastian <sebasjm@gmail.com>2023-10-01 12:50:43 -0300
commit372ddff91798cf9247eaf045f0d0ce33694fd880 (patch)
tree16af670c4bb95aec956210c7b5fc9777c385cf0c /packages/demobank-ui/src/hooks/config.ts
parent1708d49a2d5da1f325173a030695223e5a24e75c (diff)
render amount and limit input
Diffstat (limited to 'packages/demobank-ui/src/hooks/config.ts')
-rw-r--r--packages/demobank-ui/src/hooks/config.ts22
1 files changed, 15 insertions, 7 deletions
diff --git a/packages/demobank-ui/src/hooks/config.ts b/packages/demobank-ui/src/hooks/config.ts
index bb5134510..a3bd294db 100644
--- a/packages/demobank-ui/src/hooks/config.ts
+++ b/packages/demobank-ui/src/hooks/config.ts
@@ -18,13 +18,13 @@ async function getConfigState(
return result.data;
}
-type Result = undefined
- | { type: "ok", result: SandboxBackend.Config }
+export type ConfigResult = undefined
+ | { type: "ok", result: Required<SandboxBackend.Config> }
| { type: "wrong", result: SandboxBackend.Config }
| { type: "error", result: HttpError<SandboxBackend.SandboxError> }
-export function useConfigState(): Result {
- const [checked, setChecked] = useState<Result>()
+export function useConfigState(): ConfigResult {
+ const [checked, setChecked] = useState<ConfigResult>()
const { request } = useApiContext();
useEffect(() => {
@@ -32,15 +32,23 @@ export function useConfigState(): Result {
.then((result) => {
const r = LibtoolVersion.compare(BANK_INTEGRATION_PROTOCOL_VERSION, result.version)
if (r?.compatible) {
- setChecked({ type: "ok",result });
+ const complete: Required<SandboxBackend.Config> = {
+ currency_fraction_digits: result.currency_fraction_digits ?? 2,
+ currency_fraction_limit: result.currency_fraction_limit ?? 2,
+ fiat_currency: "",
+ have_cashout: result.have_cashout ?? false,
+ name: result.name,
+ version: result.version,
+ }
+ setChecked({ type: "ok", result: complete });
} else {
- setChecked({ type: "wrong",result })
+ setChecked({ type: "wrong", result })
}
})
.catch((error: unknown) => {
if (error instanceof RequestError) {
const result = error.cause
- setChecked({ type:"error", result });
+ setChecked({ type: "error", result });
}
});
}, []);