summaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/hooks/preferences.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/hooks/preferences.ts')
-rw-r--r--packages/demobank-ui/src/hooks/preferences.ts67
1 files changed, 36 insertions, 31 deletions
diff --git a/packages/demobank-ui/src/hooks/preferences.ts b/packages/demobank-ui/src/hooks/preferences.ts
index 454d840b2..454dc8d80 100644
--- a/packages/demobank-ui/src/hooks/preferences.ts
+++ b/packages/demobank-ui/src/hooks/preferences.ts
@@ -36,36 +36,6 @@ interface Preferences {
showDebugInfo: boolean;
}
-export function getAllBooleanPreferences(): Array<keyof Preferences> {
- return [
- "fastWithdrawal",
- "showDebugInfo",
- "showDemoDescription",
- "showInstallWallet",
- "showWithdrawalSuccess",
- ];
-}
-
-export function getLabelForPreferences(
- k: keyof Preferences,
- i18n: ReturnType<typeof useTranslationContext>["i18n"],
-): TranslatedString {
- switch (k) {
- case "maxWithdrawalAmount":
- return i18n.str`Max withdrawal amount`;
- case "showWithdrawalSuccess":
- return i18n.str`Show withdrawal confirmation`;
- case "showDemoDescription":
- return i18n.str`Show demo description`;
- case "showInstallWallet":
- return i18n.str`Show install wallet first`;
- case "fastWithdrawal":
- return i18n.str`Use fast withdrawal form`;
- case "showDebugInfo":
- return i18n.str`Show debug info`;
- }
-}
-
export const codecForPreferences = (): Codec<Preferences> =>
buildCodecForObject<Preferences>()
.property("showWithdrawalSuccess", codecForBoolean())
@@ -89,7 +59,11 @@ const BANK_PREFERENCES_KEY = buildStorageKey(
"bank-preferences",
codecForPreferences(),
);
-
+/**
+ * User preferences.
+ *
+ * @returns tuple of [state, update()]
+ */
export function usePreferences(): [
Readonly<Preferences>,
<T extends keyof Preferences>(key: T, value: Preferences[T]) => void,
@@ -105,3 +79,34 @@ export function usePreferences(): [
}
return [value, updateField];
}
+
+export function getAllBooleanPreferences(): Array<keyof Preferences> {
+ return [
+ "fastWithdrawal",
+ "showDebugInfo",
+ "showDemoDescription",
+ "showInstallWallet",
+ "showWithdrawalSuccess",
+ ];
+}
+
+export function getLabelForPreferences(
+ k: keyof Preferences,
+ i18n: ReturnType<typeof useTranslationContext>["i18n"],
+): TranslatedString {
+ switch (k) {
+ case "maxWithdrawalAmount":
+ return i18n.str`Max withdrawal amount`;
+ case "showWithdrawalSuccess":
+ return i18n.str`Show withdrawal confirmation`;
+ case "showDemoDescription":
+ return i18n.str`Show demo description`;
+ case "showInstallWallet":
+ return i18n.str`Show install wallet first`;
+ case "fastWithdrawal":
+ return i18n.str`Use fast withdrawal form`;
+ case "showDebugInfo":
+ return i18n.str`Show debug info`;
+ }
+}
+