From d1b4cc994bd287af5c8a3114eab70ee01f92b4ec Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 15 Apr 2022 12:56:16 +0200 Subject: anastasis-core: async provider synchronization --- .../src/hooks/use-anastasis-reducer.ts | 39 ++++++++++++++++++++++ .../src/pages/home/ContinentSelectionScreen.tsx | 1 - 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'packages/anastasis-webui/src') diff --git a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts index 434e5fb09..1b77db38f 100644 --- a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts +++ b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts @@ -21,6 +21,7 @@ import { TalerErrorCode } from "@gnu-taler/taler-util"; import { AggregatedPolicyMetaInfo, BackupStates, + completeProviderStatus, discoverPolicies, DiscoveryCursor, getBackupStartState, @@ -206,6 +207,44 @@ export function useAnastasisReducer(): AnastasisReducerApi { console.log(e); } setAnastasisStateInternal(newState); + + const tryUpdateProviders = () => { + const reducerState = newState.reducerState; + if ( + reducerState?.reducer_type !== "backup" && + reducerState?.reducer_type !== "recovery" + ) { + return; + } + const provMap = reducerState.authentication_providers; + if (!provMap) { + return; + } + const doUpdate = async () => { + const updates = await completeProviderStatus(provMap); + if (Object.keys(updates).length === 0) { + return; + } + console.log("got provider updates", updates); + const rs2 = reducerState; + if (rs2.reducer_type !== "backup" && rs2.reducer_type !== "recovery") { + return; + } + setAnastasisState({ + ...anastasisState, + reducerState: { + ...rs2, + authentication_providers: { + ...rs2.authentication_providers, + ...updates, + }, + }, + }); + }; + doUpdate().catch((e) => console.log(e)); + }; + + tryUpdateProviders(); }; async function doTransition(action: string, args: any): Promise { diff --git a/packages/anastasis-webui/src/pages/home/ContinentSelectionScreen.tsx b/packages/anastasis-webui/src/pages/home/ContinentSelectionScreen.tsx index 2a480de48..e5dbcd8fc 100644 --- a/packages/anastasis-webui/src/pages/home/ContinentSelectionScreen.tsx +++ b/packages/anastasis-webui/src/pages/home/ContinentSelectionScreen.tsx @@ -37,7 +37,6 @@ export function ContinentSelectionScreen(): VNode { if (!theCountry) return; reducer.transition("select_country", { country_code: countryCode, - currencies: [theCountry.currency], }); }; -- cgit v1.2.3