Skip to content

Commit

Permalink
updating the types file
Browse files Browse the repository at this point in the history
  • Loading branch information
NiranjanaBinoy committed Jul 18, 2024
1 parent 9ca8abf commit b273a78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 151 deletions.
Original file line number Diff line number Diff line change
@@ -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<ProviderStateHandlerResult>;

type GetProviderStateConstraint<Params extends JsonRpcParams = JsonRpcParams> =
{
Expand Down
145 changes: 0 additions & 145 deletions app/scripts/lib/rpc-method-middleware/handlers/types.ts
Original file line number Diff line number Diff line change
@@ -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<string, boolean>;
};

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<string, Json>;

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<string, string>,
) => ProviderConfig | null;
export type HasPermission = (origin: OriginString) => boolean;
export type GetAccounts = () => Promise<string[]>;
export type GetCurrentChainId = () => Hex;
export type GetCurrentRpcUrl = () => string | undefined;
export type GetNetworkConfigurations = () => NetworkConfiguration;
export type GetPermissionsForOrigin<
ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint,
> = (
origin: OriginString,
) =>
| SubjectPermissions<
ValidPermission<string, ExtractCaveats<ControllerCaveatSpecification>>
>
| undefined;
export type GetProviderConfig = () => ProviderConfig;
export type GetProviderState = (
origin: OriginString,
) => Promise<ProviderStateHandlerResult>;
export type GetUnlockPromise = (
shouldShowUnlockRequest: boolean,
) => Promise<void>;
export type GetWeb3ShimUsageState = (origin: OriginString) => undefined | 1 | 2;
export type HandleWatchAssetRequest = (
options: Record<string, string>,
) => Promise<void>;
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<string, unknown>;
id: string;
origin: OriginString;
},
]
>;
export type RequestUserApproval = (
options?: AddApprovalOptions,
) => Promise<unknown>;
export type SendMetrics = (
payload: MetaMetricsEventPayload,
options?: MetaMetricsPageOptions,
) => void;
export type SetActiveNetwork = (
networkConfigurationIdOrType: string,
) => Promise<void>;
export type SetNetworkClientIdForDomain = (
domain: string,
networkClientId: NetworkClientId,
) => void;
export type SetProviderType = (type: InfuraNetworkType) => Promise<void>;
export type SetWeb3ShimUsageRecorded = (origin: OriginString) => void;
export type StartApprovalFlow = (
options?: StartFlowOptions,
) => ApprovalFlowStartResult;
export type UpsertNetworkConfiguration = (
networkConfiguration: NetworkConfiguration,
options?: UpsertNetworkConfigurationOptions,
) => Promise<string>;

0 comments on commit b273a78

Please sign in to comment.