();
- function listenError(e: ErrorMessage) {
- setError(e);
- }
- function listenInfo(m: TranslatedString) {
- setInfo(m);
- }
useEffect(() => {
- /**
- * Refactor this to reuse the pattern observable/listener
- */
- errorListeners.push(listenError);
- infoListeners.push(listenInfo);
- return function unsuscribe() {
- const idx = infoListeners.findIndex((d) => d === listenInfo);
- if (idx !== -1) {
- infoListeners.splice(idx, 1);
+ return onNotificationUpdate((newValue) => {
+ if (newValue === undefined) {
+ setInfo(undefined);
+ setError(undefined);
+ } else {
+ if (newValue.type === "error") {
+ setError(newValue.error);
+ } else {
+ setInfo(newValue.info);
+ }
}
- const idx2 = errorListeners.findIndex((d) => d === listenError);
- if (idx2 !== -1) {
- errorListeners.splice(idx2, 1);
- }
- };
+ });
}, []);
return (
void;
diff --git a/packages/demobank-ui/src/pages/HomePage.tsx b/packages/demobank-ui/src/pages/HomePage.tsx
index 2cdbc49bc..340181a4f 100644
--- a/packages/demobank-ui/src/pages/HomePage.tsx
+++ b/packages/demobank-ui/src/pages/HomePage.tsx
@@ -27,17 +27,11 @@ import {
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
import { Fragment, VNode, h } from "preact";
-import { StateUpdater } from "preact/hooks";
import { Loading } from "../components/Loading.js";
import { useBackendContext } from "../context/backend.js";
-import {
- ObservedStateType,
- PageStateType,
- notifyError,
- notifyInfo,
- usePageContext,
-} from "../context/pageState.js";
import { getInitialBackendBaseURL } from "../hooks/backend.js";
+import { notifyError, notifyInfo } from "../hooks/notification.js";
+import { useSettings } from "../hooks/settings.js";
import { AccountPage } from "./AccountPage.js";
import { AdminPage } from "./AdminPage.js";
import { LoginForm } from "./LoginForm.js";
@@ -63,15 +57,15 @@ export function HomePage({
onRegister: () => void;
}): VNode {
const backend = useBackendContext();
- const { pageState, pageStateSetter } = usePageContext();
+ const [settings] = useSettings();
const { i18n } = useTranslationContext();
if (backend.state.status === "loggedOut") {
return ;
}
- if (pageState.currentWithdrawalOperationId) {
- onPendingOperationFound(pageState.currentWithdrawalOperationId);
+ if (settings.currentWithdrawalOperationId) {
+ onPendingOperationFound(settings.currentWithdrawalOperationId);
return ;
}
@@ -104,9 +98,10 @@ export function WithdrawalOperationPage({
});
const parsedUri = parseWithdrawUri(uri);
const { i18n } = useTranslationContext();
- const { pageStateSetter } = usePageContext();
+
+ const [settings, updateSettings] = useSettings();
function clearCurrentWithdrawal(): void {
- pageStateSetter({});
+ updateSettings("currentWithdrawalOperationId", undefined);
onAbort();
}
diff --git a/packages/demobank-ui/src/pages/LoginForm.tsx b/packages/demobank-ui/src/pages/LoginForm.tsx
index 0ea001fe2..3e8aee259 100644
--- a/packages/demobank-ui/src/pages/LoginForm.tsx
+++ b/packages/demobank-ui/src/pages/LoginForm.tsx
@@ -19,11 +19,11 @@ import {
ErrorType,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
-import { Fragment, h, VNode } from "preact";
+import { Fragment, VNode, h } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
import { useBackendContext } from "../context/backend.js";
-import { ErrorMessage } from "../context/pageState.js";
import { useCredentialsChecker } from "../hooks/backend.js";
+import { ErrorMessage } from "../hooks/notification.js";
import { bankUiSettings } from "../settings.js";
import { undefinedIfEmpty } from "../utils.js";
import { ErrorBannerFloat } from "./BankFrame.js";
diff --git a/packages/demobank-ui/src/pages/PaymentOptions.tsx b/packages/demobank-ui/src/pages/PaymentOptions.tsx
index e0ad64e64..78e55928d 100644
--- a/packages/demobank-ui/src/pages/PaymentOptions.tsx
+++ b/packages/demobank-ui/src/pages/PaymentOptions.tsx
@@ -17,15 +17,11 @@
import { AmountJson } from "@gnu-taler/taler-util";
import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser";
import { h, VNode } from "preact";
-import { StateUpdater, useState } from "preact/hooks";
-import {
- notifyError,
- notifyInfo,
- PageStateType,
- usePageContext,
-} from "../context/pageState.js";
+import { useState } from "preact/hooks";
+import { notifyInfo } from "../hooks/notification.js";
import { PaytoWireTransferForm } from "./PaytoWireTransferForm.js";
import { WalletWithdrawForm } from "./WalletWithdrawForm.js";
+import { useSettings } from "../hooks/settings.js";
/**
* Let the user choose a payment option,
@@ -33,7 +29,7 @@ import { WalletWithdrawForm } from "./WalletWithdrawForm.js";
*/
export function PaymentOptions({ limit }: { limit: AmountJson }): VNode {
const { i18n } = useTranslationContext();
- const { pageStateSetter } = usePageContext();
+ const [settings, updateSettings] = useSettings();
const [tab, setTab] = useState<"charge-wallet" | "wire-transfer">(
"charge-wallet",
@@ -66,10 +62,8 @@ export function PaymentOptions({ limit }: { limit: AmountJson }): VNode {
{
- pageStateSetter({
- currentWithdrawalOperationId,
- });
+ onSuccess={(id) => {
+ updateSettings("currentWithdrawalOperationId", id);
}}
/>
diff --git a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx
index 5f16fbf6b..0bdceddb1 100644
--- a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx
+++ b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx
@@ -29,11 +29,7 @@ import {
} from "@gnu-taler/web-util/lib/index.browser";
import { h, VNode } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
-import {
- notifyError,
- ObservedStateType,
- PageStateType,
-} from "../context/pageState.js";
+import { notifyError } from "../hooks/notification.js";
import { useAccessAPI } from "../hooks/access.js";
import {
buildRequestErrorMessage,
diff --git a/packages/demobank-ui/src/pages/PublicHistoriesPage.tsx b/packages/demobank-ui/src/pages/PublicHistoriesPage.tsx
index 290fd0a79..256653dc5 100644
--- a/packages/demobank-ui/src/pages/PublicHistoriesPage.tsx
+++ b/packages/demobank-ui/src/pages/PublicHistoriesPage.tsx
@@ -15,33 +15,15 @@
*/
import { Logger } from "@gnu-taler/taler-util";
-import {
- HttpResponsePaginated,
- useLocalStorage,
- useTranslationContext,
-} from "@gnu-taler/web-util/lib/index.browser";
-import { Fragment, h, VNode } from "preact";
-import { StateUpdater } from "preact/hooks";
+import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser";
+import { Fragment, VNode, h } from "preact";
+import { useState } from "preact/hooks";
import { Transactions } from "../components/Transactions/index.js";
import { usePublicAccounts } from "../hooks/access.js";
-import {
- PageStateType,
- notifyError,
- usePageContext,
-} from "../context/pageState.js";
import { handleNotOkResult } from "./HomePage.js";
-import { Loading } from "../components/Loading.js";
const logger = new Logger("PublicHistoriesPage");
-// export function PublicHistoriesPage2(): VNode {
-// return (
-//
-//
-//
-// );
-// }
-
interface Props {
onLoadNotOk: () => void;
}
@@ -50,10 +32,16 @@ interface Props {
* Show histories of public accounts.
*/
export function PublicHistoriesPage({ onLoadNotOk }: Props): VNode {
- const [showAccount, setShowAccount] = useShowPublicAccount();
const { i18n } = useTranslationContext();
const result = usePublicAccounts();
+
+ const [showAccount, setShowAccount] = useState(
+ result.ok && result.data.publicAccounts.length > 0
+ ? result.data.publicAccounts[0].accountLabel
+ : undefined,
+ );
+
if (!result.ok) {
onLoadNotOk();
return handleNotOkResult(i18n)(result);
@@ -64,13 +52,6 @@ export function PublicHistoriesPage({ onLoadNotOk }: Props): VNode {
const txs: Record = {};
const accountsBar = [];
- /**
- * Show the account specified in the props, or just one
- * from the list if that's not given.
- */
- if (typeof showAccount === "undefined" && data.publicAccounts.length > 0) {
- setShowAccount(data.publicAccounts[1].accountLabel);
- }
logger.trace(`Public history tab: ${showAccount}`);
// Ask story of all the public accounts.
@@ -119,23 +100,3 @@ export function PublicHistoriesPage({ onLoadNotOk }: Props): VNode {
);
}
-
-/**
- * Stores in the state a object containing a 'username'
- * and 'password' field, in order to avoid losing the
- * handle of the data entered by the user in fields.
- */
-function useShowPublicAccount(
- state?: string,
-): [string | undefined, StateUpdater] {
- const ret = useLocalStorage("show-public-account", JSON.stringify(state));
- const retObj: string | undefined = ret[0] ? JSON.parse(ret[0]) : ret[0];
- const retSetter: StateUpdater = function (val) {
- const newVal =
- val instanceof Function
- ? JSON.stringify(val(retObj))
- : JSON.stringify(val);
- ret[1](newVal);
- };
- return [retObj, retSetter];
-}
diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx
index 5b9584dde..525fefbf5 100644
--- a/packages/demobank-ui/src/pages/RegistrationPage.tsx
+++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx
@@ -18,15 +18,11 @@ import {
RequestError,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
-import { Fragment, h, VNode } from "preact";
+import { Fragment, VNode, h } from "preact";
import { useState } from "preact/hooks";
import { useBackendContext } from "../context/backend.js";
-import {
- PageStateType,
- notifyError,
- usePageContext,
-} from "../context/pageState.js";
import { useTestingAPI } from "../hooks/access.js";
+import { notifyError } from "../hooks/notification.js";
import { bankUiSettings } from "../settings.js";
import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js";
import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js";
diff --git a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
index 7f3e207ac..c57a9b9c2 100644
--- a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
+++ b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
@@ -25,14 +25,10 @@ import {
RequestError,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
-import { h, VNode } from "preact";
+import { VNode, h } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
-import {
- ObservedStateType,
- PageStateType,
- notifyError,
-} from "../context/pageState.js";
import { useAccessAPI } from "../hooks/access.js";
+import { notifyError } from "../hooks/notification.js";
import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js";
import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js";
diff --git a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
index 10a37cd88..772b07b5f 100644
--- a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
+++ b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
@@ -23,14 +23,10 @@ import {
RequestError,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
-import { Fragment, h, VNode } from "preact";
+import { Fragment, VNode, h } from "preact";
import { useMemo, useState } from "preact/hooks";
-import {
- ObservedStateType,
- PageStateType,
- notifyError,
-} from "../context/pageState.js";
import { useAccessAnonAPI } from "../hooks/access.js";
+import { notifyError } from "../hooks/notification.js";
import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js";
import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js";
diff --git a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
index a20b2e90d..826578ffc 100644
--- a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
+++ b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx
@@ -21,20 +21,15 @@ import {
} from "@gnu-taler/taler-util";
import {
ErrorType,
- HttpResponsePaginated,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
-import { Fragment, h, VNode } from "preact";
+import { Fragment, VNode, h } from "preact";
import { Loading } from "../components/Loading.js";
-import {
- ObservedStateType,
- notifyError,
- notifyInfo,
-} from "../context/pageState.js";
import { useWithdrawalDetails } from "../hooks/access.js";
+import { notifyInfo } from "../hooks/notification.js";
+import { handleNotOkResult } from "./HomePage.js";
import { QrCodeSection } from "./QrCodeSection.js";
import { WithdrawalConfirmationQuestion } from "./WithdrawalConfirmationQuestion.js";
-import { handleNotOkResult } from "./HomePage.js";
const logger = new Logger("WithdrawalQRCode");
diff --git a/packages/demobank-ui/src/utils.ts b/packages/demobank-ui/src/utils.ts
index af0329555..e0aac8ecb 100644
--- a/packages/demobank-ui/src/utils.ts
+++ b/packages/demobank-ui/src/utils.ts
@@ -20,7 +20,7 @@ import {
HttpError,
useTranslationContext,
} from "@gnu-taler/web-util/lib/index.browser";
-import { ErrorMessage } from "./context/pageState.js";
+import { ErrorMessage } from "./hooks/notification.js";
/**
* Validate (the number part of) an amount. If needed,