gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: fix #9138


From: gnunet
Subject: [taler-wallet-core] branch master updated: fix #9138
Date: Tue, 03 Sep 2024 18:59:52 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 5ae45ca44 fix #9138
5ae45ca44 is described below

commit 5ae45ca44def6eadeebb42e11336802f9180012c
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Tue Sep 3 13:59:31 2024 -0300

    fix #9138
---
 packages/kyc-ui/src/Routing.tsx      | 29 +++++++++++++++++++++++------
 packages/kyc-ui/src/hooks/session.ts | 18 ++++++------------
 packages/kyc-ui/src/pages/Start.tsx  |  2 +-
 3 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/packages/kyc-ui/src/Routing.tsx b/packages/kyc-ui/src/Routing.tsx
index 8dcfa24a4..a5508e7da 100644
--- a/packages/kyc-ui/src/Routing.tsx
+++ b/packages/kyc-ui/src/Routing.tsx
@@ -23,10 +23,11 @@ import {
 import { Fragment, VNode, h } from "preact";
 
 import { AccessToken, assertUnreachable } from "@gnu-taler/taler-util";
-import { useErrorBoundary } from "preact/hooks";
+import { useEffect, useErrorBoundary } from "preact/hooks";
 import { CallengeCompleted } from "./pages/CallengeCompleted.js";
 import { Frame } from "./pages/Frame.js";
 import { Start } from "./pages/Start.js";
+import { useSessionState } from "./hooks/session.js";
 
 export function Routing(): VNode {
   // check session and defined if this is
@@ -60,6 +61,8 @@ export function safeToURL(s: string | undefined): URL | 
undefined {
   }
 }
 
+const ACCESS_TOKEN_REGEX = new RegExp("[A-Z0-9]{52}")
+
 /**
  * by how the exchange
  * /kyc-spa/KXAFXEWM7E3EJSYD9GJ30FYK1C17AKZWV119ZJA3XGPBBMZFJ2C0
@@ -70,19 +73,33 @@ function getAccessTokenFromURL(): AccessToken | undefined {
   if (typeof window === "undefined") return undefined;
   const paths = window.location.pathname.split("/");
   if (paths.length < 3) return undefined;
-  return paths[2] as AccessToken;
+  const res = paths[2] as AccessToken
+  if (!ACCESS_TOKEN_REGEX.test(res)) return undefined;
+  return res;
 }
 
 function PublicRounting(): VNode {
   const location = useCurrentLocation(publicPages);
+  const { state, start } = useSessionState();
   const { navigateTo } = useNavigationContext();
   useErrorBoundary((e) => {
     console.log("error", e);
   });
+  const sessionToken = state?.accessToken
+  const urlToken = getAccessTokenFromURL();
+  useEffect(() => {
+    if (!urlToken) {
+      //special case, loading without URL the it should use the session
+      return;
+    }
+    // loading a new session
+    if (urlToken !== sessionToken) {
+      start(urlToken)
+    }
+  },[sessionToken, urlToken])
 
-  const at = getAccessTokenFromURL();
-  if (!at) {
-    return <div>no access token</div>;
+  if (!sessionToken) {
+    return <div>No access token</div>;
   }
 
   switch (location.name) {
@@ -93,7 +110,7 @@ function PublicRounting(): VNode {
     case "start": {
       return (
         <Start
-          token={at}
+          token={sessionToken}
           onLoggedOut={() => {
             navigateTo(publicPages.completed.url({}));
           }}
diff --git a/packages/kyc-ui/src/hooks/session.ts 
b/packages/kyc-ui/src/hooks/session.ts
index ff644ae24..f7d903bcb 100644
--- a/packages/kyc-ui/src/hooks/session.ts
+++ b/packages/kyc-ui/src/hooks/session.ts
@@ -23,27 +23,19 @@ import {
 } from "@gnu-taler/taler-util";
 import { buildStorageKey, useLocalStorage } from "@gnu-taler/web-util/browser";
 
-/**
- * Has the information to reach and
- * authenticate at the bank's backend.
- */
-export type SessionId = {
-  // accessToken: AccessToken;
-};
-
 export type SessionState = {
-  // accessToken: AccessToken;
+  accessToken: AccessToken;
 };
 
 export const codecForSessionState = (): Codec<SessionState> =>
   buildCodecForObject<SessionState>()
-    // .property("accessToken", codecForAccessToken())
+    .property("accessToken", codecForAccessToken())
     //     .property("lastAddress", 
codecOptional(codecForList(codecForLastAddress())))
     .build("SessionState");
 
 export interface SessionStateHandler {
   state: SessionState | undefined;
-  start(s: SessionId): void;
+  start(s: AccessToken): void;
 }
 
 const SESSION_STATE_KEY = buildStorageKey(
@@ -61,6 +53,8 @@ export function useSessionState(): SessionStateHandler {
 
   return {
     state,
-    start(s) {},
+    start(accessToken) {
+      update({accessToken})
+    },
   };
 }
diff --git a/packages/kyc-ui/src/pages/Start.tsx 
b/packages/kyc-ui/src/pages/Start.tsx
index d30f8b840..ce71cc2cc 100644
--- a/packages/kyc-ui/src/pages/Start.tsx
+++ b/packages/kyc-ui/src/pages/Start.tsx
@@ -190,11 +190,11 @@ function ShowReqList({
   );
 }
 export function Start({ token, onLoggedOut }: Props): VNode {
-  // const { state } = useSessionState();
   const [req, setReq] = useState<KycRequirementInformation>();
   // if (!state) {
   //   return <Loading />;
   // }
+
   if (!req) {
     return <ShowReqList token={token} onFormSelected={(r) => setReq(r)} />;
   }

-- 
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]