wallet-core-embedded: add initial states to Anastasis handler
This commit is contained in:
parent
5a91ec2da6
commit
0f6310bba4
@ -43,6 +43,8 @@ import {
|
|||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
import {
|
import {
|
||||||
reduceAction,
|
reduceAction,
|
||||||
|
getBackupStartState,
|
||||||
|
getRecoveryStartState,
|
||||||
ReducerState,
|
ReducerState,
|
||||||
} from "@gnu-taler/anastasis-core";
|
} from "@gnu-taler/anastasis-core";
|
||||||
|
|
||||||
@ -177,19 +179,32 @@ class NativeWalletMessageHandler {
|
|||||||
* Handle an Anastasis request from the native app.
|
* Handle an Anastasis request from the native app.
|
||||||
*/
|
*/
|
||||||
async function handleAnastasisRequest(
|
async function handleAnastasisRequest(
|
||||||
state: ReducerState,
|
operation: string,
|
||||||
action: string,
|
|
||||||
id: string,
|
id: string,
|
||||||
args: any,
|
args: any,
|
||||||
): Promise<CoreApiResponse> {
|
): Promise<CoreApiResponse> {
|
||||||
// For now, this will return "success" even if the wrapped Anastasis
|
const wrapSuccessResponse = (result: unknown): CoreApiResponseSuccess => {
|
||||||
// response is a ReducerStateError.
|
return {
|
||||||
return {
|
type: "response",
|
||||||
type: "response",
|
id,
|
||||||
id,
|
operation,
|
||||||
operation: "anastasis",
|
result,
|
||||||
result: await reduceAction(state, action, args),
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 {
|
export function installNativeWalletListener(): void {
|
||||||
@ -213,10 +228,8 @@ export function installNativeWalletListener(): void {
|
|||||||
|
|
||||||
let respMsg: CoreApiResponse;
|
let respMsg: CoreApiResponse;
|
||||||
try {
|
try {
|
||||||
if (msg.operation === "anastasis") {
|
if (msg.operation.startsWith("anastasis")) {
|
||||||
// TODO: do some input validation here
|
respMsg = await handleAnastasisRequest(operation, id, msg.args ?? {});
|
||||||
let req = msg.args ?? {};
|
|
||||||
respMsg = await handleAnastasisRequest(req.state, req.action, id, req.args ?? {});
|
|
||||||
} else {
|
} else {
|
||||||
respMsg = await handler.handleMessage(operation, id, msg.args ?? {});
|
respMsg = await handler.handleMessage(operation, id, msg.args ?? {});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user