diff options
author | Sebastian <sebasjm@gmail.com> | 2022-12-07 11:22:21 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-12-07 16:08:16 -0300 |
commit | 5d5b63416bbbf8bfefe5ee8d5a5adfdc8c361e31 (patch) | |
tree | 95189d0f484abe5152fedc1ecdbb9b508cfffe60 /packages/demobank-ui/src/pages/home/BankFrame.tsx | |
parent | 0fa3b8ddb93e2d0352da82a6f2b07304ea239c28 (diff) | |
download | wallet-core-5d5b63416bbbf8bfefe5ee8d5a5adfdc8c361e31.tar.xz |
no-fix: moving out public histories page
Diffstat (limited to 'packages/demobank-ui/src/pages/home/BankFrame.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/home/BankFrame.tsx | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/packages/demobank-ui/src/pages/home/BankFrame.tsx b/packages/demobank-ui/src/pages/home/BankFrame.tsx new file mode 100644 index 000000000..9b4bc4567 --- /dev/null +++ b/packages/demobank-ui/src/pages/home/BankFrame.tsx @@ -0,0 +1,201 @@ +/* + This file is part of GNU Taler + (C) 2022 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import { Fragment, h, VNode } from "preact"; +import { PageStateType, usePageContext } from "../../context/pageState.js"; +import { useTranslationContext } from "../../context/translation.js"; +import { bankUiSettings } from "../../settings.js"; +import { LangSelectorLikePy as LangSelector } from "../../components/menu/LangSelector.js"; +import { StateUpdater } from "preact/hooks"; +import talerLogo from "../../assets/logo-white.svg"; + +export function BankFrame(Props: any): VNode { + const { i18n } = useTranslationContext(); + const { pageState, pageStateSetter } = usePageContext(); + console.log("BankFrame state", pageState); + const logOut = ( + <div class="logout"> + <a + href="#" + class="pure-button logout-button" + onClick={() => { + pageStateSetter((prevState: PageStateType) => { + const { talerWithdrawUri, withdrawalId, ...rest } = prevState; + return { + ...rest, + isLoggedIn: false, + withdrawalInProgress: false, + error: undefined, + info: undefined, + isRawPayto: false, + }; + }); + }} + >{i18n.str`Logout`}</a> + </div> + ); + + const demo_sites = []; + for (const i in bankUiSettings.demoSites) + demo_sites.push( + <a href={bankUiSettings.demoSites[i][1]}> + {bankUiSettings.demoSites[i][0]} + </a>, + ); + + return ( + <Fragment> + <header + class="demobar" + style="display: flex; flex-direction: row; justify-content: space-between;" + > + <a href="#main" class="skip">{i18n.str`Skip to main content`}</a> + <div style="max-width: 50em; margin-left: 2em;"> + <h1> + <span class="it"> + <a href="/">{bankUiSettings.bankName}</a> + </span> + </h1> + {maybeDemoContent( + <p> + <i18n.Translate> + This part of the demo shows how a bank that supports Taler + directly would work. In addition to using your own bank account, + you can also see the transaction history of some{" "} + <a + href="/public-accounts" + onClick={goPublicAccounts(pageStateSetter)} + > + Public Accounts + </a> + . + </i18n.Translate> + </p>, + )} + </div> + <a href="https://taler.net/"> + <img + src={talerLogo} + alt={i18n.str`Taler logo`} + height="100" + width="224" + style="margin: 2em 2em" + /> + </a> + </header> + <div style="display:flex; flex-direction: column;" class="navcontainer"> + <nav class="demolist"> + {maybeDemoContent(<Fragment>{demo_sites}</Fragment>)} + <div class="right"> + <LangSelector /> + </div> + </nav> + </div> + <section id="main" class="content"> + <ErrorBanner pageState={[pageState, pageStateSetter]} /> + <StatusBanner pageState={[pageState, pageStateSetter]} /> + {pageState.isLoggedIn ? logOut : null} + {Props.children} + </section> + <section id="footer" class="footer"> + <div class="footer"> + <hr /> + <div> + <p> + You can learn more about GNU Taler on our{" "} + <a href="https://taler.net">main website</a>. + </p> + </div> + <div style="flex-grow:1" /> + <p>Copyright © 2014—2022 Taler Systems SA</p> + </div> + </section> + </Fragment> + ); +} + +function maybeDemoContent(content: VNode): VNode { + if (bankUiSettings.showDemoNav) { + return content; + } + return <Fragment />; +} + +/** + * Bring the state to show the public accounts page. + */ +function goPublicAccounts(pageStateSetter: StateUpdater<PageStateType>) { + return () => + pageStateSetter((prevState) => ({ + ...prevState, + showPublicHistories: true, + })); +} + +function ErrorBanner(Props: any): VNode | null { + const [pageState, pageStateSetter] = Props.pageState; + // const { i18n } = useTranslationContext(); + if (!pageState.error) return null; + + const rval = ( + <div class="informational informational-fail" style={{ marginTop: 8 }}> + <div style={{ display: "flex", justifyContent: "space-between" }}> + <p> + <b>{pageState.error.title}</b> + </p> + <div> + <input + type="button" + class="pure-button" + value="Clear" + onClick={async () => { + pageStateSetter((prev: any) => ({ ...prev, error: undefined })); + }} + /> + </div> + </div> + <p>{pageState.error.description}</p> + </div> + ); + delete pageState.error; + return rval; +} + +function StatusBanner(Props: any): VNode | null { + const [pageState, pageStateSetter] = Props.pageState; + if (!pageState.info) return null; + + const rval = ( + <div class="informational informational-ok" style={{ marginTop: 8 }}> + <div style={{ display: "flex", justifyContent: "space-between" }}> + <p> + <b>{pageState.info}</b> + </p> + <div> + <input + type="button" + class="pure-button" + value="Clear" + onClick={async () => { + pageStateSetter((prev: any) => ({ ...prev, info: undefined })); + }} + /> + </div> + </div> + </div> + ); + return rval; +} |