commit 541f2fb960f125802931519966981691914ed903
parent ae993d949b4a754bf87f1eb008ec8e6803170ebb
Author: Sebastian <sebasjm@gmail.com>
Date: Thu, 27 Jun 2024 09:18:09 -0300
fix types
Diffstat:
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/packages/challenger-ui/src/pages/AnswerChallenge.tsx b/packages/challenger-ui/src/pages/AnswerChallenge.tsx
@@ -75,15 +75,15 @@ export function AnswerChallenge({
return await lib.challenger.challenge(nonce, { email: lastEmail });
},
(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,
- });
- // }
+ if (ok.body.type === "completed") {
+ completed(new URL(ok.body.redirect_url));
+ } else {
+ accepted({
+ attemptsLeft: ok.body.attempts_left,
+ nextSend: ok.body.next_tx_time,
+ transmitted: ok.body.transmitted,
+ });
+ }
return undefined;
},
(fail) => {
@@ -112,7 +112,11 @@ export function AnswerChallenge({
return lib.challenger.solve(nonce, { pin: pin! });
},
(ok) => {
- completed(new URL(ok.body.redirect_url));
+ if (ok.body.type === "completed") {
+ completed(new URL(ok.body.redirect_url));
+ } else {
+ setLastTryError(ok.body);
+ }
onComplete();
},
(fail) => {
@@ -120,8 +124,7 @@ export function AnswerChallenge({
case HttpStatusCode.BadRequest:
return i18n.str`Invalid request`;
case HttpStatusCode.Forbidden: {
- setLastTryError(fail.body);
- return i18n.str`Invalid pin`;
+ return i18n.str`Too many attemps where made`;
}
case HttpStatusCode.NotFound:
return i18n.str``;
diff --git a/packages/challenger-ui/src/pages/AskChallenge.tsx b/packages/challenger-ui/src/pages/AskChallenge.tsx
@@ -87,15 +87,15 @@ export function AskChallenge({
return lib.challenger.challenge(nonce, { email: email! });
},
(ok) => {
- // if ("redirectURL" in ok.body) {
- // completed(ok.body.);
- // } else {
- accepted({
- attemptsLeft: ok.body.attempts_left,
- nextSend: ok.body.next_tx_time,
- transmitted: ok.body.transmitted,
- });
- // }
+ if (ok.body.type === "completed") {
+ completed(new URL(ok.body.redirect_url));
+ } else {
+ accepted({
+ attemptsLeft: ok.body.attempts_left,
+ nextSend: ok.body.next_tx_time,
+ transmitted: ok.body.transmitted,
+ });
+ }
onSendSuccesful();
},
(fail) => {