Skip to content

Commit 8bd37ae

Browse files
authored
Merge pull request #747 from vh/master
fix: wrong params mapping
2 parents 537d3c5 + 8390289 commit 8bd37ae

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/router.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface MockModeSettings {
2121

2222
export type TMethodHandler = (...args: any) => Promise<any>;
2323

24-
const sortParamKeys = (method?: MethodObject, params?: Record<string, unknown>) => {
24+
const toArray = (method?: MethodObject, params?: Record<string, unknown>) => {
2525
if (!method) {
2626
return [];
2727
}
@@ -34,8 +34,10 @@ const sortParamKeys = (method?: MethodObject, params?: Record<string, unknown>)
3434
.reduce((m, pn, i) => ({ ...m, [pn]: i }), {});
3535

3636
return Object.entries(params)
37-
.sort((v1, v2) => methodParamsOrder[v1[0]] - methodParamsOrder[v2[0]])
38-
.map(([key, val]) => val);
37+
.reduce((params: unknown[], [key, val]) => {
38+
params[methodParamsOrder[key]] = val;
39+
return params;
40+
}, []);
3941
};
4042

4143
export class Router {
@@ -79,7 +81,7 @@ export class Router {
7981

8082
const methodObject = (this.openrpcDocument.methods as MethodObject[]).find((m) => m.name === methodName) as MethodObject;
8183

82-
const paramsAsArray = params instanceof Array ? params : sortParamKeys(methodObject, params);
84+
const paramsAsArray = params instanceof Array ? params : toArray(methodObject, params);
8385

8486
try {
8587
return { result: await this.methods[methodName](...paramsAsArray) };

0 commit comments

Comments
 (0)