diff --git a/packages/taler-wallet-embedded/src/wallet-qjs.ts b/packages/taler-wallet-embedded/src/wallet-qjs.ts index db0aeacb6..0a252f514 100644 --- a/packages/taler-wallet-embedded/src/wallet-qjs.ts +++ b/packages/taler-wallet-embedded/src/wallet-qjs.ts @@ -43,6 +43,8 @@ import { } from "@gnu-taler/taler-wallet-core"; import { reduceAction, + getBackupStartState, + getRecoveryStartState, ReducerState, } from "@gnu-taler/anastasis-core"; @@ -177,19 +179,32 @@ class NativeWalletMessageHandler { * Handle an Anastasis request from the native app. */ async function handleAnastasisRequest( - state: ReducerState, - action: string, + operation: string, id: string, args: any, ): Promise { - // For now, this will return "success" even if the wrapped Anastasis - // response is a ReducerStateError. - return { - type: "response", - id, - operation: "anastasis", - result: await reduceAction(state, action, args), + const wrapSuccessResponse = (result: unknown): CoreApiResponseSuccess => { + return { + type: "response", + id, + operation, + result, + }; }; + + switch (operation) { + case "anastasisReduce": + // TODO: do some input validation here + let req = args ?? {}; + let res = await reduceAction(req.state, req.action, req.args ?? {}); + // For now, this will return "success" even if the wrapped Anastasis + // response is a ReducerStateError. + return wrapSuccessResponse(res); + case "anastasisStartBackup": + return wrapSuccessResponse(await getBackupStartState()); + case "anastasisStartRecovery": + return wrapSuccessResponse(await getRecoveryStartState()); + } } export function installNativeWalletListener(): void { @@ -213,10 +228,8 @@ export function installNativeWalletListener(): void { let respMsg: CoreApiResponse; try { - if (msg.operation === "anastasis") { - // TODO: do some input validation here - let req = msg.args ?? {}; - respMsg = await handleAnastasisRequest(req.state, req.action, id, req.args ?? {}); + if (msg.operation.startsWith("anastasis")) { + respMsg = await handleAnastasisRequest(operation, id, msg.args ?? {}); } else { respMsg = await handler.handleMessage(operation, id, msg.args ?? {}); }