diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-22 11:38:28 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-22 11:40:57 -0300 |
commit | 82ec30e81e4352146de6e3de668465100ef4274d (patch) | |
tree | d9cc3b690560c49915eeb5de57e50bb75a5e0485 /packages/challenger-ui/src/pages/AnswerChallenge.tsx | |
parent | 66c3a47ec6bb69ed0bda69f53b5242ba4795d823 (diff) | |
download | wallet-core-82ec30e81e4352146de6e3de668465100ef4274d.tar.xz |
refactor to keep the challenge status up to date
Diffstat (limited to 'packages/challenger-ui/src/pages/AnswerChallenge.tsx')
-rw-r--r-- | packages/challenger-ui/src/pages/AnswerChallenge.tsx | 87 |
1 files changed, 15 insertions, 72 deletions
diff --git a/packages/challenger-ui/src/pages/AnswerChallenge.tsx b/packages/challenger-ui/src/pages/AnswerChallenge.tsx index 69600e2ba..bad6d70de 100644 --- a/packages/challenger-ui/src/pages/AnswerChallenge.tsx +++ b/packages/challenger-ui/src/pages/AnswerChallenge.tsx @@ -16,15 +16,16 @@ import { ChallengerApi, HttpStatusCode, - assertUnreachable, + assertUnreachable } from "@gnu-taler/taler-util"; import { + Attention, Button, LocalNotificationBanner, ShowInputErrorLabel, useChallengerApiContext, useLocalNotificationHandler, - useTranslationContext, + useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; @@ -37,13 +38,7 @@ type Props = { onComplete: () => void; }; -function SolveChallengeForm({ - nonce, - onComplete, -}: { - nonce: string; - onComplete: () => void; -}): VNode { +export function AnswerChallenge({ nonce, onComplete }: Props): VNode { const { lib } = useChallengerApiContext(); const { i18n } = useTranslationContext(); const { state, accepted, completed } = useSessionState(); @@ -64,8 +59,8 @@ function SolveChallengeForm({ return await lib.bank.challenge(nonce, { email: state.email }); }, (ok) => { - if ('redirectURL' in ok.body) { - completed(ok.body.redirectURL) + if ("redirectURL" in ok.body) { + completed(ok.body.redirectURL); } else { accepted(state.email!, { attemptsLeft: ok.body.attempts_left, @@ -99,7 +94,7 @@ function SolveChallengeForm({ return lib.bank.solve(nonce, { pin: pin! }); }, (ok) => { - completed(ok.body.redirectURL as URL) + completed(ok.body.redirectURL as URL); onComplete(); }, (fail) => { @@ -149,11 +144,13 @@ function SolveChallengeForm({ A TAN was sent to your address "{state.email}". </i18n.Translate> ) : ( - <i18n.Translate> - We recently already sent a TAN to your address " - {state.email}". A new TAN will not be transmitted again - before {state.lastTry.nextSend}. - </i18n.Translate> + <Attention title={i18n.str`Resend failed`} type="warning"> + <i18n.Translate> + We recently already sent a TAN to your address " + {state.email}". A new TAN will not be transmitted again + before "{state.lastTry.nextSend}". + </i18n.Translate> + </Attention> )} </p> {!lastTryError ? undefined : ( @@ -230,61 +227,7 @@ function SolveChallengeForm({ </form> </div> </Fragment> - ); -} - -export function AnswerChallenge({ nonce, onComplete }: Props): VNode { - const { i18n } = useTranslationContext(); - - // const result = useChallengeSession(nonce, clientId, redirectURI, state); - - // if (!result) { - // return <Loading />; - // } - // if (result instanceof TalerError) { - // return <div />; - // } - - // if (result.type === "fail") { - // switch (result.case) { - // case HttpStatusCode.BadRequest: { - // return ( - // <Attention type="danger" title={i18n.str`Bad request`}> - // <i18n.Translate> - // Could not start the challenge, check configuration. - // </i18n.Translate> - // </Attention> - // ); - // } - // case HttpStatusCode.NotFound: { - // return ( - // <Attention type="danger" title={i18n.str`Not found`}> - // <i18n.Translate>Nonce not found</i18n.Translate> - // </Attention> - // ); - // } - // case HttpStatusCode.NotAcceptable: { - // return ( - // <Attention type="danger" title={i18n.str`Not acceptable`}> - // <i18n.Translate> - // Server has wrong template configuration - // </i18n.Translate> - // </Attention> - // ); - // } - // case HttpStatusCode.InternalServerError: { - // return ( - // <Attention type="danger" title={i18n.str`Internal error`}> - // <i18n.Translate>Check logs</i18n.Translate> - // </Attention> - // ); - // } - // default: - // assertUnreachable(result); - // } - // } - - return <SolveChallengeForm nonce={nonce} onComplete={onComplete} />; + ) } export function undefinedIfEmpty<T extends object>(obj: T): T | undefined { |