From a62deeef5d0cbe5fa98be390eac0e03bcae0f0b5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 10 Nov 2021 10:20:52 -0300 Subject: prettier --- .../src/pages/home/ChallengeOverviewScreen.tsx | 208 +++++++++++++-------- 1 file changed, 126 insertions(+), 82 deletions(-) (limited to 'packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.tsx') diff --git a/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.tsx b/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.tsx index ae03dd4d4..c6de00e98 100644 --- a/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.tsx +++ b/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.tsx @@ -11,23 +11,34 @@ function OverviewFeedbackDisplay(props: { feedback?: ChallengeFeedback }) { } switch (feedback.state) { case ChallengeFeedbackStatus.Message: - return ( -
{feedback.message}
- ); + return
{feedback.message}
; case ChallengeFeedbackStatus.Solved: - return
+ return
; case ChallengeFeedbackStatus.Pending: - case ChallengeFeedbackStatus.Solved: case ChallengeFeedbackStatus.AuthIban: return null; case ChallengeFeedbackStatus.ServerFailure: return
Server error.
; case ChallengeFeedbackStatus.RateLimitExceeded: - return
There were to many failed attempts.
; + return ( +
+ There were to many failed attempts. +
+ ); case ChallengeFeedbackStatus.Unsupported: - return
This client doesn't support solving this type of challenge. Use another version or contact the provider.
; + return ( +
+ This client doesn't support solving this type of challenge. Use + another version or contact the provider. +
+ ); case ChallengeFeedbackStatus.TruthUnknown: - return
Provider doesn't recognize the challenge of the policy. Contact the provider for further information.
; + return ( +
+ Provider doesn't recognize the challenge of the policy. Contact the + provider for further information. +
+ ); case ChallengeFeedbackStatus.Redirect: default: return
; @@ -70,19 +81,25 @@ export function ChallengeOverviewScreen(): VNode { feedback: challengeFeedback[ch.uuid], }; } - const policiesWithInfo = policies.map((row) => { - let isPolicySolved = true; - const challenges = row - .map(({ uuid }) => { - const info = knownChallengesMap[uuid]; - const isChallengeSolved = info?.feedback?.state === "solved"; - isPolicySolved = isPolicySolved && isChallengeSolved; - return { info, uuid, isChallengeSolved }; - }) - .filter((ch) => ch.info !== undefined); + const policiesWithInfo = policies + .map((row) => { + let isPolicySolved = true; + const challenges = row + .map(({ uuid }) => { + const info = knownChallengesMap[uuid]; + const isChallengeSolved = info?.feedback?.state === "solved"; + isPolicySolved = isPolicySolved && isChallengeSolved; + return { info, uuid, isChallengeSolved }; + }) + .filter((ch) => ch.info !== undefined); - return { isPolicySolved, challenges }; - }); + return { + isPolicySolved, + challenges, + corrupted: row.length > challenges.length, + }; + }) + .filter((p) => !p.corrupted); const atLeastThereIsOnePolicySolved = policiesWithInfo.find((p) => p.isPolicySolved) !== undefined; @@ -92,19 +109,19 @@ export function ChallengeOverviewScreen(): VNode { : undefined; return ( - {!policies.length ? ( + {!policiesWithInfo.length ? (

No policies found, try with another version of the secret

- ) : policies.length === 1 ? ( + ) : policiesWithInfo.length === 1 ? (

One policy found for this secret. You need to solve all the challenges in order to recover your secret.

) : (

- We have found {policies.length} polices. You need to solve all the - challenges from one policy in order to recover your secret. + We have found {policiesWithInfo.length} polices. You need to solve all + the challenges from one policy in order to recover your secret.

)} {policiesWithInfo.map((policy, policy_index) => { @@ -113,74 +130,100 @@ export function ChallengeOverviewScreen(): VNode { const method = authMethods[info.type as KnownAuthMethods]; if (!method) { - return
-
- unknown challenge + return ( +
+
+ unknown challenge +
- -
+ ); } - function ChallengeButton({ id, feedback }: { id: string; feedback?: ChallengeFeedback }): VNode { + function ChallengeButton({ + id, + feedback, + }: { + id: string; + feedback?: ChallengeFeedback; + }): VNode { function selectChallenge(): void { - if (reducer) reducer.transition("select_challenge", { uuid: id }) + if (reducer) reducer.transition("select_challenge", { uuid: id }); } if (!feedback) { - return
- -
+ return ( +
+ +
+ ); } switch (feedback.state) { case ChallengeFeedbackStatus.ServerFailure: case ChallengeFeedbackStatus.Unsupported: case ChallengeFeedbackStatus.TruthUnknown: - case ChallengeFeedbackStatus.RateLimitExceeded: return
+ case ChallengeFeedbackStatus.RateLimitExceeded: + return
; case ChallengeFeedbackStatus.AuthIban: - case ChallengeFeedbackStatus.Payment: return
- -
- case ChallengeFeedbackStatus.Redirect: return
- -
- case ChallengeFeedbackStatus.Solved: return
-
- Solved -
-
- default: return
- -
- + case ChallengeFeedbackStatus.Payment: + return ( +
+ +
+ ); + case ChallengeFeedbackStatus.Redirect: + return ( +
+ +
+ ); + case ChallengeFeedbackStatus.Solved: + return ( +
+
Solved
+
+ ); + default: + return ( +
+ +
+ ); } - // return
- // {feedback.state !== "solved" ? ( - // - - // } - // > - // {isFree ? "Solve" : `Pay and Solve`} - // - // ) : null} - // {feedback.state === "solved" ? ( - // //
Solved
- //
Solved
- - // ) : null} - //
} return (
-
); }); @@ -210,11 +252,13 @@ export function ChallengeOverviewScreen(): VNode { const policyName = policy.challenges .map((x) => x.info.type) .join(" + "); + const opa = !atLeastThereIsOnePolicySolved ? undefined : policy.isPolicySolved - ? undefined - : "0.6"; + ? undefined + : "0.6"; + return (