diff options
author | Sebastian <sebasjm@gmail.com> | 2023-04-07 17:30:01 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-04-07 17:30:01 -0300 |
commit | a3aa7d95d09c83794067c47df4a455c0e3f21806 (patch) | |
tree | 00837196305227fe6f7cbc7289f96b256d5de089 /packages/demobank-ui/src/pages/Routing.tsx | |
parent | 43ae414a55b84b1125c5e4377c6d485ca6c748e2 (diff) | |
download | wallet-core-a3aa7d95d09c83794067c47df4a455c0e3f21806.tar.xz |
anon withdrawal confirmation, and fix error with infinity loop
Diffstat (limited to 'packages/demobank-ui/src/pages/Routing.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/Routing.tsx | 177 |
1 files changed, 58 insertions, 119 deletions
diff --git a/packages/demobank-ui/src/pages/Routing.tsx b/packages/demobank-ui/src/pages/Routing.tsx index 8234d8988..27aae69e9 100644 --- a/packages/demobank-ui/src/pages/Routing.tsx +++ b/packages/demobank-ui/src/pages/Routing.tsx @@ -14,140 +14,77 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { - ErrorType, - HttpResponsePaginated, - useTranslationContext, -} from "@gnu-taler/web-util/lib/index.browser"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { createHashHistory } from "history"; -import { h, VNode } from "preact"; -import { Router, route, Route } from "preact-router"; -import { useEffect } from "preact/hooks"; -import { Loading } from "../components/Loading.js"; -import { PageStateType, usePageContext } from "../context/pageState.js"; -import { HomePage } from "./HomePage.js"; +import { VNode, h } from "preact"; +import { Route, Router, route } from "preact-router"; +import { useEffect, useMemo, useState } from "preact/hooks"; import { BankFrame } from "./BankFrame.js"; +import { BusinessAccount } from "./BusinessAccount.js"; +import { HomePage, WithdrawalOperationPage } from "./HomePage.js"; import { PublicHistoriesPage } from "./PublicHistoriesPage.js"; import { RegistrationPage } from "./RegistrationPage.js"; -import { BusinessAccount } from "./BusinessAccount.js"; - -function handleNotOkResult( - safe: string, - saveError: (state: PageStateType["error"]) => void, - i18n: ReturnType<typeof useTranslationContext>["i18n"], -): <T>(result: HttpResponsePaginated<T, SandboxBackend.SandboxError>) => VNode { - return function handleNotOkResult2<T>( - result: HttpResponsePaginated<T, SandboxBackend.SandboxError>, - ): VNode { - if (result.clientError && result.isUnauthorized) { - route(safe); - return <Loading />; - } - if (result.clientError && result.isNotfound) { - route(safe); - return ( - <div>Page not found, you are going to be redirected to {safe}</div> - ); - } - if (result.loading) return <Loading />; - if (!result.ok) { - switch (result.type) { - case ErrorType.TIMEOUT: { - saveError({ - title: i18n.str`Request timeout, try again later.`, - }); - break; - } - case ErrorType.CLIENT: { - const errorData = result.error; - saveError({ - title: i18n.str`Could not load due to a client error`, - description: errorData.error.description, - debug: JSON.stringify(result), - }); - break; - } - case ErrorType.SERVER: { - const errorData = result.error; - saveError({ - title: i18n.str`Server returned with error`, - description: errorData.error.description, - debug: JSON.stringify(result), - }); - break; - } - case ErrorType.UNEXPECTED: { - saveError({ - title: i18n.str`Unexpected error.`, - description: `Diagnostic from ${result.info?.url} is "${result.message}"`, - debug: JSON.stringify(result.error), - }); - break; - } - default: - { - assertUnreachable(result); - } - route(safe); - } - } - return <div />; - }; -} export function Routing(): VNode { const history = createHashHistory(); - const { pageStateSetter } = usePageContext(); - function saveError(error: PageStateType["error"]): void { - pageStateSetter((prev) => ({ ...prev, error })); - } - const { i18n } = useTranslationContext(); return ( - <Router history={history}> - <Route - path="/public-accounts" - component={() => ( - <BankFrame> + <BankFrame + goToBusinessAccount={() => { + route("/business"); + }} + > + <Router history={history}> + <Route + path="/operation/:wopid" + component={({ wopid }: { wopid: string }) => ( + <WithdrawalOperationPage + operationId={wopid} + onAbort={() => { + route("/account"); + }} + onLoadNotOk={() => { + route("/account"); + }} + /> + )} + /> + <Route + path="/public-accounts" + component={() => ( <PublicHistoriesPage - onLoadNotOk={handleNotOkResult("/account", saveError, i18n)} + onLoadNotOk={() => { + route("/account"); + }} /> - </BankFrame> - )} - /> - <Route - path="/register" - component={() => ( - <BankFrame> + )} + /> + <Route + path="/register" + component={() => ( <RegistrationPage - onError={saveError} onComplete={() => { route("/account"); }} /> - </BankFrame> - )} - /> - <Route - path="/account" - component={() => ( - <BankFrame - goToBusinessAccount={() => { - route("/business"); - }} - > + )} + /> + <Route + path="/account" + component={() => ( <HomePage + onPendingOperationFound={(wopid) => { + route(`/operation/${wopid}`); + }} onRegister={() => { route("/register"); }} /> - </BankFrame> - )} - /> - <Route - path="/business" - component={() => ( - <BankFrame> + )} + /> + <Route + path="/business" + component={() => ( <BusinessAccount onClose={() => { route("/account"); @@ -155,13 +92,15 @@ export function Routing(): VNode { onRegister={() => { route("/register"); }} - onLoadNotOk={handleNotOkResult("/account", saveError, i18n)} + onLoadNotOk={() => { + route("/account"); + }} /> - </BankFrame> - )} - /> - <Route default component={Redirect} to="/account" /> - </Router> + )} + /> + <Route default component={Redirect} to="/account" /> + </Router> + </BankFrame> ); } |