aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-12-07 18:45:49 -0300
committerSebastian <sebasjm@gmail.com>2022-12-07 18:45:49 -0300
commit4fbc22b94a4a72f37faa3beff68f85ce4fdcd2ea (patch)
tree735edc8b2cefe0e5869eb391cfc8f25c572a692d
parentc2a982e575b532c52514e7343bdd3aaaac655b5f (diff)
pretty
-rw-r--r--packages/demobank-ui/src/context/backend.ts12
-rw-r--r--packages/demobank-ui/src/hooks/backend.ts31
-rw-r--r--packages/demobank-ui/src/utils.ts7
3 files changed, 29 insertions, 21 deletions
diff --git a/packages/demobank-ui/src/context/backend.ts b/packages/demobank-ui/src/context/backend.ts
index b9b7f8527..1c40506c9 100644
--- a/packages/demobank-ui/src/context/backend.ts
+++ b/packages/demobank-ui/src/context/backend.ts
@@ -16,7 +16,11 @@
import { ComponentChildren, createContext, h, VNode } from "preact";
import { useContext } from "preact/hooks";
-import { BackendStateHandler, defaultState, useBackendState } from "../hooks/backend.js";
+import {
+ BackendStateHandler,
+ defaultState,
+ useBackendState,
+} from "../hooks/backend.js";
/**
*
@@ -28,10 +32,10 @@ export type Type = BackendStateHandler;
const initial: Type = {
state: defaultState,
clear() {
- null
+ null;
},
save(info) {
- null
+ null;
},
};
const Context = createContext<Type>(initial);
@@ -49,4 +53,4 @@ export const BackendStateProvider = ({
value,
children,
});
-}; \ No newline at end of file
+};
diff --git a/packages/demobank-ui/src/hooks/backend.ts b/packages/demobank-ui/src/hooks/backend.ts
index 967d5ee85..babdcd830 100644
--- a/packages/demobank-ui/src/hooks/backend.ts
+++ b/packages/demobank-ui/src/hooks/backend.ts
@@ -4,7 +4,7 @@ import { hooks } from "@gnu-taler/web-util/lib/index.browser";
* Has the information to reach and
* authenticate at the bank's backend.
*/
-export type BackendState = LoggedIn | LoggedOut
+export type BackendState = LoggedIn | LoggedOut;
export interface BackendInfo {
url: string;
@@ -13,16 +13,16 @@ export interface BackendInfo {
}
interface LoggedIn extends BackendInfo {
- status: "loggedIn"
+ status: "loggedIn";
}
interface LoggedOut {
- status: "loggedOut"
+ status: "loggedOut";
}
-export const defaultState: BackendState = { status: "loggedOut" }
+export const defaultState: BackendState = { status: "loggedOut" };
export interface BackendStateHandler {
- state: BackendState,
+ state: BackendState;
clear(): void;
save(info: BackendInfo): void;
}
@@ -32,24 +32,27 @@ export interface BackendStateHandler {
* base URL.
*/
export function useBackendState(): BackendStateHandler {
- const [value, update] = hooks.useLocalStorage("backend-state", JSON.stringify(defaultState));
+ const [value, update] = hooks.useLocalStorage(
+ "backend-state",
+ JSON.stringify(defaultState),
+ );
// const parsed = value !== undefined ? JSON.parse(value) : value;
- let parsed
+ let parsed;
try {
- parsed = JSON.parse(value!)
+ parsed = JSON.parse(value!);
} catch {
- parsed = undefined
+ parsed = undefined;
}
- const state: BackendState = !parsed?.status ? defaultState : parsed
+ const state: BackendState = !parsed?.status ? defaultState : parsed;
return {
state,
clear() {
- update(JSON.stringify(defaultState))
+ update(JSON.stringify(defaultState));
},
save(info) {
- const nextState: BackendState = { status: "loggedIn", ...info }
- update(JSON.stringify(nextState))
+ const nextState: BackendState = { status: "loggedIn", ...info };
+ update(JSON.stringify(nextState));
},
- }
+ };
}
diff --git a/packages/demobank-ui/src/utils.ts b/packages/demobank-ui/src/utils.ts
index 223dbe707..f769bca9a 100644
--- a/packages/demobank-ui/src/utils.ts
+++ b/packages/demobank-ui/src/utils.ts
@@ -6,7 +6,9 @@ import { canonicalizeBaseUrl } from "@gnu-taler/taler-util";
* the input is invalid, the valid amount otherwise.
*/
const amountRegex = /^[0-9]+(.[0-9]+)?$/;
-export function validateAmount(maybeAmount: string | undefined): string | undefined {
+export function validateAmount(
+ maybeAmount: string | undefined,
+): string | undefined {
if (!maybeAmount || !amountRegex.test(maybeAmount)) {
return;
}
@@ -29,8 +31,7 @@ const maybeRootPath = "https://bank.demo.taler.net/demobanks/default/";
export function getBankBackendBaseUrl(): string {
const overrideUrl = localStorage.getItem("bank-base-url");
- return canonicalizeBaseUrl(overrideUrl ? overrideUrl : maybeRootPath)
-
+ return canonicalizeBaseUrl(overrideUrl ? overrideUrl : maybeRootPath);
}
export function undefinedIfEmpty<T extends object>(obj: T): T | undefined {