diff options
Diffstat (limited to 'packages/demobank-ui/src/settings.ts')
-rw-r--r-- | packages/demobank-ui/src/settings.ts | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/packages/demobank-ui/src/settings.ts b/packages/demobank-ui/src/settings.ts index 7c7b04424..91790d10d 100644 --- a/packages/demobank-ui/src/settings.ts +++ b/packages/demobank-ui/src/settings.ts @@ -14,7 +14,14 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { Codec, buildCodecForObject, codecForBoolean, codecForList, codecForMap, codecForString, codecOptional } from "@gnu-taler/taler-util"; +import { + Codec, + buildCodecForObject, + codecForBoolean, + codecForMap, + codecForString, + codecOptional, +} from "@gnu-taler/taler-util"; export interface BankUiSettings { // Where libeufin backend is localted @@ -31,7 +38,7 @@ export interface BankUiSettings { // Bank name shown in the header // default: "Taler Bank" bankName?: string; - // URL where the user is going to be redirected after + // URL where the user is going to be redirected after // clicking in Taler Logo // default: home page iconLinkURL?: string; @@ -58,41 +65,48 @@ const codecForBankUISettings = (): Codec<BankUiSettings> => buildCodecForObject<BankUiSettings>() .property("backendBaseURL", codecOptional(codecForString())) .property("allowRandomAccountCreation", codecOptional(codecForBoolean())) - .property("simplePasswordForRandomAccounts", codecOptional(codecForBoolean())) + .property( + "simplePasswordForRandomAccounts", + codecOptional(codecForBoolean()), + ) .property("bankName", codecOptional(codecForString())) .property("iconLinkURL", codecOptional(codecForString())) .property("topNavSites", codecOptional(codecForMap(codecForString()))) .build("BankUiSettings"); -function removeUndefineField(obj: any): object { - return Object.keys(obj).reduce((prev, cur) => { +function removeUndefineField<T extends object>(obj: T): T { + const keys = Object.keys(obj) as Array<keyof T>; + return keys.reduce((prev, cur) => { if (typeof prev[cur] === "undefined") { - delete prev[cur] + delete prev[cur]; } - return prev - }, obj) + return prev; + }, obj); } export function fetchSettings(listener: (s: BankUiSettings) => void): void { fetch("./settings.json") - .then(resp => resp.json()) - .then(json => codecForBankUISettings().decode(json)) - .then(result => listener({ - ...defaultSettings, - ...removeUndefineField(result), - })) - .catch(e => { - console.log("failed to fetch settings", e) - listener(defaultSettings) - }) + .then((resp) => resp.json()) + .then((json) => codecForBankUISettings().decode(json)) + .then((result) => + listener({ + ...defaultSettings, + ...removeUndefineField(result), + }), + ) + .catch((e) => { + console.log("failed to fetch settings", e); + listener(defaultSettings); + }); } - - function buildDefaultBackendBaseURL(): string | undefined { if (typeof window !== "undefined") { - const currentLocation = new URL(window.location.pathname, window.location.origin).href - return currentLocation.replace("/webui", "") + const currentLocation = new URL( + window.location.pathname, + window.location.origin, + ).href; + return currentLocation.replace("/webui", ""); } - return undefined + return undefined; } |