diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-22 12:18:41 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-22 12:18:41 -0300 |
commit | 5db4cb99e3f16c8471117ca7443bc323180e67ec (patch) | |
tree | a2340eb33b259cf420abb6a1e3cf295c0393b4f9 /packages/challenger-ui/src/pages/AskChallenge.tsx | |
parent | 594dd1fd4638d658303c4c8a0f24c4082564eceb (diff) | |
download | wallet-core-5db4cb99e3f16c8471117ca7443bc323180e67ec.tar.xz |
fix #8393
Diffstat (limited to 'packages/challenger-ui/src/pages/AskChallenge.tsx')
-rw-r--r-- | packages/challenger-ui/src/pages/AskChallenge.tsx | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/packages/challenger-ui/src/pages/AskChallenge.tsx b/packages/challenger-ui/src/pages/AskChallenge.tsx index 813636fa4..76fe6f00a 100644 --- a/packages/challenger-ui/src/pages/AskChallenge.tsx +++ b/packages/challenger-ui/src/pages/AskChallenge.tsx @@ -13,9 +13,7 @@ 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 { - HttpStatusCode -} from "@gnu-taler/taler-util"; +import { HttpStatusCode } from "@gnu-taler/taler-util"; import { Attention, Button, @@ -24,7 +22,7 @@ import { ShowInputErrorLabel, useChallengerApiContext, useLocalNotificationHandler, - useTranslationContext + useTranslationContext, } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; @@ -38,24 +36,22 @@ export const EMAIL_REGEX = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/; type Props = { nonce: string; onSendSuccesful: () => void; - routeSolveChallenge: RouteDefinition<{nonce:string}>, + routeSolveChallenge: RouteDefinition<{ nonce: string }>; }; -export function AskChallenge({ nonce, onSendSuccesful,routeSolveChallenge }: Props): VNode { +export function AskChallenge({ + nonce, + onSendSuccesful, + routeSolveChallenge, +}: Props): VNode { const { state, accepted, completed } = useSessionState(); - const status = state?.challengeStatus; + const status = state?.lastStatus; const prevEmail = - !status || !status.last_address - ? undefined - : ((status.last_address as any)["email"] as string); + !status || !status.last_address ? undefined : status.last_address["email"]; const regexEmail = !status || !status.restrictions ? undefined - : ((status.restrictions as any)["email"] as { - regex?: string; - hint?: string; - hint_i18n?: string; - }); + : status.restrictions["email"]; const { lib } = useChallengerApiContext(); const { i18n } = useTranslationContext(); @@ -82,37 +78,39 @@ export function AskChallenge({ nonce, onSendSuccesful,routeSolveChallenge }: Pro : undefined, }); - const onSend = errors? undefined : withErrorHandler( - async () => { - return lib.bank.challenge(nonce, { email: email! }); - }, - (ok) => { - if ("redirectURL" in ok.body) { - completed(ok.body.redirectURL); - } else { - accepted(email!, { - attemptsLeft: ok.body.attempts_left, - nextSend: ok.body.next_tx_time, - transmitted: ok.body.transmitted, - }); - } - onSendSuccesful(); - }, - (fail) => { - switch (fail.case) { - case HttpStatusCode.BadRequest: - return i18n.str``; - case HttpStatusCode.NotFound: - return i18n.str``; - case HttpStatusCode.NotAcceptable: - return i18n.str``; - case HttpStatusCode.TooManyRequests: - return i18n.str``; - case HttpStatusCode.InternalServerError: - return i18n.str``; - } - }, - ); + const onSend = errors + ? undefined + : withErrorHandler( + async () => { + return lib.bank.challenge(nonce, { email: email! }); + }, + (ok) => { + if ("redirectURL" in ok.body) { + completed(ok.body.redirectURL); + } else { + accepted({ + attemptsLeft: ok.body.attempts_left, + nextSend: ok.body.next_tx_time, + transmitted: ok.body.transmitted, + }); + } + onSendSuccesful(); + }, + (fail) => { + switch (fail.case) { + case HttpStatusCode.BadRequest: + return i18n.str``; + case HttpStatusCode.NotFound: + return i18n.str``; + case HttpStatusCode.NotAcceptable: + return i18n.str``; + case HttpStatusCode.TooManyRequests: + return i18n.str``; + case HttpStatusCode.InternalServerError: + return i18n.str``; + } + }, + ); if (!status) { return <div>no status loaded</div>; @@ -136,9 +134,13 @@ export function AskChallenge({ nonce, onSendSuccesful,routeSolveChallenge }: Pro </div> {state.lastTry && ( <Fragment> - <Attention title={i18n.str`A code has been sent to ${state.email}`}> + <Attention title={i18n.str`A code has been sent to ${prevEmail}`}> <i18n.Translate> - You can change the destination or <a href={routeSolveChallenge.url({nonce })}><i18n.Translate>complete the challenge here</i18n.Translate></a>. + You can change the destination or{" "} + <a href={routeSolveChallenge.url({ nonce })}> + <i18n.Translate>complete the challenge here</i18n.Translate> + </a> + . </i18n.Translate> </Attention> </Fragment> |