diff options
Diffstat (limited to 'packages/challenger-ui/src/Routing.tsx')
-rw-r--r-- | packages/challenger-ui/src/Routing.tsx | 151 |
1 files changed, 45 insertions, 106 deletions
diff --git a/packages/challenger-ui/src/Routing.tsx b/packages/challenger-ui/src/Routing.tsx index f7488cb8d..179263286 100644 --- a/packages/challenger-ui/src/Routing.tsx +++ b/packages/challenger-ui/src/Routing.tsx @@ -30,7 +30,6 @@ import { AnswerChallenge } from "./pages/AnswerChallenge.js"; import { AskChallenge } from "./pages/AskChallenge.js"; import { CallengeCompleted } from "./pages/CallengeCompleted.js"; import { Frame } from "./pages/Frame.js"; -import { MissingParams } from "./pages/MissingParams.js"; import { NonceNotFound } from "./pages/NonceNotFound.js"; import { Setup } from "./pages/Setup.js"; @@ -45,26 +44,11 @@ export function Routing(): VNode { } const publicPages = { - noinfo: urlPattern<{ nonce: string }>( - /\/noinfo\/(?<nonce>[a-zA-Z0-9]+)/, - ({ nonce }) => `#/noinfo/${nonce}`, - ), - authorize: urlPattern<{ nonce: string }>( - /\/authorize\/(?<nonce>[a-zA-Z0-9]+)/, - ({ nonce }) => `#/authorize/${nonce}`, - ), - ask: urlPattern<{ nonce: string }>( - /\/ask\/(?<nonce>[a-zA-Z0-9]+)/, - ({ nonce }) => `#/ask/${nonce}`, - ), - answer: urlPattern<{ nonce: string }>( - /\/answer\/(?<nonce>[a-zA-Z0-9]+)/, - ({ nonce }) => `#/answer/${nonce}`, - ), - completed: urlPattern<{ nonce: string }>( - /\/completed\/(?<nonce>[a-zA-Z0-9]+)/, - ({ nonce }) => `#/completed/${nonce}`, - ), + noinfo: urlPattern(/\/noinfo/, () => `#/noinfo`), + authorize: urlPattern(/\/authorize/, () => `#/authorize`), + ask: urlPattern(/\/ask/, () => `#/ask`), + answer: urlPattern(/\/answer/, () => `#/answer`), + completed: urlPattern(/\/completed/, () => `#/completed`), setup: urlPattern<{ client: string }>( /\/setup\/(?<client>[0-9]+)/, ({ client }) => `#/setup/${client}`, @@ -79,7 +63,7 @@ function safeGetParam( return ps[n][0]; } -function safeToURL(s: string | undefined): URL | undefined { +export function safeToURL(s: string | undefined): URL | undefined { if (s === undefined) return undefined; try { return new URL(s); @@ -105,58 +89,44 @@ function PublicRounting(): VNode { return <div>no info</div>; } case "setup": { + const secret = safeGetParam(location.params, "secret"); + const redirectURL = safeToURL( + safeGetParam(location.params, "redirect_url"), + ); + return ( <Setup clientId={location.values.client} - onCreated={(nonce) => { - navigateTo(publicPages.ask.url({ nonce })); - //response_type=code - //client_id=1 - //redirect_uri=http://exchange.taler.test:1180/kyc-proof/kyc-provider-wallet - //state=123 + secret={secret} + // "http://exchange.taler.test:1180/kyc-proof/kyc-provider-wallet" + redirectURL={redirectURL} + onCreated={() => { + navigateTo(publicPages.ask.url({})); }} /> ); } case "authorize": { - const responseType = safeGetParam(location.params, "response_type"); const clientId = safeGetParam(location.params, "client_id"); const redirectURL = safeToURL( - safeGetParam(location.params, "redirect_uri"), + safeGetParam(location.params, "redirect_url"), ); const state = safeGetParam(location.params, "state"); - // http://localhost:8080/app/#/authorize/ASDASD123?response_type=code&client_id=1&redirect_uri=goog.ecom&state=123 - // - // http://localhost:8080/app/?response_type=code&client_id=1&redirect_uri=http://exchange.taler.test:1180/kyc-proof/kyc-provider-wallet&state=123#/authorize/X9668AR2CFC26X55H0M87GJZXGM45VD4SZE05C5SNS5FADPWN220 + const sessionId: SessionId | undefined = + !clientId || !redirectURL || !state + ? undefined + : { + clientId, + nonce: location.values.nonce, + redirectURL: redirectURL.href, + state, + }; - if ( - !responseType || - !clientId || - !redirectURL || - !state || - responseType !== "code" - ) { - return <MissingParams />; - } - const sessionId: SessionId = { - clientId, - redirectURL: redirectURL.href, - state, - }; return ( <CheckChallengeIsUpToDate - sessionId={sessionId} - nonce={location.values.nonce} - onNoInfo={() => { - navigateTo( - publicPages.noinfo.url({ - nonce: location.values.nonce, - }), - ); - }} + session={sessionId} onCompleted={() => { - start(sessionId); navigateTo( publicPages.completed.url({ nonce: location.values.nonce, @@ -164,7 +134,6 @@ function PublicRounting(): VNode { ); }} onChangeLeft={() => { - start(sessionId); navigateTo( publicPages.ask.url({ nonce: location.values.nonce, @@ -172,7 +141,6 @@ function PublicRounting(): VNode { ); }} onNoMoreChanges={() => { - start(sessionId); navigateTo( publicPages.ask.url({ nonce: location.values.nonce, @@ -186,26 +154,9 @@ function PublicRounting(): VNode { } case "ask": { return ( - <CheckChallengeIsUpToDate - nonce={location.values.nonce} - onNoInfo={() => { - navigateTo( - publicPages.noinfo.url({ - nonce: location.values.nonce, - }), - ); - }} - onCompleted={() => { - navigateTo( - publicPages.completed.url({ - nonce: location.values.nonce, - }), - ); - }} - > + <CheckChallengeIsUpToDate> <AskChallenge focus - nonce={location.values.nonce} routeSolveChallenge={publicPages.answer} onSendSuccesful={() => { navigateTo( @@ -214,32 +165,22 @@ function PublicRounting(): VNode { }), ); }} + // onCompleted={() => { + // navigateTo( + // publicPages.completed.url({ + // nonce: location.values.nonce, + // }), + // ); + // }} /> </CheckChallengeIsUpToDate> ); } case "answer": { return ( - <CheckChallengeIsUpToDate - nonce={location.values.nonce} - onNoInfo={() => { - navigateTo( - publicPages.noinfo.url({ - nonce: location.values.nonce, - }), - ); - }} - onCompleted={() => { - navigateTo( - publicPages.completed.url({ - nonce: location.values.nonce, - }), - ); - }} - > + <CheckChallengeIsUpToDate> <AnswerChallenge focus - nonce={location.values.nonce} routeAsk={publicPages.ask} onComplete={() => { navigateTo( @@ -248,23 +189,21 @@ function PublicRounting(): VNode { }), ); }} + // onCompleted={() => { + // navigateTo( + // publicPages.completed.url({ + // nonce: location.values.nonce, + // }), + // ); + // }} /> </CheckChallengeIsUpToDate> ); } case "completed": { return ( - <CheckChallengeIsUpToDate - nonce={location.values.nonce} - onNoInfo={() => { - navigateTo( - publicPages.noinfo.url({ - nonce: location.values.nonce, - }), - ); - }} - > - <CallengeCompleted nonce={location.values.nonce} /> + <CheckChallengeIsUpToDate> + <CallengeCompleted /> </CheckChallengeIsUpToDate> ); } |