aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/AccountPage/state.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/pages/AccountPage/state.ts')
-rw-r--r--packages/demobank-ui/src/pages/AccountPage/state.ts51
1 files changed, 22 insertions, 29 deletions
diff --git a/packages/demobank-ui/src/pages/AccountPage/state.ts b/packages/demobank-ui/src/pages/AccountPage/state.ts
index ca7e1d447..96d45b7bd 100644
--- a/packages/demobank-ui/src/pages/AccountPage/state.ts
+++ b/packages/demobank-ui/src/pages/AccountPage/state.ts
@@ -14,54 +14,47 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { Amounts, HttpStatusCode, parsePaytoUri } from "@gnu-taler/taler-util";
+import { Amounts, HttpStatusCode, TalerError, TalerErrorCode, parsePaytoUri } from "@gnu-taler/taler-util";
import { ErrorType, notifyError, useTranslationContext } from "@gnu-taler/web-util/browser";
-import { useBackendContext } from "../../context/backend.js";
import { useAccountDetails } from "../../hooks/access.js";
import { Props, State } from "./index.js";
+import { assertUnreachable } from "../HomePage.js";
export function useComponentState({ account, goToBusinessAccount, goToConfirmOperation }: Props): State {
const result = useAccountDetails(account);
- const backend = useBackendContext();
const { i18n } = useTranslationContext();
- if (result.loading) {
+ if (!result) {
return {
status: "loading",
error: undefined,
};
}
- if (!result.ok) {
- if (result.loading || result.type === ErrorType.TIMEOUT) {
- return {
- status: "loading-error",
- error: result,
- };
- }
- //logout if there is any error, not if loading
- // backend.logOut();
- if (result.status === HttpStatusCode.NotFound) {
- notifyError(i18n.str`Username or account label "${account}" not found`, undefined);
- return {
- status: "error-user-not-found",
- error: result,
- };
- }
- if (result.status === HttpStatusCode.Unauthorized) {
- notifyError(i18n.str`Authorization denied`, i18n.str`Maybe the session has expired, login again.`);
- return {
- status: "error-user-not-found",
- error: result,
- };
- }
+ if (result instanceof TalerError) {
return {
status: "loading-error",
error: result,
};
}
- const { data } = result;
+ if (result.type === "fail") {
+ switch (result.case) {
+ case "unauthorized": return {
+ status: "login",
+ reason: "forbidden"
+ }
+ case "not-found": return {
+ status: "login",
+ reason: "not-found",
+ }
+ default: {
+ assertUnreachable(result)
+ }
+ }
+ }
+
+ const { body: data } = result;
const balance = Amounts.parseOrThrow(data.balance.amount);
@@ -71,7 +64,7 @@ export function useComponentState({ account, goToBusinessAccount, goToConfirmOpe
if (!payto || !payto.isKnown || (payto.targetType !== "iban" && payto.targetType !== "x-taler-bank")) {
return {
status: "invalid-iban",
- error: result
+ error: data
};
}