gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated (acef3baeb -> 055645e17)


From: gnunet
Subject: [taler-wallet-core] branch master updated (acef3baeb -> 055645e17)
Date: Mon, 11 Dec 2023 19:22:12 +0100

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a change to branch master
in repository wallet-core.

    from acef3baeb match 1:1 testing with taler-uri spec
     new 86a9b24b5 warn when clipboard is not available
     new 055645e17 wip: #7752

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 packages/demobank-ui/src/Routing.tsx               |   5 +
 packages/demobank-ui/src/pages/DownloadStats.tsx   | 122 +++++++++++++++++++++
 packages/demobank-ui/src/pages/admin/AdminHome.tsx |   7 +-
 packages/web-util/src/components/CopyButton.tsx    |   9 +-
 4 files changed, 140 insertions(+), 3 deletions(-)
 create mode 100644 packages/demobank-ui/src/pages/DownloadStats.tsx

diff --git a/packages/demobank-ui/src/Routing.tsx 
b/packages/demobank-ui/src/Routing.tsx
index f8a625621..711b7f871 100644
--- a/packages/demobank-ui/src/Routing.tsx
+++ b/packages/demobank-ui/src/Routing.tsx
@@ -38,6 +38,7 @@ import { WireTransfer } from "./pages/WireTransfer.js";
 import { AccountPage } from "./pages/AccountPage/index.js";
 import { useSettingsContext } from "./context/settings.js";
 import { useBankCoreApiContext } from "./context/config.js";
