From b273a786da3bea7994a1237d8f4076d8cc4f14cc Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:11:34 -0400 Subject: [PATCH] updating the types file --- .../handlers/get-provider-state.ts | 26 +++- .../rpc-method-middleware/handlers/types.ts | 145 ------------------ 2 files changed, 20 insertions(+), 151 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts b/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts index b5c3daca24ef..2f15d61a45cd 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/get-provider-state.ts @@ -1,18 +1,32 @@ import type { JsonRpcEngineNextCallback, JsonRpcEngineEndCallback, -} from '@metamask/json-rpc-engine'; +} from 'json-rpc-engine'; import type { JsonRpcRequest, PendingJsonRpcResponse, JsonRpcParams, } from '@metamask/utils'; +import { OriginString } from '@metamask/permission-controller'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; -import { - HandlerWrapper, - GetProviderState, - ProviderStateHandlerResult, -} from './handlers-helper'; +import { HandlerWrapper } from './types'; + +/** + * @property chainId - The current chain ID. + * @property isUnlocked - Whether the extension is unlocked or not. + * @property networkVersion - The current network ID. + * @property accounts - List of permitted accounts for the specified origin. + */ +type ProviderStateHandlerResult = { + chainId: string; + isUnlocked: boolean; + networkVersion: string; + accounts: string[]; +}; + +type GetProviderState = ( + origin: OriginString, +) => Promise; type GetProviderStateConstraint = { diff --git a/app/scripts/lib/rpc-method-middleware/handlers/types.ts b/app/scripts/lib/rpc-method-middleware/handlers/types.ts index 35b384e3d565..f2ae5a3db51c 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/types.ts +++ b/app/scripts/lib/rpc-method-middleware/handlers/types.ts @@ -1,149 +1,4 @@ -import { - AddApprovalOptions, - ApprovalFlowStartResult, - EndFlowOptions, - StartFlowOptions, -} from '@metamask/approval-controller'; -import { - NetworkClientId, - NetworkConfiguration, - ProviderConfig, -} from '@metamask/network-controller'; -import type { - CaveatSpecificationConstraint, - ExtractCaveats, - ExtractPermission, - OriginString, - PermissionSpecificationConstraint, - PermissionSubjectMetadata, - RequestedPermissions, - SubjectPermissions, - SubjectType, - ValidPermission, -} from '@metamask/permission-controller'; -import type { Hex, Json } from '@metamask/utils'; -import { InfuraNetworkType } from '@metamask/controller-utils'; -import { - MetaMetricsEventPayload, - MetaMetricsPageOptions, -} from '../../../../../shared/constants/metametrics'; - -export type ExistingNetworkChainIds = '0x1' | '0xaa36a7' | '0xe704' | '0xe708'; - export type HandlerWrapper = { methodNames: [string] | string[]; hookNames: Record; }; - -export type NetworkConfigurations = Record< - string, - NetworkConfiguration & { - id: string; - } ->; - -/** - * @property chainId - The current chain ID. - * @property isUnlocked - Whether the extension is unlocked or not. - * @property networkVersion - The current network ID. - * @property accounts - List of permitted accounts for the specified origin. - */ -export type ProviderStateHandlerResult = { - chainId: string; - isUnlocked: boolean; - networkVersion: string; - accounts: string[]; -}; - -export type SubjectMetadataToAdd = PermissionSubjectMetadata & { - name?: string | null; - subjectType?: SubjectType | null; - extensionId?: string | null; - iconUrl?: string | null; -} & Record; - -export type UpsertNetworkConfigurationOptions = { - referrer: string; - source: string; - setActive?: boolean; -}; - -export type AddSubjectMetadata = (metadata: SubjectMetadataToAdd) => void; -export type EndApprovalFlow = ({ id }: EndFlowOptions) => void; -export type FindNetworkClientIdByChainId = (chainId: Hex) => NetworkClientId; -export type FindNetworkConfigurationBy = ( - rpcInfo: Record, -) => ProviderConfig | null; -export type HasPermission = (origin: OriginString) => boolean; -export type GetAccounts = () => Promise; -export type GetCurrentChainId = () => Hex; -export type GetCurrentRpcUrl = () => string | undefined; -export type GetNetworkConfigurations = () => NetworkConfiguration; -export type GetPermissionsForOrigin< - ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint, -> = ( - origin: OriginString, -) => - | SubjectPermissions< - ValidPermission> - > - | undefined; -export type GetProviderConfig = () => ProviderConfig; -export type GetProviderState = ( - origin: OriginString, -) => Promise; -export type GetUnlockPromise = ( - shouldShowUnlockRequest: boolean, -) => Promise; -export type GetWeb3ShimUsageState = (origin: OriginString) => undefined | 1 | 2; -export type HandleWatchAssetRequest = ( - options: Record, -) => Promise; -export type RequestAccountsPermission< - ControllerPermissionSpecification extends PermissionSpecificationConstraint = PermissionSpecificationConstraint, - ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint, -> = ( - subject?: PermissionSubjectMetadata, - requestedPermissions?: RequestedPermissions, - options?: { - id?: string; - preserveExistingPermissions?: boolean; - }, -) => Promise< - [ - SubjectPermissions< - ExtractPermission< - ControllerPermissionSpecification, - ControllerCaveatSpecification - > - >, - { - data?: Record; - id: string; - origin: OriginString; - }, - ] ->; -export type RequestUserApproval = ( - options?: AddApprovalOptions, -) => Promise; -export type SendMetrics = ( - payload: MetaMetricsEventPayload, - options?: MetaMetricsPageOptions, -) => void; -export type SetActiveNetwork = ( - networkConfigurationIdOrType: string, -) => Promise; -export type SetNetworkClientIdForDomain = ( - domain: string, - networkClientId: NetworkClientId, -) => void; -export type SetProviderType = (type: InfuraNetworkType) => Promise; -export type SetWeb3ShimUsageRecorded = (origin: OriginString) => void; -export type StartApprovalFlow = ( - options?: StartFlowOptions, -) => ApprovalFlowStartResult; -export type UpsertNetworkConfiguration = ( - networkConfiguration: NetworkConfiguration, - options?: UpsertNetworkConfigurationOptions, -) => Promise;