diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-07-05 11:14:31 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2023-07-26 12:09:17 -0600 |
commit | 0f6310bba423dc910a89693509038b62c85f35b4 (patch) | |
tree | dea243d609d9296846e6f6997bc77904076ad0cb /packages | |
parent | 5a91ec2da6a63bd31b1f26efaad01b7dc71cd20b (diff) | |
download | wallet-core-0f6310bba423dc910a89693509038b62c85f35b4.tar.xz |
wallet-core-embedded: add initial states to Anastasis handler
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-wallet-embedded/src/wallet-qjs.ts | 39 |
1 files changed, 26 insertions, 13 deletions
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<CoreApiResponse> { - // 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 ?? {}); } |