diff options
author | Sebastian <sebasjm@gmail.com> | 2023-04-14 14:07:15 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-04-14 14:16:25 -0300 |
commit | 5ea22a325c069fe497b2dc8a73d4de69fd8cc27b (patch) | |
tree | 7783c8a47c5f645a2c277bb0251863e4d6165dde /packages/demobank-ui/src/pages/PublicHistoriesPage.tsx | |
parent | c3e1a0bb519bf5012781891c15c433841203bce2 (diff) | |
download | wallet-core-5ea22a325c069fe497b2dc8a73d4de69fd8cc27b.tar.xz |
using new localStorage api, pageState => settings, notifcation using observer api
Diffstat (limited to 'packages/demobank-ui/src/pages/PublicHistoriesPage.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/PublicHistoriesPage.tsx | 59 |
1 files changed, 10 insertions, 49 deletions
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 ( -// <BankFrame> -// <PublicHistories /> -// </BankFrame> -// ); -// } - 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<string, h.JSX.Element> = {}; 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 { </Fragment> ); } - -/** - * 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 <input> fields. - */ -function useShowPublicAccount( - state?: string, -): [string | undefined, StateUpdater<string | undefined>] { - const ret = useLocalStorage("show-public-account", JSON.stringify(state)); - const retObj: string | undefined = ret[0] ? JSON.parse(ret[0]) : ret[0]; - const retSetter: StateUpdater<string | undefined> = function (val) { - const newVal = - val instanceof Function - ? JSON.stringify(val(retObj)) - : JSON.stringify(val); - ret[1](newVal); - }; - return [retObj, retSetter]; -} |