diff options
Diffstat (limited to 'packages/challenger-ui/src/hooks/session.ts')
-rw-r--r-- | packages/challenger-ui/src/hooks/session.ts | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/packages/challenger-ui/src/hooks/session.ts b/packages/challenger-ui/src/hooks/session.ts index 4bb1bfbc8..4d0ffeccf 100644 --- a/packages/challenger-ui/src/hooks/session.ts +++ b/packages/challenger-ui/src/hooks/session.ts @@ -15,13 +15,14 @@ */ import { + ChallengerApi, Codec, buildCodecForObject, codecForBoolean, + codecForChallengeStatus, codecForNumber, codecForString, codecForStringURL, - codecForURL, codecOptional, } from "@gnu-taler/taler-util"; import { buildStorageKey, useLocalStorage } from "@gnu-taler/web-util/browser"; @@ -46,6 +47,7 @@ export type LastChallengeResponse = { export type SessionState = SessionId & { email: string | undefined; lastTry: LastChallengeResponse | undefined; + challengeStatus: ChallengerApi.ChallengeStatus | undefined; completedURL: string | undefined; }; export const codecForLastChallengeResponse = (): Codec<LastChallengeResponse> => @@ -61,6 +63,7 @@ export const codecForSessionState = (): Codec<SessionState> => .property("redirectURL", codecForStringURL()) .property("completedURL", codecOptional(codecForStringURL())) .property("state", codecForString()) + .property("challengeStatus", codecOptional(codecForChallengeStatus())) .property("lastTry", codecOptional(codecForLastChallengeResponse())) .property("email", codecOptional(codecForString())) .build("SessionState"); @@ -70,6 +73,7 @@ export interface SessionStateHandler { start(s: SessionId): void; accepted(e: string, l: LastChallengeResponse): void; completed(e: URL): void; + updateStatus(s: ChallengerApi.ChallengeStatus): void; } const SESSION_STATE_KEY = buildStorageKey( @@ -92,6 +96,7 @@ export function useSessionState(): SessionStateHandler { ...info, lastTry: undefined, completedURL: undefined, + challengeStatus: undefined, email: undefined, }); cleanAllCache(); @@ -111,6 +116,29 @@ export function useSessionState(): SessionStateHandler { completedURL: url.href, }); }, + updateStatus(st: ChallengerApi.ChallengeStatus) { + if (!state) return; + if (!state.challengeStatus) { + update({ + ...state, + challengeStatus: st, + }); + return; + } + // current status + const cu = state.challengeStatus; + if ( + cu.changes_left !== st.changes_left || + cu.fix_address !== st.fix_address || + cu.last_address !== st.last_address + ) { + update({ + ...state, + challengeStatus: st, + }); + return; + } + }, }; } |