+import { DownloadStats } from "./pages/DownloadStats.js";
 
 export function Routing(): VNode {
   const history = createHashHistory();
@@ -119,6 +120,10 @@ export function Routing(): VNode {
           path="/public-accounts"
           component={() => <PublicHistoriesPage />}
         />
+        <Route
+          path="/download-stats"
+          component={() => <DownloadStats />}
+        />
 
         <Route
           path="/new-account"
diff --git a/packages/demobank-ui/src/pages/DownloadStats.tsx 
b/packages/demobank-ui/src/pages/DownloadStats.tsx
new file mode 100644
index 000000000..cd3e6d875
--- /dev/null
+++ b/packages/demobank-ui/src/pages/DownloadStats.tsx
@@ -0,0 +1,122 @@
+/*
+ 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 { AccessToken, Logger, RefreshReason, TalerCoreBankHttpClient, 
TalerCorebankApi, TalerError } from "@gnu-taler/taler-util";
+import { useTranslationContext } from "@gnu-taler/web-util/browser";
+import { Fragment, VNode, h } from "preact";
+import { useState } from "preact/hooks";
+import { Loading } from "@gnu-taler/web-util/browser";
+import { Transactions } from "../components/Transactions/index.js";
+import { usePublicAccounts } from "../hooks/access.js";
+import { useBackendState } from "../hooks/backend.js";
+import { useBankCoreApiContext } from "../context/config.js";
+import { getTimeframesForDate } from "./admin/AdminHome.js";
+
+const logger = new Logger("PublicHistoriesPage");
+
+interface Props { }
+
+/** 
+ * Show histories of public accounts.
+ */
+export function DownloadStats({ }: Props): VNode {
+  const { i18n } = useTranslationContext();
+
+  const { state: credentials } = useBackendState();
+  const creds = credentials.status !== "loggedIn" || 
!credentials.isUserAdministrator ? undefined : credentials
+  const { api, config } = useBankCoreApiContext();
+
+  const [state, setState] = useState<number>()
+
+  if (!creds) {
+    return <div>only admin can download stats</div>
+  }
+
+  return (
+    <Fragment>
+      <h1 class="nav">{i18n.str`Stats`}</h1>
+      <button type="button"
+        class="inline-flex items-center  disabled:opacity-50 
disabled:cursor-default cursor-pointer rounded-md bg-indigo-600 px-3 py-2 
text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 
focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 
focus-visible:outline-indigo-600"
+        onClick={() => {
+          fetchAllStatus(api, creds.token, new Date(), (p, total) => {
+            console.log("doing...", total - p)
+            setState(total - p)
+          })
+        }}
+      >
+        start
+      </button>
+      progress {state}
+    </Fragment>
+  );
+}
+
+
+async function fetchAllStatus(api: TalerCoreBankHttpClient, token: 
AccessToken, reference: Date, progres: (current: number, total: number) => 
void) {
+  const allMetrics = [
+    TalerCorebankApi.MonitorTimeframeParam.day,
+    TalerCorebankApi.MonitorTimeframeParam.hour,
+    // TalerCorebankApi.MonitorTimeframeParam.month,
+    // TalerCorebankApi.MonitorTimeframeParam.year,
+    // TalerCorebankApi.MonitorTimeframeParam.decade,
+  ]
+  const allFrames = allMetrics.map(timeframe => ({
+    timeframe, moment: getTimeframesForDate(reference, timeframe)
+  }))
+
+  type Data = {
+    previous: TalerCorebankApi.MonitorResponse;
+    current: TalerCorebankApi.MonitorResponse;
+  }
+  const total = allFrames.length
+  
+  const dataResolvers = allFrames.map((frame, index) => async function 
getData(): Promise<Data | undefined> {
+    const previous = await api.getMonitor(token, {
+      timeframe: frame.timeframe,
+      which: frame.moment.previous
+    })
+    await delay()
+    if (previous.type !== "ok") return undefined;
+    const current = await api.getMonitor(token, {
+      timeframe: frame.timeframe,
+      which: frame.moment.current
+    })
+    await delay()
+    if (current.type !== "ok") return undefined;
+    return { previous: previous.body, current: current.body }
+  });
+
+  const csv = await dataResolvers.reduce(async (prev, resolver, index) => {
+    const accumulatedMap = await prev
+    console.log(index)
+    progres(index, total)
+    const data = await resolver()
+    if (!data) return accumulatedMap
+
+    const metricName = 
TalerCorebankApi.MonitorTimeframeParam[allMetrics[index]]
+    accumulatedMap[metricName] = data
+    return accumulatedMap
+  }, Promise.resolve({} as Record<string, Data>))
+  progres(total, total)
+  console.log(csv)
+}
+async function delay() {
+  return new Promise((res, rej) => {
+    setTimeout(() => {
+      res(null);
+    }, 1000)
+  })
+}
\ No newline at end of file
diff --git a/packages/demobank-ui/src/pages/admin/AdminHome.tsx 
b/packages/demobank-ui/src/pages/admin/AdminHome.tsx
index 18e88a409..9c6e6cde6 100644
--- a/packages/demobank-ui/src/pages/admin/AdminHome.tsx
+++ b/packages/demobank-ui/src/pages/admin/AdminHome.tsx
@@ -54,7 +54,7 @@ function getDateForTimeframe(which: number, timeframe: 
TalerCorebankApi.MonitorT
   assertUnreachable(timeframe)
 }
 
-function getTimeframesForDate(time: Date, timeframe: 
TalerCorebankApi.MonitorTimeframeParam): { current: number, previous: number } {
+export function getTimeframesForDate(time: Date, timeframe: 
TalerCorebankApi.MonitorTimeframeParam): { current: number, previous: number } {
   switch (timeframe) {
     case TalerCorebankApi.MonitorTimeframeParam.hour: return {
       current: getHours(sub(time, { hours: 1 })),
@@ -183,6 +183,11 @@ function Metrics(): VNode {
         />
       </div>
     </dl>
+    <div class="flex justify-end mt-2">
+      <a href="#/download-stats" class="link"><i18n.Translate>
+        download stats as csv
+      </i18n.Translate></a>
+    </div>
   </Fragment>
 
 }
diff --git a/packages/web-util/src/components/CopyButton.tsx 
b/packages/web-util/src/components/CopyButton.tsx
index 0096da365..e76447291 100644
--- a/packages/web-util/src/components/CopyButton.tsx
+++ b/packages/web-util/src/components/CopyButton.tsx
@@ -20,8 +20,13 @@ export function CopiedIcon(): VNode {
 export function CopyButton({ class: clazz, getContent }: { class: string, 
getContent: () => string }): VNode {
   const [copied, setCopied] = useState(false);
   function copyText(): void {
-    navigator.clipboard.writeText(getContent() || "");
-    setCopied(true);
+    if (!navigator.clipboard && !window.isSecureContext) {
+      alert('clipboard is not available on insecure context (http)')
+    }
+    if (navigator.clipboard) {
+      navigator.clipboard.writeText(getContent() || "");
+      setCopied(true);
+    }
   }
   useEffect(() => {
     if (copied) {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]