Skip to content

Commit 05ffe82

Browse files
committed
Use isObject for better performance
1 parent 6d1af36 commit 05ffe82

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/snaps-rpc-methods/jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module.exports = deepmerge(baseConfig, {
1010
],
1111
coverageThreshold: {
1212
global: {
13-
branches: 92.95,
14-
functions: 97.44,
13+
branches: 92.98,
14+
functions: 97.46,
1515
lines: 97.93,
1616
statements: 97.52,
1717
},

packages/snaps-rpc-methods/src/permitted/setState.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
StructError,
1313
} from '@metamask/superstruct';
1414
import type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';
15-
import { assert, JsonStruct, isPlainObject, type Json } from '@metamask/utils';
15+
import { isObject, assert, JsonStruct, type Json } from '@metamask/utils';
1616

1717
import { manageStateBuilder } from '../restricted/manageState';
1818
import type { MethodHooksObject } from '../utils';
@@ -129,7 +129,7 @@ async function setStateImplementation(
129129
await getUnlockPromise(true);
130130
}
131131

132-
if (key === undefined && !isPlainObject(value)) {
132+
if (key === undefined && !isObject(value)) {
133133
return end(
134134
rpcErrors.invalidParams(
135135
'Invalid params: Value must be an object if key is not provided.',
@@ -189,7 +189,7 @@ async function getNewState(
189189
getSnapState: SetStateHooks['getSnapState'],
190190
) {
191191
if (key === undefined) {
192-
assert(isPlainObject(value));
192+
assert(isObject(value));
193193
return value;
194194
}
195195

@@ -218,7 +218,7 @@ export function set(
218218
value: Json,
219219
): JsonObject {
220220
if (key === undefined) {
221-
assert(isPlainObject(value));
221+
assert(isObject(value));
222222
return value;
223223
}
224224

@@ -239,7 +239,7 @@ export function set(
239239
return requiredObject;
240240
}
241241

242-
currentObject[currentKey] = isPlainObject(currentObject[currentKey])
242+
currentObject[currentKey] = isObject(currentObject[currentKey])
243243
? currentObject[currentKey]
244244
: {};
245245

0 commit comments

Comments
 (0)