commit 589a013eadfccb22a2b8dd4b77785c46743c69cb
parent 8026d1dec99e08ea8e9316b3dd5ebc7c8684f4dc
Author: Sebastian <sebasjm@gmail.com>
Date: Tue, 11 Mar 2025 16:18:06 -0300
fix #9552
Diffstat:
2 files changed, 13 insertions(+), 35 deletions(-)
diff --git a/packages/challenger-ui/src/pages/AnswerChallenge.tsx b/packages/challenger-ui/src/pages/AnswerChallenge.tsx
@@ -41,7 +41,7 @@ import { SessionId, useSessionState } from "../hooks/session.js";
type Props = {
focus?: boolean;
- session: SessionId,
+ session: SessionId;
onComplete: () => void;
routeAsk: RouteDefinition<EmptyObject>;
};
@@ -64,7 +64,12 @@ function useReloadOnDeadline(deadline: AbsoluteTime): void {
}, [deadline]);
}
-export function AnswerChallenge({ session, focus, onComplete, routeAsk }: Props): VNode {
+export function AnswerChallenge({
+ session,
+ focus,
+ onComplete,
+ routeAsk,
+}: Props): VNode {
const { config, lib } = useChallengerApiContext();
const { i18n } = useTranslationContext();
const { sent, failed, completed } = useSessionState();
@@ -74,12 +79,7 @@ export function AnswerChallenge({ session, focus, onComplete, routeAsk }: Props)
pin: !pin ? i18n.str`Can't be empty` : undefined,
});
- const restrictionKeys = !config.restrictions
- ? []
- : Object.keys(config.restrictions);
- const restrictionKey = !restrictionKeys.length
- ? undefined
- : restrictionKeys[0];
+ const restrictionKey = config.address_type;
const result = useChallengeSession(session);
@@ -95,17 +95,10 @@ export function AnswerChallenge({ session, focus, onComplete, routeAsk }: Props)
useReloadOnDeadline(deadline ?? AbsoluteTime.never());
- if (!restrictionKey) {
- return (
- <div>
- invalid server configuration, there is no restriction in /config
- </div>
- );
- }
-
- const lastAddr = !lastStatus?.last_address
- ? undefined
- : lastStatus.last_address[restrictionKey];
+ const lastAddr =
+ !restrictionKey || !lastStatus?.last_address
+ ? undefined
+ : lastStatus.last_address[restrictionKey];
const unableToChangeAddr = !lastStatus || lastStatus.changes_left < 1;
const contact = lastAddr ? { [restrictionKey]: lastAddr } : undefined;
diff --git a/packages/challenger-ui/src/pages/AskChallenge.tsx b/packages/challenger-ui/src/pages/AskChallenge.tsx
@@ -63,25 +63,10 @@ export function AskChallenge({
const [remember, setRemember] = useState<boolean>(false);
const [addrIndex, setAddrIndex] = useState<number | undefined>();
- const restrictionKeys = !config.restrictions
- ? []
- : Object.keys(config.restrictions);
- const restrictionKey = !restrictionKeys.length
- ? undefined
- : restrictionKeys[0];
+ const restrictionKey = config.address_type;
const result = useChallengeSession(session);
- if (!restrictionKey) {
- return (
- <Attention title={i18n.str`Server configuration error`} type="danger">
- <i18n.Translate>
- Invalid server configuration, there is no restriction in /config
- </i18n.Translate>
- </Attention>
- );
- }
-
const restriction = !config.restrictions
? undefined
: config.restrictions[restrictionKey];