aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-06-25 18:03:47 -0300
committerSebastian <sebasjm@gmail.com>2024-06-25 18:03:47 -0300
commit83680013581a530ccaa014ed4a94985453e45123 (patch)
treeaac8212c66f51cad5eca665dd228b371eeb46871 /packages
parent4bb0adb96516a55c3036252ac088493b3d6155da (diff)
downloadwallet-core-83680013581a530ccaa014ed4a94985453e45123.tar.xz
new json api
Diffstat (limited to 'packages')
-rw-r--r--packages/challenger-ui/src/Routing.tsx4
-rw-r--r--packages/challenger-ui/src/app.tsx5
-rw-r--r--packages/challenger-ui/src/components/CheckChallengeIsUpToDate.tsx4
-rw-r--r--packages/challenger-ui/src/hooks/challenge.ts2
-rw-r--r--packages/challenger-ui/src/hooks/session.ts7
-rw-r--r--packages/challenger-ui/src/pages/AnswerChallenge.tsx29
-rw-r--r--packages/challenger-ui/src/pages/AskChallenge.tsx20
7 files changed, 44 insertions, 27 deletions
diff --git a/packages/challenger-ui/src/Routing.tsx b/packages/challenger-ui/src/Routing.tsx
index 6166f159a..7f9f52a19 100644
--- a/packages/challenger-ui/src/Routing.tsx
+++ b/packages/challenger-ui/src/Routing.tsx
@@ -32,6 +32,7 @@ import { Frame } from "./pages/Frame.js";
import { MissingParams } from "./pages/MissingParams.js";
import { NonceNotFound } from "./pages/NonceNotFound.js";
import { Setup } from "./pages/Setup.js";
+import { useErrorBoundary } from "preact/hooks";
export function Routing(): VNode {
// check session and defined if this is
@@ -91,6 +92,9 @@ function PublicRounting(): VNode {
const location = useCurrentLocation(publicPages);
const { navigateTo } = useNavigationContext();
const { start } = useSessionState();
+ useErrorBoundary((e) => {
+ console.log("error", e);
+ });
if (location === undefined) {
return <NonceNotFound />;
diff --git a/packages/challenger-ui/src/app.tsx b/packages/challenger-ui/src/app.tsx
index 2b5c5c815..02ec95107 100644
--- a/packages/challenger-ui/src/app.tsx
+++ b/packages/challenger-ui/src/app.tsx
@@ -41,6 +41,7 @@ import { strings } from "./i18n/strings.js";
import { ChallengerUiSettings, fetchSettings } from "./settings.js";
import { Frame } from "./pages/Frame.js";
import { revalidateChallengeSession } from "./hooks/challenge.js";
+
const WITH_LOCAL_STORAGE_CACHE = false;
const evictBankSwrCache: CacheEvictor<ChallengerCacheEviction> = {
@@ -50,6 +51,10 @@ const evictBankSwrCache: CacheEvictor<ChallengerCacheEviction> = {
await Promise.all([revalidateChallengeSession()]);
return;
}
+ case ChallengerCacheEviction.SOLVE_CHALLENGE: {
+ await Promise.all([revalidateChallengeSession()]);
+ return;
+ }
default: {
assertUnreachable(op);
}
diff --git a/packages/challenger-ui/src/components/CheckChallengeIsUpToDate.tsx b/packages/challenger-ui/src/components/CheckChallengeIsUpToDate.tsx
index 70e41bf1e..ebfa57d02 100644
--- a/packages/challenger-ui/src/components/CheckChallengeIsUpToDate.tsx
+++ b/packages/challenger-ui/src/components/CheckChallengeIsUpToDate.tsx
@@ -46,7 +46,7 @@ export function CheckChallengeIsUpToDate({
onNoInfo,
}: Props): VNode {
const { state, updateStatus } = useSessionState();
- const { i18n } = useTranslationContext();
+ const {i18n} = useTranslationContext();
const sessionId = sessionFromParam
? sessionFromParam
@@ -59,7 +59,7 @@ export function CheckChallengeIsUpToDate({
};
const result = useChallengeSession(nonce, sessionId);
- console.log("asd");
+
if (!sessionId) {
onNoInfo();
return <Loading />;
diff --git a/packages/challenger-ui/src/hooks/challenge.ts b/packages/challenger-ui/src/hooks/challenge.ts
index 846242816..224c60b9b 100644
--- a/packages/challenger-ui/src/hooks/challenge.ts
+++ b/packages/challenger-ui/src/hooks/challenge.ts
@@ -38,7 +38,7 @@ export function useChallengeSession(
lib: { challenger: api },
} = useChallengerApiContext();
- async function fetcher([n, c, r, s]: [string, string, string, string]) {
+ async function fetcher([n, c, r, s]: [string, string, string, string]): Promise<any> {
return await api.login(n, c, r, s);
}
const { data, error } = useSWR<
diff --git a/packages/challenger-ui/src/hooks/session.ts b/packages/challenger-ui/src/hooks/session.ts
index ed7ea8986..847b1fcca 100644
--- a/packages/challenger-ui/src/hooks/session.ts
+++ b/packages/challenger-ui/src/hooks/session.ts
@@ -60,8 +60,8 @@ export const codecForSessionState = (): Codec<SessionState> =>
buildCodecForObject<SessionState>()
.property("clientId", codecForString())
.property("redirectURL", codecForStringURL())
- .property("completedURL", codecOptional(codecForStringURL()))
.property("state", codecForString())
+ .property("completedURL", codecOptional(codecForStringURL()))
.property("lastStatus", codecOptional(codecForChallengeStatus()))
.property("lastTry", codecOptional(codecForLastChallengeResponse()))
.build("SessionState");
@@ -121,12 +121,11 @@ export function useSessionState(): SessionStateHandler {
});
return;
}
- // current status
+ // current status, FIXME: better check to know if the sate changed
const ls = state.lastStatus;
if (
ls.changes_left !== st.changes_left ||
- ls.fix_address !== st.fix_address ||
- ls.last_address !== st.last_address
+ ls.fix_address !== st.fix_address || ls.last_address !== st.last_address
) {
update({
...state,
diff --git a/packages/challenger-ui/src/pages/AnswerChallenge.tsx b/packages/challenger-ui/src/pages/AnswerChallenge.tsx
index 73a79c51f..9788ea8a5 100644
--- a/packages/challenger-ui/src/pages/AnswerChallenge.tsx
+++ b/packages/challenger-ui/src/pages/AnswerChallenge.tsx
@@ -41,7 +41,12 @@ type Props = {
routeAsk: RouteDefinition<{ nonce: string }>;
};
-export function AnswerChallenge({ focus, nonce, onComplete, routeAsk }: Props): VNode {
+export function AnswerChallenge({
+ focus,
+ nonce,
+ onComplete,
+ routeAsk,
+}: Props): VNode {
const { lib } = useChallengerApiContext();
const { i18n } = useTranslationContext();
const { state, accepted, completed } = useSessionState();
@@ -70,21 +75,23 @@ export function AnswerChallenge({ focus, nonce, onComplete, routeAsk }: Props):
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 ("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,
+ });
+ // }
return undefined;
},
(fail) => {
switch (fail.case) {
case HttpStatusCode.BadRequest:
return i18n.str``;
+ case HttpStatusCode.Forbidden:
+ return i18n.str``;
case HttpStatusCode.NotFound:
return i18n.str``;
case HttpStatusCode.NotAcceptable:
@@ -105,7 +112,7 @@ export function AnswerChallenge({ focus, nonce, onComplete, routeAsk }: Props):
return lib.challenger.solve(nonce, { pin: pin! });
},
(ok) => {
- completed(ok.body.redirectURL as URL);
+ completed(new URL(ok.body.redirect_url));
onComplete();
},
(fail) => {
diff --git a/packages/challenger-ui/src/pages/AskChallenge.tsx b/packages/challenger-ui/src/pages/AskChallenge.tsx
index 30b50d707..c2ef43615 100644
--- a/packages/challenger-ui/src/pages/AskChallenge.tsx
+++ b/packages/challenger-ui/src/pages/AskChallenge.tsx
@@ -87,21 +87,23 @@ export function AskChallenge({
return lib.challenger.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,
- });
- }
+ // 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,
+ });
+ // }
onSendSuccesful();
},
(fail) => {
switch (fail.case) {
case HttpStatusCode.BadRequest:
return i18n.str``;
+ case HttpStatusCode.Forbidden:
+ return i18n.str``;
case HttpStatusCode.NotFound:
return i18n.str``;
case HttpStatusCode.NotAcceptable: