Skip to content

Commit 4a6f06f

Browse files
committed
Use snap_manageState's target name instead of hardcoding permission name
1 parent 746bb0a commit 4a6f06f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@metamask/superstruct';
1313
import type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';
1414

15+
import { manageStateBuilder } from '../restricted/manageState';
1516
import type { MethodHooksObject } from '../utils';
1617

1718
const hookNames: MethodHooksObject<ClearStateHooks> = {
@@ -80,7 +81,7 @@ async function clearStateImplementation(
8081
): Promise<void> {
8182
const { params } = request;
8283

83-
if (!hasPermission('snap_manageState')) {
84+
if (!hasPermission(manageStateBuilder.targetName)) {
8485
return end(providerErrors.unauthorized());
8586
}
8687

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';
1515
import { hasProperty, isPlainObject, type Json } from '@metamask/utils';
1616

17+
import { manageStateBuilder } from '../restricted/manageState';
1718
import type { MethodHooksObject } from '../utils';
1819

1920
const hookNames: MethodHooksObject<GetStateHooks> = {
@@ -96,7 +97,7 @@ async function getStateImplementation(
9697
): Promise<void> {
9798
const { params } = request;
9899

99-
if (!hasPermission('snap_manageState')) {
100+
if (!hasPermission(manageStateBuilder.targetName)) {
100101
return end(providerErrors.unauthorized());
101102
}
102103

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';
1515
import { JsonStruct, isPlainObject, type Json } from '@metamask/utils';
1616

17+
import { manageStateBuilder } from '../restricted/manageState';
1718
import type { MethodHooksObject } from '../utils';
1819

1920
const hookNames: MethodHooksObject<SetStateHooks> = {
@@ -119,7 +120,7 @@ async function setStateImplementation(
119120
): Promise<void> {
120121
const { params } = request;
121122

122-
if (!hasPermission('snap_manageState')) {
123+
if (!hasPermission(manageStateBuilder.targetName)) {
123124
return end(providerErrors.unauthorized());
124125
}
125126

0 commit comments

Comments
 (0)